Discriminator in Openapi

I am new to openAPI and trying to understand the discriminator property that can be used along with anyOf and oneOf. how can this property help in implementing the client code?

Please share your wisdom.

1 Answer

The discriminator is a way to distinguish or "discriminate" different schemas. So let's say you have a schema for Animal but you use OpenAPI's polymorphism capabilities to also define a Cat and Dog. Let's say Animal is "oneOf" Cat or Dog. When the receiver gets a response, how can it determine which one it is?

This is where the discriminator is useful. You can provide a value in a field to Animal that tells you which specific kind of animal it is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest