Skip to content

Comments

Don't escape [ and ] in query param keys#2107

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
BastiOfBerlin:rails-compat-query-array-params
Feb 11, 2019
Merged

Don't escape [ and ] in query param keys#2107
wing328 merged 1 commit intoOpenAPITools:masterfrom
BastiOfBerlin:rails-compat-query-array-params

Conversation

@BastiOfBerlin
Copy link
Contributor

rails' default naming for arrays in query parameters is name[]=...&name[]=...
It doesn't recognize the escaped forms %5B + %5D but fails silently

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh, ./bin/security/{LANG}-petstore.sh and ./bin/openapi3/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Adapting the solution here to prevent HttpParameterCodec from encoding '[' and ']' in query param keys.

This is important for using Rails as a backend as the square brackets are added to the parameter names as per default.

I suppose this change doesn't interfere with most people's APIs as square brackets are not common suffixes other to arrays. Encoding them on the other hand is not necessary for URIs and users could still do this if required for their specific project.

However, if this still considered to be a breaking change, I suppose introducing an additional parameter such as 'rails-compat-query-array-params'.

rails' default naming for arrays is name[]=...&name[]=...
It doesn't recognize the escaped forms %5B + %5D but fails silently
@wing328
Copy link
Member

wing328 commented Feb 11, 2019

@BastiOfBerlin I don't think it's a breaking change but it's fine to include breaking changes in the upcoming 4.0.0 release.

cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10)

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wing328
Copy link
Member

wing328 commented Feb 11, 2019

I'll update the samples in a separate commit.

@wing328 wing328 merged commit ba9c12f into OpenAPITools:master Feb 11, 2019
@macjohnny
Copy link
Member

@BastiOfBerlin @wing328 I think we should revert this because square brackets are reserved characters, see https://stackoverflow.com/a/39294315 for a good explanation.
PHP e.g. accepts both, unencoded and encoded square brackets as array indicator

wing328 pushed a commit that referenced this pull request Feb 13, 2019
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
rails' default naming for arrays is name[]=...&name[]=...
It doesn't recognize the escaped forms %5B + %5D but fails silently
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants