Skip to content

Duplicated path parameter in a path is deemed invalid #278

Closed

Description

@jamietanna

As part of triaging an issue raised in oapi-codegen/oapi-codegen#1574 I noticed that vacuum (and therefore libopenapi) seemed to see this as an error, too.

Via the other issue, the spec in question:

openapi: 3.0.3
paths:
  /admin/realms/{realm}/clients/{client-uuid}/roles/{role-name}/composites/clients/{client-uuid}:
    get:
      tags:
      - Roles
      summary: Get client-level roles for the client that are in the role's composite
      parameters:
      - name: client-uuid
        in: path
        required: true
        schema:
          type: string
      - name: role-name
        in: path
        description: role's name (not id!)
        required: true
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/RoleRepresentation'
    parameters:
    - name: realm
      in: path
      description: realm name (not id!)
      required: true
      schema:
        type: string

Which fails with:

/proc/self/fd/11:3:3   | error    | Path `/admin/realms/{realm}/clients/{client-uuid}/roles/{role-name}/composites/c...     | path-params                | Operations   | $.paths.['/admin/realms/{realm}/clients/{client-uuid}/roles/...

(Aside: should I raise a separate issue to allow word wrapping / allow not truncating the output?

I've also attached an HTML report from vacuum 0.5.9-1

https://gist.github.com/jamietanna/8fe64d84a31c60fe03300f627c730e82

Activity

  1. daveshanley commented on Apr 25, 2024

    @daveshanley
    Member

    Hi Jamie,

    This is actually by design. The rule that is triggering this is path-params (https://quobix.com/vacuum/rules/operations/path-params/)

    The rule is checking for multiple things, including 'Duplicate parameter names in paths`'

    It's not a bug in libopenapi, it's not a bug in vacuum - it's by design.

    Also the formatting thing is a known issue, it's marked as a todo in vacuum (https://github.com/daveshanley/vacuum/blob/main/cmd/lint.go#L400)

  2. added
    invalid
    on Apr 25, 2024
  3. evankanderson commented on May 3, 2024

    @evankanderson

    I'm slightly confused; the API doctor rule seems to be covering best practices, but the linked OpenAPI spec doesn't seem to forbid duplicated parameters.

    I can understand why this isn't an API best practice -- it introduces unnecessary stutter in the API surface, and leads to the question of what to do when the two instances don't match (presumably, the request is invalid on the server side). On the other hand, this appears to happen in the wild (Keycloak is one example), and other implementations seem to be able to generate clients for this at least.

  4. daveshanley commented on May 4, 2024

    @daveshanley
    Member

    This isn't a libopenapi issue to be honest, it's a vacuum one. Even then vacuum is a linter, it's not a code generator, it's going to tell you to pay attention to certain things, however that won't prevent the spec from working with other tools that may or may not support that particular function.

    The purpose of the tooling is to draw attention to problem areas, because 'in the wild' is just that, anything goes and folks do some crazy stuff with OpenAPI specs. the goal is to help clean things up.

    The good news is that all rules can be customized, the levels changed, or disabled completely if they conflict with a pattern you're happy with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions