Linter rulesOpenAPIschema-required-properties-defined

schema-required-properties-defined

Since 0.9.0

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 allOf members, following references;
  • in the schemas using it in allOf, anyOf, oneOf, not, if, then or else, and in their other members. This accepts common patterns such as anyOf: [{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.

Configuration

None.

Examples

Good.

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]

When Not to Use It

Disable this rule when required properties are intentionally left undescribed.

Compatibility

This rule is compatible with all OpenAPI 3.x versions.

Related rules