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.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Error |
Message | Inline schema is used in polymorphism. |
Code | OPENAPI3STANDARDS_L250 |
Type | Linting |
Rule System | Semantic |
Broad Category | Discriminators |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | openapi3 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
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#composition-and-inheritance-polymorphism
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#components-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#composition-and-inheritance-polymorphism
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md
- https://docs.apimatic.io/rulesets/overview/