warspite
6 years agoNew Contributor
Response mixing object and number in an array
I am trying to model the following structure (taken from Paypal API guidelines) into openapi 3.0.0
I have no problem getting the object users in the array, but I cannot get the total_items and total_pages into the array without getting indent error (tried all the indent levels) and have failed to find an example
So any help/example would be appreciated
{
"total_items": "166",
"total_pages": "83",
"users": [
{
"given_name": "James",
"surname": "Greenwood",
...
"links": [
{
"href": "https://api.foo.com/v1/customer/users/ALT-JFWXHGUV7VI",
"rel": "self"
}
]
},
{
"given_name": "David",
"surname": "Brown",
...
"links": [
{
"href": "https://api.foo.com/v1/customer/users/ALT-MDFSKFGIFJ86DSF",
"rel": "self"
}
},
...
}
"users" is an array of objects. Those individual objects are currently defined with the given_name and surname properties, but you can define additional properties as required.
Maybe if you replace inline schemas with named schemas it will be easier to understand.
paths: /results: get: responses: "200": description: OK content: application/json: schema: $ref: '#/components/schemas/Results' components: schemas: User: type: object properties: given_name: type: string maxLength: 50 example: James surname: type: string maxLength: 50 example: Greenwood ... # <---- Define other user properties here Results: type: object properties: total_items: type: integer example: 116 total_pages: type: integer example: 12 users: description: An array of users type: array items: $ref: '#/components/schemas/User' example: - given_name: James surname: Greenwood ... # <---- Add example values here - given_name: David surname: Brown ... # <---- Add example values here