vacuum icon indicating copy to clipboard operation
vacuum copied to clipboard

Incorrectly reporting duplicate query params

Open burkettd opened this issue 8 months ago • 2 comments

vacuum is reporting duplicate query parameters for the following spec:

openapi: 3.1.0
info:
  title: Test api spec
  version: 1.0.0
  description: test description
servers:
  - url: 'http://localhost:8080'
components:
paths:
  /test:
    get:
      operationId: test
      summary: Test
      parameters:
        - schema:
            type: string
          required: false
          name: name
          in: query
        - schema:
            type: string
            enum:
              - name
              - domain
            default: name
          required: false
          name: sortBy
          in: query
      responses:
        '200':
          description: Test response
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: string
❯ vacuum lint -d -e ./openapi-doc-v1.yaml


██╗   ██╗ █████╗  ██████╗██╗   ██╗██╗   ██╗███╗   ███╗
██║   ██║██╔══██╗██╔════╝██║   ██║██║   ██║████╗ ████║
██║   ██║███████║██║     ██║   ██║██║   ██║██╔████╔██║
╚██╗ ██╔╝██╔══██║██║     ██║   ██║██║   ██║██║╚██╔╝██║
 ╚████╔╝ ██║  ██║╚██████╗╚██████╔╝╚██████╔╝██║ ╚═╝ ██║
  ╚═══╝  ╚═╝  ╚═╝ ╚═════╝ ╚═════╝  ╚═════╝ ╚═╝     ╚═╝


version: 0.16.5 | compiled: Sat, 22 Mar 2025 16:43:02 UTC
🔗 https://quobix.com/vacuum | https://github.com/daveshanley/vacuum


 INFO  Linting file './openapi-doc-v1.yaml' against 48 rules: https://quobix.com/vacuum/rulesets/recommended


/Users/snoopy/Code/openapi-scratchpad/openapi-doc-v1.yaml
---------------------------------------------------------------
Location                    | Severity | Message                                                                                          | Rule                 | Category   | Path
./openapi-doc-v1.yaml:20:11 | error    | the `GET` operation parameter at path `/test`, index 1 has a duplicate name `name` and `in` type | operation-parameters | Operations | $.paths['/test'].get.parameters[1]
./openapi-doc-v1.yaml:20:11 | error    | the `GET` operation parameter at path `/test`, index 1 has a duplicate name `name` and `in` type | path-params          | Operations | $.paths['/test'].get.parameters[1]

Category     | Errors | Warnings | Info
Operations   | 2      | 0        | 0
Tags         | 0      | 1        | 0
Descriptions | 0      | 2        | 0
Examples     | 0      | 2        | 0


          Linting file './openapi-doc-v1.yaml' failed with 2 errors, 5 warnings and 0 informs

Error: failed with 2 errors

burkettd avatar Apr 14 '25 15:04 burkettd

looks like a bug, will investigate

daveshanley avatar Apr 14 '25 22:04 daveshanley

@daveshanley looks this is related to default value management

with smaller test / unit case

paths:
  /test:
    get:
      operationId: test
      summary: Test
      parameters:
        - schema:
            type: string
          name: name
          in: query
        - schema:
            type: string
          name: sortBy
          in: query

there is no duplication mentionned

but with this one , ie with default value set to name , it spot it as a duplicate

paths:
  /test:
    get:
      operationId: test
      summary: Test
      parameters:
        - schema:
            type: string
          name: name
          in: query
        - schema:
            type: string
            default: name
          name: sortBy
          in: query

notice that it is definitely because of the default value set to a value "name" ,

upating to namez both first param and default value does not spot set the issue

paths:
   /test:
    get:
      operationId: test
      summary: Test
      parameters:
        - schema:
            type: string
          name: namez
          in: query
        - schema:
            type: string
            default: namez
          name: sortBy
          in: query`

so to me the issue is not in vacuum but rather in libopenapi , may be somewhere there in the utility_methods.go , scanOperationParams

but debugging more looks it is even deeper as the index looks already corrupted at this stage

LasneF avatar Apr 15 '25 07:04 LasneF

resolved in v0.16.6

daveshanley avatar Apr 27 '25 01:04 daveshanley