daveshanley / vacuum

vacuum is the worlds fastest OpenAPI 3, OpenAPI 2 / Swagger linter and quality analysis tool. Built in go, it tears through API specs faster than you can think. vacuum is compatible with Spectral rulesets and generates compatible reports.
https://quobix.com/vacuum
MIT License
488 stars 39 forks source link

False positive for oas3-unused-component rule #442

Closed crodriguezleon closed 4 months ago

crodriguezleon commented 5 months ago

Summary

Vacuum detects components as unused when they are only referenced from a component that inherits from another component using the allOf keyword.

Example

components:
  schemas:
    Dog:
      type: object
      allOf:
        - $ref: '#/components/schemas/Pet'
      required:
        - breed
      properties:
        breed:
          $ref: '#/components/schemas/Breed'
    Pet:
      type: object
      properties:
       id: 
        type: String
        description: Unique identifier of the Pet
      age:
        type: integer
        format: int64
   Breed:
      type: object
      properties:
        name:
         type: String
       category:
        type: String

Expected result

Breed should not be detected as unused by oas3-unused-component rule because it's being referenced from Dog.

Actual result

Vacuum detects Breed as an unused component. If we remove the allOf section from the Dog definition, then Breed is not detected anymore as unused.

daveshanley commented 5 months ago

This has been resolved in v0.8.7

A test has been added to validate:

https://github.com/daveshanley/vacuum/blob/main/functions/openapi/unused_component_test.go#L303

crodriguezleon commented 4 months ago

Hello @daveshanley,

Just tested it and the issue keeps happening for me with v0.8.7.

I've attached a zip file with the specification I've used to test it and the report I get.

Example.zip

Thanks in advance!

daveshanley commented 4 months ago

OK this is strange. I will re-investigate for you.

daveshanley commented 4 months ago

This has been resolved in v0.9

The Example.zip now passes.