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

Valid spec is mentionned as invalid #481

Closed LasneF closed 2 months ago

LasneF commented 2 months ago

taking the following specification

vacuum raises 3 errors whereas the file looks ok it look like it is interpreting the field $ref as an instruction

notice it looks a regression i do not remind to have it last month ...

notice it s a real use case about having run time discovery of schema


openapi: '3.1.0'
info:
  title: this is the title
  description: this is the description
  version: '1.0'
servers:
  - url: https://api.server.test/v1

paths:
  /test:
    get:
      operationId: getTest
      responses:
        '200':
          "description" : "testOK"
          "content":
            "application/json": 
              "schema": 
                  "$ref": "#/components/schemas/PetPot"

components:
  schemas:
    PetPot:
      type: object
      properties:
        value:
          description: value
          oneOf:
            - type: array
              items:
                type: object
                description: The value to be used within the operations.
                required:
                  - $ref
                  - value
                properties:
                  $ref:
                    description: $ref
                    type:
                      - string
                      - 'null'
                  value:
                    type: string
                    description: The value to be used within the operations.
            - type: string
              description: The value to be used within the operations.
daveshanley commented 2 months ago

Do you know which version the regression occurred in?

LasneF commented 2 months ago

sorry @daveshanley , my mistake , it s not a regression done test since 0.9.1 and issue was there too , just a new use case

daveshanley commented 2 months ago

Got it, will investigate

daveshanley commented 2 months ago

You found an edge case, thank you. This was an issue in libopenapi which has been fixed in `(https://github.com/pb33f/libopenapi/blob/main/index/extract_refs.go#L219) and a test added (https://github.com/pb33f/libopenapi/blob/main/index/spec_index_test.go#L1720)

Fix is available in vacuum v0.9.15