stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.48k stars 233 forks source link

Examples for recursive object types aren't validated #2548

Open belka-ew opened 11 months ago

belka-ew commented 11 months ago

Describe the bug Examples for recursive object types aren't validated.

To Reproduce

.spectral.yaml

extends:
  - [spectral:oas, recommended]
rules:
  info-contact: off
  oas3-api-servers: off
  operation-description: off
  oas3-valid-schema-example: true

api.yaml

openapi: 3.0.0

info:
  version: 1.0.0
  title: Title
  description: Description

paths:
  /:
    post:
      tags:
        - Tags
      operationId: operation

      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                external:
                  $ref: "#/components/schemas/A"
              example:
                external: A-1
      responses:
        "201":
          description: Created

tags:
  - name: Tags

components:
  schemas:
    A:
      type: object
      properties:
        internal:
          $ref: "#/components/schemas/A"
  1. Run this CLI command ./spectral lint api.yml.
  2. Produces no error.

Expected behavior Replacing the $ref in A.internal with type: number produces an error:

24:27 error oas3-valid-schema-example "external" property type must be object paths./.post.requestBody.content.application/json.schema.example.external

But this doesn't happen for an object as in the example above.

Environment: