Linter rulesOpenAPIschema-conditional-effective
schema-conditional-effective
Since 0.9.0
This rule checks that if, then and else in schemas have an effect.
Rule Details
JSON Schema applies then to values matching if and else to the other values.
Several combinations silently do nothing, usually because of a typo or a keyword placed
at the wrong level:
thenorelsewithoutifis ignored.ifwithoutthenandelsehas no effect.elsenever applies whenifaccepts every value, e.g.if: {}or anifwith only adescription;thennever applies whenifisfalse.thenorelseaccepting every value (e.g.{}) has no effect.
References are followed, so if: {$ref: ...} is checked against the referenced schema.
Configuration
None.
Examples
Good. Card payments require a card number, the others an IBAN.
components:
schemas:
Payment:
type: object
if:
properties:
kind:
const: card
then:
required: [cardNumber]
else:
required: [iban]
Bad. then is ignored because the schema has no if.
components:
schemas:
Payment:
type: object
then:
required: [cardNumber]
When Not to Use It
We recommend to always enable this rule.
Compatibility
This rule applies to OpenAPI 3.1 and later, where if, then and else are schema
keywords. OpenAPI 3.0 documents are skipped.