Skip to content

Allow implicit path parameter matching #132

@DavidBiesack

Description

@DavidBiesack

Say a Swagger 2.0 API has the following paths (I'm using YAML here, as it's easier to write and read)

...
paths:
  /products
  /products/{productId}
  /products/{productId}/design
  /products/{productId}/marketing
  /products/{productId}/engineering

I can define productId once in Parameters Definitions Object and $ref it as per Reference Object:

  /products/{productId}
        parameters:
           - { $ref: productId }
        get: ....
  /products/{productId}/design
        parameters:
           - { $ref: productId }
        get: ....
  /products/{productId}/marketing
        parameters:
           - { $ref: productId }
        get: ....
  /products/{productId}/engineering
        parameters:
           - { $ref: productId }
        get: ....
parameters:
  productId: 
       name: productId
       in: path
       type: string
       required: true

but this gets pretty verbose pretty quickly. (Note: I think the editor incorrectly flags this as an error.)

Swagger should automatically match a path parameter with a definition (by {paramName} and { name: paramName, in: path} )

I could still override it if I don't want the common def, which would be no more work than currently.

This would help greatly in cases like the above where the same path parameter is used in multiple separate paths, doubly so for paths that have multiple path parameters.

tony tam replied on this Swagger Google Groups thread that this is intentional to avoid ambiguity. I think this is unnecessarily cumbersome, repetitive, error prone, and a maintenance nightmare. I'd like this to be reconsidered, not just as a tooling convenience, but in the spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions