FAQ

  • GitHub GitHub Repo stars
  • Discord Discord Server
  • Recommended

    oas3-unused-component


    Formats: Severity:

    Components in OpenAPI 3 are reusable/sharable elements. Any other object can reference it, to save duplication.

    Sometimes components are never referenced from anywhere, they are ‘unused’ or ‘orphaned’.

    This could be an oversight, it could be a case where the spec was changed and new schemas have replaced older ones, and those older components were never removed.

    It’s good contract hygiene to prune anything that isn’t used, out of it.

    Why did this violation appear?

    A component has been created, but it’s not actually used/referenced by anything else in the specification.

    Bad example

    paths:
      /pizzas:
        get:
          responses:
            '200':
              content:
                application/json:
                  schema:
                    $ref: '#/shared-components/schemas/PizzaList'
    components:
      schemas:
        IAmNotUsedByAnything:
          properties:
          ...  
        PizzaList:
          properties:
          ...
    

    Good Example

    paths:
      /pizzas:
        get:
          responses:
            '200':
              content:
                application/json:
                  schema:
                    $ref: '#/shared-components/schemas/PizzaList'
    components:
      schemas:
        PizzaList:
          properties:
          ...
    

    How do I fix this violation?

    Make sure any component definitions are used/referenced somewhere within the specification.

    Spectral Equivalent

    The rule is equivalent to oas3-unused-component