spectral icon indicating copy to clipboard operation
spectral copied to clipboard

Missing validation for discriminator property existence in schema properties

Open RasankRam opened this issue 1 month ago • 0 comments

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

RasankRam avatar Nov 08 '25 01:11 RasankRam