OpenAPI-Specification
OpenAPI-Specification copied to clipboard
Are indexes in the query parameter array representable?
I understand how to represent in 2.0 and 3.0 these query parameters with OpenAPI:
?list=x&list=y
But I can't understand if it is possible or not (so I imagine, not?) to represent this:
?list[0]=x&list[1]=y
or this:
?obj[x][0]=a&obj[x][1]=b
We use indexes so we can mix arrays and maps with the same notation, i.e. we would also have:
?map[x]=1&map[y]=2
Is this even representable today? Any hack around it if not?
@webron, I think you originally added collectionFormat and style so probably you have given this some thought
Your last example ?map[x]=1&map[y]=2
can be defined an an object parameter with style: deepObject
:
parameters:
- in: query
name: map
schema:
type: object
properties:
x:
type: integer
y:
type: integer
style: deepObject
explode: true
or
parameters:
- in: query
name: map
schema:
type: object
additionalProperties:
type: integer
style: deepObject
explode: true
Not sure about other examples though.
.NET uses the ?list=x&list=y
format for simple nested objects which currently works fine with Swagger/OpenAPI.
However, when .NET has to pass an array of objects, it switches to the ?list[0]=x&list[1]=y
format, which is incorrectly parsed by Swagger because OpenAPI has no way of describing how it should be serialized.
This issue is better documented here: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1832
I've just recently encountered this issue myself. Has anything new happened?
This notation is also commonly used in PHP