I have this schema defined:
User:
type: object
required:
- id
- username
properties:
id:
type: integer
format: int32
readOnly: true
xml:
attribute: true
description: The user ID
username:
type: string
readOnly: true
description: The username
first_name:
type: string
description: Users First Name
last_name:
type: string
description: Users Last Name
avatar:
$ref: '#/components/schemas/Image'
example:
id: 10
username: jsmith
first_name: Jessica
last_name: Smith
avatar: image goes here
xml:
name: user
Works great. The GET /user/{id}
call displays the sample data just fine.
I have a second schema that creates an array of the above schema:
ArrayOfUsers:
type: array
items:
type: object
required:
- id
- username
properties:
id:
type: integer
format: int32
xml:
attribute: true
description: The user ID
username:
type: string
description: The username
first_name:
type: string
description: Users First Name
last_name:
type: string
description: Users Last Name
avatar:
$ref: '#/components/schemas/Image'
This also works great. The GET /user
call displays the proper structure in an array just fine.
But I'd rather not define this schema twice.
I would like to create a schema that utilizes the first one and stick in an array.
I have failed in this attempt.
I tried it this way:
UserArray:
type: array
items:
type: object
required:
- id
- username
properties:
things:
type: array
items:
oneOf:
- $ref: '#/components/schemas/User'
This attempt gives me an empty array:
[
{}
]
This is not my desired result.
Any hints on this?
An array of User
objects is defined as follows:
UserArray:
type: array
items:
$ref: '#/components/schemas/User'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With