Skip to content

Are indexes in the query parameter array representable? #1501

Closed

Description

@jcarres-mdsol

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?

Activity

  1. jcarres-mdsol commented on Mar 3, 2018

    @jcarres-mdsol
    Author

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

  2. hkosova commented on Mar 5, 2018

    @hkosova
    Contributor

    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.

  3. harvzor commented on Aug 16, 2021

    @harvzor

    .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: domaindrivendev/Swashbuckle.AspNetCore#1832

  4. DSchougaard commented on Mar 23, 2022

    @DSchougaard

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

  5. septatrix commented on Jul 8, 2022

    @septatrix

    This notation is also commonly used in PHP

  6. OleksiiBulba commented on Jun 20, 2024

    @OleksiiBulba

    I have a question about the workaround: is it legit to name the parameter with brackets. E.g. for the author example it would be list[]. At least it solves the issue for just indexed query but not for maps.

  7. handrews commented on Jun 20, 2024

    @handrews
    Member

    @OleksiiBulba the OpenAPI parameter name syntax allows it. Although the question of whether non-percent-encoded [] is valid in a URL query string is complex (see Appendix E in the work-in-progress 3.0.4 and 3.1.1 specs, which are on their own branches). But if it's working for you in practice, then you're probably fine (I can't tell whether that PHP framework is encoding/decoding behind the scenes or if it's just relying on the interoperability problems of [ and ] in URLs being very rare).

  8. OleksiiBulba commented on Jun 20, 2024

    @OleksiiBulba

    @handrews thanks for your prompt response!

    Actually, I've already tried it with nelmio/api-doc-bundle (for Symfony) and it works absolutely ok.

    P.S. For anyone who would find this comment: if your property is required, don't forget to add [] to the property name in required list, it will save you ~20 mins of life :D

  9. handrews commented on Aug 19, 2025

    @handrews
    Member

    With PR #4590 and the new media types registry, it is possible to define new ways to structure the query string, and that is now the recommended approach to try out complex formats such as this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    param serializationIssues related to parameter and/or header serialization

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions