Skip to content

Missing validation for discriminator property existence in schema properties #2865

@RasankRam

Description

@RasankRam

Hi!

According to the OpenAPI specification, when a discriminator.propertyName is specified, the property must be present in the schema's properties section (though it doesn't have to be required, as per OpenAPI 3.2.0). However, the linter does not detect this violation.

I've created a repository demo (see /spectral-issue folder).

Expected behavior

The linter should fail validation and report an error similar to: discriminator property 'petType' is not defined in schema properties. Probably need to add a validation rule for discriminator property existence in OpenAPI 3.x schemas.

Current behavior

Spectral passes without errors or warnings related to this issue, even though the discriminator references a non-existent property.

In-Repository Example

Pet:
  type: object
  properties:
    name:
      type: string
    age:
      type: integer
  discriminator:
    propertyName: petType  # ERROR: petType not in properties

According to the OpenAPI 3.1.2 specification:

The expectation now is that a property with name petType MUST be present in the response payload

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions