schema-discriminator-defined

schema-discriminator-defined

This rule ensures that whenever a schema object defines a oneOf clause, it also defines a discriminator property.

Rule Details

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.

Configuration

None.

Examples

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"

When Not to Use It

We recommend to always enable this rule.

Compatibility

This rule is compatible with all OpenAPI 3.x versions.

← Back to Index