Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger/OpenAPI spec for arrays of objects in URL query parameter

Assume I have a URL which takes a path of: ?filter[id]=1&filter[name]=bob&order[][name]=asc&order[][age]=desc

How would one be able to convert this into swagger documentation, specifically, array of objects and arrays as the query parameter.

like image 689
Bill Avatar asked Oct 23 '25 18:10

Bill


1 Answers

Your example is not an array of objects but two separate object parameters - filter and order[], each serialized using the deepObject style (supported in OpenAPI 3.0). You can describe these parameters as follows:

openapi: 3.0.2
...

paths:
  /something:
    get:
      # ?filter[id]=1&filter[name]=bob&order[][name]=asc&order[][age]=desc
      parameters:
        - in: query
          name: filter
          schema:
            type: object
            properties:
              id:
                type: integer
                example: 1
              name:
                type: string
                example: bob
          style: deepObject

        - in: query
          name: order[]
          schema:
            type: object
            properties:
              name:
                type: string
                example: asc
              age:
                type: string
                example: desc
          style: deepObject
like image 176
Helen Avatar answered Oct 26 '25 11:10

Helen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!