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 as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.37k stars 228 forks source link

Spectral oas3-unused-component warning #2571

Open igorkud90 opened 6 months ago

igorkud90 commented 6 months ago

Describe the bug Spectral alert oas3-unused-component warning.

To Reproduce

  1. Given this OpenAPI document and referenced document in same folder:

index.yaml

openapi: 3.1.0
info:
  title: Test
  version: 1.0.0
paths:
  '/':
    description: test
    get:
      operationId: test
      description: test
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: './common.yaml#/components/schemas/ResponseType'

common.yaml

openapi: 3.1.0
info:
  title: Common schema definition
  description: test
  version: 1.0.0
paths: {}
components:
  schemas:
    # Spectral lint warning "Potentially unused component has been detected."
    ResponseType:
      type: string
      example: test
      description: test
  1. Run this CLI command

    spectral lint index.yaml common.yaml
  2. See warning

/tmp/test/common.yaml 10:18 warning oas3-unused-component Potentially unused component has been detected. components.schemas.ResponseType



**Expected behavior**
Component ResponseType used in index.yaml. Spectral can't alert oas3-unused-component warning.