Ben Randall Ben Randall - 3 months ago 32
YAML Question

Define shared path parameter that can be re-used by multiple paths with Swagger

I've got a series of paths that use the same path parameter:

paths:
/catalog/items/{id}:
...
/catalog/items/{id}/children:
...
etc.


I would like the {id} parameter to be defined once with a description and type so that I can reuse it, but this appears to be invalid:

paths:
...
parameters:
catalogItemId: # <-- Not a valid parameter definition
name: id
in: path
description: The ID of the catalog item to update.
required: false
type: integer
format: int64


It doesn't seem like this should be invalid according to the schema linked by the editor (http://swagger.io/v2/schema.json#), but for some reason this is rejected by the online editor.

Is there anyway to share path parameter definitions?

Answer

Shortly after posting this I realized that the path parameter was listed as

required: false

Path parameters MUST be required for Swagger API definitions. Changing that to true fixed everything up. It's just a side effect of the way the schema validation occurs that causes a non descriptive error to get dumped out.

Comments