New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[develop 2.0] add support for collection format with brackets #191
Comments
addressed in 30eb4f3 |
Why was swagger-js updated to support this but the Swagger 2.0 JSON Schema files were not? Also, there is no mention of this feature in the Swagger 2.0 Specification. Supporting this in swagger-js but not officially means that if you intend to keep valid Swagger documents, per the JSON Schema and Specification Documentation, you either can't use this feature. Mentioning @fehguy so he sees this. |
I square brackets are in the name of the field and not the value. There's no restriction on that in the spec... Have you looked at the original issue? swagger-api/swagger-ui#661 |
I'm just the messenger but yes, I did look at the original issue and I even did some code surfing. If you search for |
I was actually confused because swagger-ui supports "brackets" as a collectionFormat value. See here for example: 30eb4f3 The problem when using "myparam[]" as a name (and "multi" as a collectionFormat) is that swagger-ui will actually use "myparam%5B%5D" in the query string instead of "myparam[]" if you use "brackets" as a collectionFormat. |
Okay, so to clarify, there's no 'brackets' collectionFormat. Perhaps the implementation is wrong. |
So the right way to do it is to put the brackets in the parameter name? |
That is correct. |
You want me to open a ticket to remove support for it? :) |
It seems swagger-ui does the right thing when you use "collectionFormat": "brackets" While when "name": "myparam[]" is used (with the allowed "collectionFormat": "multi") you get The later doesn't match the jQuery "traditional" convention: If there is no plan to add "brackets" support to the swagger 2.0 spec it is weird to allow it in swagger-ui. |
The "encodeQueryParam" method responsible for the excessive URL encoding is simply:
The problem is: that method is actually part of https://www.npmjs.com/package/swagger-client But the corresponding git repo yields a 404: https://github.com/swagger-api/swagger-client Where is that code hosted now? |
All I believe if you go through the workgroup discussions, this format was supposed to be in the spec. It's a very common array specifier for query params. @ddm please look at swagger-js |
Well the thing is, the recommended method of using brackets in the name and 'multi' as a collectionFormat falls short because when using That makes the job of swagger-tools or other automated validation generators harder. @whitlockjc can correct me if I'm wrong here. My understanding was that 'collectionFormat' was an indication of how the collection would be serialised in the queryString/path/body of the request while 'name' was the actual name of the parameter. So 'multi' means that the parameter name can be repeated and 'brackets' means that [] is appended to the name to indicate a collection (with repetition adding items to the collection like with 'multi'). I still believe that 'brackets' has its place in the spec because it's a serialisation convention that is used in both server-side frameworks (express etc.) and client side ajax libraries (jQuery.ajax traditional and probably others). |
@fehguy Thanks for the pointer BTW, I see that the repo URL is fixed in the develop_2.0 branch so npm will eventually point to the correct repo once it's merged into master and published. |
Did the bug come back? This is my swagger
And I input multi lines in the textarea, they are just joined with a comma. |
Per swagger-api/swagger-ui#661
need to add support for query params with ?param[]=1¶m[]=2
The text was updated successfully, but these errors were encountered: