This rule ensures that whenever a schema object defines a oneOf
clause, it
also defines a discriminator property.
The schema-discriminator-defined
rule is designed to ensure that all schema
objects that define a oneOf
clause also define the discriminator
property.
The discriminator
property is used to aid in the deserialization of oneOf
schemas.
None.
Good.
components:
schemas:
Pet:
type: object
discriminator:
propertyName: petType
oneOf:
- $ref: "#/components/schemas/Cat"
- $ref: "#/components/schemas/Dog"
Bad. It is not obvious when a pet is a cat, and when it is a dog.
components:
schemas:
Pet:
type: object
oneOf:
- $ref: "#/components/schemas/Cat"
- $ref: "#/components/schemas/Dog"
We recommend to always enable this rule.
This rule is compatible with all OpenAPI 3.x versions.