OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Add support for query param array format

Open fehguy opened this issue 12 years ago • 30 comments

There is no standard for handling arrays as query parameters. We should be able to add a format structure to let the API server specify what it expects, and have swagger-js + codegen produce the correct structure.

fehguy avatar Apr 29 '14 03:04 fehguy

@webron Okey, wordnik/swagger-ui#661

kiaplayer avatar Oct 15 '14 05:10 kiaplayer

@kiaplayer - thank you for taking the time.

webron avatar Oct 15 '14 08:10 webron

@webron I think we're missing two collectionFormat values in the spec. Many frameworks want this:

a=1&a=2&a=3

to represent a list a with values (1,2,3). This includes jaxrs, and you're describing multi in this ticket which isn't actually in the spec right now (that I see).

Similarly, many frameworks want the brackets in the name like in this initial issue, and it seems like this might be a named format, like brackets or something. Would make life much easier in the js library, since we don't need to handle special characters in the parameter name (the brackets will be encoded by default):

https://github.com/wordnik/swagger-js/blob/develop_2.0/src/main/javascript/swagger.js#L624

fehguy avatar Oct 15 '14 12:10 fehguy

multi is described in the spec and the schema - https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#parameterCollectionFormat with a few restrictions (it's only relevant in query and formData params).

I think you need to handle special characters in the name one way or another. What if someone decides to name their parameter api-key? Or have some accented letters in the parameter name? Wouldn't all those cause issues as well? I can add it, of course, it just feels like we're dealing with an edge case rather than the problem as a whole.

webron avatar Oct 15 '14 13:10 webron

Hi! I've also had recently a problem representing this: productID1=1&productID2=2&... I'm rewriting a hand-written API spec. as swagger.yaml

packpaul avatar Nov 25 '16 12:11 packpaul

@packpaul that URI syntax can't be represented in OpenAPI (neither in version 2.0 nor what is currently proprosed in 3.0, as far as I understand).

ePaul avatar Dec 12 '16 19:12 ePaul

I didn't know it. So here's a proposal to implement it in the following version.

packpaul avatar Dec 12 '16 19:12 packpaul

Please open a new issue (with a more detailed proposal how you imagine it to be represented). Commenting on closed issues doesn't help.

ePaul avatar Dec 12 '16 19:12 ePaul

the brackets will be encoded by default

Isn't this the bug? Encoding characters that need not be encoded is just... wrong is it not?

Download avatar May 11 '17 11:05 Download

Brackets in fields names are encoded anyway

Isn't this the bug? Encoding characters that need not be encoded is just... wrong is it not?

Actually, the encoded brackets work (at least with PHP), so ?array[]=1&array[]=2 is the same as ?array%5B%5D=1&array%5B%5D=2

aleksbrgt avatar Sep 07 '18 07:09 aleksbrgt