Forum Discussion
chichepo no worries - I understood the example 😉
With the autogenerated examples I would assume that:
anyOf would generate:
"animals": [
{
"name": "string",
"legs": 0
},
{
"name": "string",
"owner": "string"
}
]
and oneOf would generate:
"animals": [
{
"name": "string",
"legs": 0
},
{
"name": "string",
"legs": 0
}
]
(Here the first item in the oneOf would just be repeated twice...)
Where in the specifications does it specify that the oneOf or anyOf applies to the entire list and not to each item in the list?
My assumption was that below the keyword "items" - the structure for each item in the list is specified. This could be a type:string - in which case all items in the list would have to be of type string. In case it is a oneOf - then each item in the list would be a oneOf... Again - this is just my (maybe wrongly) assumption - it would be great to read an official specification for the use of oneOf and/or anyOf in combination with an array (items field) 🙂
- chichepo12 months agoChampion Level 2
Sorry for my late answer but your question is about a particular point that is still under discussion by us as well.
As far as I understand the purpose of oneOf, anyOf and allOf, it's a kind of scaffold for polymorphism validation.
Again, I am not expected anything from SwaggerHub preview and, by the way, the resolved YAML/JSON are identical (like you mentioned).
I would expect, in your specific case, to get the exact Dog/Cat structure, even under an array items (including items characteristics).
For example, in our architecture convention, the oneOf/anyOf have a specific model in our code (then we are free to add our own validations within)
I'll be happy to get some comments, from the community, about the following facts:
- Not all the code generators are supporting oneOf, anyOf and allOf. (depending on the target language).- I don't know if there is a OAS YAML/JSON generator that support it.
- AWS Gateway and APIGEE are not supporting it (or very partially)
Let us know
Related Content
- 3 years ago
- 3 years ago
- 3 years ago
- 2 years ago
Recent Discussions
- 12 days ago
- 31 days ago