使用 Swagger 定义可被多个路径重用的共享路径参数

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

我有一系列使用相同路径参数的路径:

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

我希望使用描述和类型定义一次 {id} 参数,以便我可以重复使用它,但这似乎无效:

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

根据编辑器 (http://swagger.io/v2/schema.json#) 链接的模式,似乎 这样应该是无效的,但出于某种原因,这被拒绝了在线编辑器。

有没有共享路径参数定义的?

发布后不久,我意识到路径参数被列为

required: false

Swagger API 定义必须需要路径参数。将其更改为 true 可以解决所有问题。这只是模式验证发生方式的副作用,导致非描述性错误被转储。