Replies: 3 comments 11 replies
-
@mhonert we've added the following in the soon-to-be-published 3.1.1 and 3.0.4 versions, which should answer your question (see the part about what is and is not validated in the
|
Beta Was this translation helpful? Give feedback.
-
@ralfhandl and @mikekistler review |
Beta Was this translation helpful? Give feedback.
-
I'm going to go ahead and close this because we have done our best to improve the wording around this in 3.0.4 and 3.1.1, which we believe will be out by October (we're just debating some final wording tweaks right now). Do feel free to open a new discussion if needed. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I have a question about the Pet, Cat, and Dog polymorphism example using "allOf" and "discriminator" from the OpenAPI specification. There have been several discussions and issues in the past about this topic, but I could not find an answer to this specific question.
A short summary of the example:
The "Pet" schema object defines properties common to all pets. The "Dog" and "Cat" schemas use "allOf" to combine all pet properties with properties specific to a "Dog" or "Cat".
The "Pet" schema also contains the "discriminator" object, which according to the specification, "can be used to aid in serialization, deserialization, and validation."
What I could not find information about is what this means when another schema object references the "Pet" within one of its properties, like in this example:
If the "discriminator" object is just an "aid" and does not change the semantics of allOf, then I would expect that simply referencing the 'Pet' schema object here is not sufficient if the goal is to allow only valid "Cat" or "Dog" objects as values for 'availablePets'.
With the current definition, none of the constraints defined for a "Cat" or "Dog" would be validated — only the ones defined for the "Pet".
Is this assumption correct? If yes, then I would assume that "oneOf" could be used here to restrict the values to "Cat" or "Dog" as intended.
Best regards
Martin
Beta Was this translation helpful? Give feedback.
All reactions