Linter rulesOpenAPIschema-no-contradictions
schema-no-contradictions
Since 0.9.0
This rule reports schemas with contradicting constraints, which reject every value or some of the properties they describe.
Rule Details
The rule merges each schema with its allOf members, following references, and reports
contradictions it can prove:
allOfmembers requiring types with nothing in common, such asstringandinteger;- bounds excluding every value:
minimumabovemaximum(takingexclusiveMinimumandexclusiveMaximuminto account, and integers when the type isinteger),minLengthabovemaxLength,minItemsabovemaxItems,minPropertiesabovemaxProperties, or more required properties thanmaxProperties; - an
allOfmember rejecting every value, e.g.falseornot: {}, andanyOforoneOfwhose every branch does; enumorconstvalues of anallOfmember none of which satisfies the whole schema;- a required property whose schema rejects every value, or which an
allOfmember withadditionalProperties: falsedoes not declare; - a property which can never be present because an
allOfmember withadditionalProperties: falsedoes not declare it. This is the common mistake of closing a base schema and extending it withallOf; useunevaluatedProperties: false(OpenAPI 3.1) on the combined schema instead.
A contradiction is reported once, at the schema it originates from, and not again at
every schema using that one. Formats are not checked, and constraints the rule cannot
reason about (such as pattern) never lead to a report.
Configuration
None.
Examples
Good. Cat declares every property it allows.
components:
schemas:
Pet:
type: object
required: [petType]
properties:
petType:
type: string
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- properties:
meow:
type: boolean
unevaluatedProperties: false
Bad. Pet forbids meow, so a Cat can never have it.
components:
schemas:
Pet:
type: object
additionalProperties: false
required: [petType]
properties:
petType:
type: string
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- properties:
meow:
type: boolean
Bad. No value is both a string and an integer.
components:
schemas:
Id:
allOf:
- type: string
- type: integer
When Not to Use It
We recommend to always enable this rule.
Compatibility
This rule is compatible with all OpenAPI 3.x versions. In OpenAPI 3.0 documents,
nullable and the boolean exclusiveMinimum/exclusiveMaximum are taken into account,
and keywords beside $ref are ignored as the specification requires.