Swagger openapi:引用列表中的现有示例
我有一个OpenAPI 3.0.0规范,其中包含一个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
小部件
组件,其中包括一个示例
部分:
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#谢谢!我修正了问题中的错误语法;那是一个抄写错误。