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

Are indexes in the query parameter array representable?

Open jcarres-mdsol opened this issue 6 years ago • 8 comments

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?

jcarres-mdsol avatar Mar 02 '18 15:03 jcarres-mdsol

@webron, I think you originally added collectionFormat and style so probably you have given this some thought

jcarres-mdsol avatar Mar 03 '18 15:03 jcarres-mdsol

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.

hkosova avatar Mar 05 '18 10:03 hkosova

.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

harvzor avatar Aug 16 '21 09:08 harvzor

I've just recently encountered this issue myself. Has anything new happened?

DSchougaard avatar Mar 23 '22 07:03 DSchougaard

This notation is also commonly used in PHP

septatrix avatar Jul 08 '22 13:07 septatrix