HenrikHL
2 years agoFrequent Contributor
The use of oneOf or anyOf in arrays
Hi all,
We have been discussing internally of how to use the oneOf and anyOf keywords in arrays.
Suppose we have the following 2 items (Dog and Cat)
Dog:
type: object
properties:
name:
type: string
legs:
type: number
Cat:
type: object
properties:
name:
type: string
owner:
type: string
I now want an "animals" list. What is the difference between the following two specifications:
animals:
type: array
items:
anyOf:
- $ref: Dog
- $ref: Cat
and
animals:
type: array
items:
oneOf:
- $ref: Dog
- $ref: Cat
If anybody has a link to an official documentation that would be great.
What I am looking for is a list like this:
{
"animals": [
{
"name": "King",
"legs": 4
},
{
"name": "White",
"owner": "John"
}
]
}
Which is a list containing both Dog and Cat objects