schema-required-properties-defined
Since 0.9.0 · In the rulesets: Recommended at warning, Strict at error, All at error
This rule checks that every name listed in required is defined in properties.
Rule details
A required property which is not defined is usually a typo (required: [nmae]) or a
property removed from properties but not from required. Its value is not described,
and generated code often cannot represent it.
The rule looks for the definition wherever the schema’s value is also described:
- in the schema’s
allOfmembers, following references; - in the schemas using it in
allOf,anyOf,oneOf,not,if,thenorelse, and in their other members. This accepts common patterns such asanyOf: [{required: [email]}, {required: [phone]}]below a schema defining both properties, or a mixin requiring a property that the schemas using it define.
Schemas which allow undeclared properties on purpose are skipped: those with
patternProperties, a schema in additionalProperties, or additionalProperties: true.
Schemas whose references cannot be resolved are skipped too.
required in a schema which does not allow objects, for example beside items in an
array schema instead of inside it, has no effect and is reported as such.
The rule reports Required property '...' is not defined in 'properties' and 'required' has no effect because the schema does not allow objects.
Examples
Good. Both required properties are defined.
components:
schemas:
User:
type: object
required: [id, name]
properties:
id:
type: string
name:
type: string
Bad. nmae is not defined.
components:
schemas:
User:
type: object
required: [id, nmae]
properties:
id:
type: string
name:
type: string
Bad. required applies to the array, not to its items.
components:
schemas:
Packages:
type: array
items:
type: object
properties:
name:
type: string
required: [name]
Turn it off or change its severity
In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.rules has the details.
commands:
lint:
rules:
schema-required-properties-defined: off