discriminator-field-must-be-a-required-field
Overview
This rule belongs to the openapi-v3-standards-validation
ruleset and states that:
The discriminator is the name of the property that decides which schema definition validates the structure of the model. This field must be marked as a required schema field.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Error |
Message | Discriminator field is marked as optional. |
Code | OPENAPI3STANDARDS_V337 |
Type | Validation |
Rule System | Semantic |
Broad Category | Schemas |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | openapi3 openapi standards semantic validation discriminator property field schema |
Suggested Fixes
- Ensure that name of the schema property, which is marked as a discriminator, is also included in the schema's required list.
- If the schema property should not be a required property, it should not be marked as a discriminator.
- Name of the property marked as discriminator is compared with the schema property name in a case-sensitive manner.
For More Information
- 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.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#openapi-specification
- https://docs.apimatic.io/rulesets/overview/