Skip to content

Latest commit

 

History

History
105 lines (81 loc) · 2.7 KB

File metadata and controls

105 lines (81 loc) · 2.7 KB
slug /docs/cli/rules/oas/spec-discriminator-defaultMapping

spec-discriminator-defaultMapping

Ensures that discriminator objects with optional propertyName include a defaultMapping field as required by the OpenAPI 3.2.0 specification.

OAS Compatibility
2.0
3.0
3.1
3.2
flowchart TD

Root ==> Paths --> PathItem --> Operation --> RequestBody --> MediaType --> Schema --> Discriminator
Operation --> Responses --> MediaType
NamedSchemas --> Schema
Root ==> components

subgraph components
NamedSchemas
end

style Discriminator fill:#codaf9,stroke:#0044d4,stroke-width:5px
Loading

API design principles

According to the OpenAPI 3.2.0 specification, when a discriminator's propertyName is optional (not in the required array), the discriminator MUST include a defaultMapping field. This field specifies the schema to validate against when the discriminating property is absent or has no explicit/implicit mapping.

Configuration

Option Type Description
severity string Possible values: off, warn, error. Default warn (in recommended configuration).

An example configuration:

rules:
  spec-discriminator-defaultMapping: warn

Examples

Given this configuration:

rules:
  spec-discriminator-defaultMapping: warn

Example of an incorrect discriminator object:

components:
  schemas:
    Base:
      type: object
      discriminator:
        propertyName: type
        mapping:
          a: SomeType
      properties:
        type:
          type: string
    SomeType:
      allOf:
        - $ref: '#/components/schemas/Base'

Example of a correct discriminator object:

components:
  schemas:
    Base:
      type: object
      discriminator:
        propertyName: type
        defaultMapping: DefaultType
      properties:
        type:
          type: string
    DefaultType:
      allOf:
        - $ref: '#/components/schemas/Base'

Related rules

Resources