'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.
Solution 1:[1]
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
Solution 2:[2]
It's an old question, but the answer above is misleading
array of objects s is not supported in OpenAPI 3.0/3.1 Specifications currently defines
see the question OpenAPI query string parameter with list of objects
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Helen |
| Solution 2 | Happy Coder |
