Forum Discussion
According to this article: https://www.baeldung.com/openapi-array-of-varying-types
When using oneOf - each item in the list must be either of type Dog OR type Cat (https://www.baeldung.com/openapi-array-of-varying-types#1-oneof-keyword)
When using anyOf - then the items in the list can be a merge of Dog AND Cat (https://www.baeldung.com/openapi-array-of-varying-types#2-anyof-keyword)
If this article is correct - then the autogenerated examples on SwaggerHub are wrong.
- chichepo2 years agoChampion Level 1
HenrikHL
My apologies for the error in my first example. Please look at the updated screen shot.
Regarding your specific case, to achieve your expected structure, you will have to use anyOf, since it admits a mix of both items types.
Even if it looks like identical, the validation (specification) behavior is different.
If you are working with some API gateway, (AWS, APIGEE, etc.) you will be able to test the validation according to your specifications.
Regarding the SwaggerHub rendering, don't be surprised if you don't got the exact structure form.
Especially for such kind of "polymorphism".
It makes sense by the way.
How do you want to render such a complex structure? In allOf, for example, should it display the first definition or the second?
Let us know 😉
Related Content
- 3 years ago
- 3 years ago
- 3 years ago
- 3 years ago
- 6 years ago
Recent Discussions
- 10 days ago
- 2 months ago