no-inline-schemas-in-polymorphism
Overview
This rule belongs to the swagger-v2-standards-validation
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 | SWAGGER20STANDARDS_V317 |
Type | Validation |
Rule System | Semantic |
Broad Category | Schemas |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | swagger2 swagger standards semantic validation discriminator polymorphism schema inline definitions |
Suggested Fixes
- Remove the inline schema definition and relocate it to the definitions section.
- Define the inline schema globally in the definitions section with a unique name. Then reference it using $ref in your current object with a path like '#/definitions/<global name>'.
- The schema being discriminated i.e. the Schema Object containing the
discriminator
property should not be an inline schema. - When using allOf 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/2.0.md#composition-and-inheritance-polymorphism
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#schema-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md
- https://docs.apimatic.io/rulesets/overview/