parameters-unique

Since 0.0.1 · fixed by --fix · In the rulesets: Recommended at error, Strict at error, All at error

This rule checks that no path item or operation declares two parameters with the same name and location.

Rule details

A name and a location identify a parameter: two declarations of id in the path are one parameter with two definitions, and each tool picks one of them. The same name in two locations, id in the path and id in the query, is two parameters and is allowed.

The rule reports Duplicate parameter name '...' in location '...' on the later declaration.

Examples

Good. Two parameters, two names.

paths:
  /users/{id}:
    get:
      parameters:
        - name: id
          in: path
          description: The ID of the user to retrieve.
          required: true
          schema:
            type: string
        - name: with-relations
          in: query
          description: If true, also returns related resources.
          required: false
          schema:
            type: boolean

Good. The same name in two locations.

paths:
  /users/{id}:
    get:
      parameters:
        - name: id
          in: path
          description: The ID of the user to retrieve.
          required: true
          schema:
            type: string
        - name: id
          in: query
          description: Confusing, but allowed.
          required: false
          schema:
            type: boolean

Bad. id in the path twice, with two types.

paths:
  /users/{id}:
    get:
      parameters:
        - name: id
          in: path
          description: The ID of the user to retrieve.
          required: true
          schema:
            type: string
        - name: id
          in: path
          description: The ID of the user to retrieve.
          required: true
          schema:
            type: boolean

Automatic fixes

--fix removes a later duplicate when its definition is identical to the first one. Duplicates that differ stay for you to merge.

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.rules has the details.

commands:
  lint:
    rules:
      parameters-unique: off
Was this helpful?