Skip to main content

no-inline-schemas-in-polymorphism

Overview

This rule belongs to the openapi-v3-standards-linting ruleset and states that:

Inline schema definitions, which do not have a given id, cannot be used in polymorphism. When using the discriminator, inline schemas will not be considered.

PropertyValue
EnabledYes
Maximum SeverityError
MessageInline schema is used in polymorphism.
CodeOPENAPI3STANDARDS_L250
TypeLinting
Rule SystemSemantic
Broad CategoryDiscriminators
Products ImpactedAPI Transformer, Code Generation, Developer Experience Portal
Tagsopenapi3 openapi standards semantic linting discriminator polymorphism schema inline components

Suggested Fixes

  • Remove the inline schema definition and relocate it to the components/schemas section.
  • Define the inline schema globally in the components/schemas section with a unique name. Then reference it using $ref in your current object with a path like '#/components/schemas/<global name>'.
  • The schema being discriminated i.e. the Schema Object containing the discriminator property should not be an inline schema.
  • When using oneOf/anyOf constructs with the discriminator, the schemas in these constructs must not be inline schemas.

For More Information