【发布时间】:2018-04-15 06:31:14
【问题描述】:
使用此架构定义:
schemas:
AllContacts:
type: array
items:
$ref: '#/definitions/ContactModel1'
example:
- id: 1
firstName: Sherlock
lastName: Holmes
- id: 2
firstName: John
lastName: Watson
我得到了这个预期的结果:
[
{
"id": 1,
"firstName": "Sherlock",
"lastName": "Holmes"
},
{
"id": 2,
"firstName": "John",
"lastName": "Watson"
}
]
现在我想为单个用户 (ContactModel1) 和作为一组用户 (AllContacts) 的一部分重复使用 Holmes 示例。但是如果我使用引用的例子:
schemas:
AllContacts:
type: array
items:
$ref: '#/definitions/ContactModel1'
example:
Homes:
$ref: '#/components/examples/Homes'
Watson:
$ref: '#/components/examples/Watson'
examples:
Holmes:
value:
id: 1
first_name: Sherlock
last_name: Holmes
Watson:
value:
id: 2
first_name: John
last_name: Watson
我在 Swagger UI 中得到了这个意想不到的结果:
[
{
"value": {
"id": 1,
"first_name": "Sherlock",
"last_name": "Holmes",
},
"$$ref": "#/components/examples/Holmes"
},
{
"value": {
"id": 2,
"first_name": "John",
"last_name": "Watson",
},
"$$ref": "#/components/examples/Watson"
}
]
以及GET /user/1 的类似意外示例:
[
{
"value": {
"id": 1,
"first_name": "Sherlock",
"last_name": "Holmes",
},
"$$ref": "#/components/examples/Holmes"
}
]
我做错了什么?
我使用此文档作为参考:
https://swagger.io/docs/specification/adding-examples/#reuse
【问题讨论】:
-
EXAMPLE 下的 Homes(和 Watson)行在这个问题中错误地丢失了冒号,而不是在我的代码中。我的道歉
标签: swagger-ui openapi