-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
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.