Swagger openapi:引用列表中的现有示例

Swagger openapi:引用列表中的现有示例,swagger,openapi,Swagger,Openapi,我有一个OpenAPI 3.0.0规范,其中包含一个小部件组件,其中包括一个示例部分: components: schemas: Widget: properties: id: type: string description: type: string cost: type: float example: id: 1234

我有一个OpenAPI 3.0.0规范,其中包含一个
小部件
组件,其中包括一个
示例
部分:

components:
  schemas:
    Widget:
      properties:
        id:
          type: string
        description:
          type: string
        cost:
          type: float
      example:
        id: 1234
        description: An example widget
        cost: 0.10
我正在添加一个
Warehouse
组件,其中包括
小部件的列表。是否有方法使用
仓库
模式中
小部件
模式上的
示例
?比如:

    Warehouse:
      properties:
        id:
          type: string
        location:
          type: string
        widgets:
          type: array
          items:
            $ref: '#/components/schemas/Widget'
      example:
        id: 4321
        widgets:
          - $ref: '#/components/schemas/Widget'

上述方法不起作用。我查看了如何将
示例
小部件
模式中移动到
#/components/examples/WidgetExample
,但我仍然不确定该语法是什么意思。

示例
关键字不支持
$ref

您可以改为将
仓库
模式更改为对
小部件
以外的属性使用属性级示例,在这种情况下,
小部件
的示例将“继承”自
小部件
模式。至少这是它在Swagger UI和Swagger编辑器中的工作方式

仓库:
特性:
身份证件:
类型:字符串

示例:4321#谢谢!我修正了问题中的错误语法;那是一个抄写错误。