[英]swagger-ui how to form multiple responses in schema array
I am trying to form a swagger document in this format. 我正在尝试以这种格式形成一个庞大的文档。 The response is the below json on 200 http code.
响应是200 http代码上的以下json。 I am unable to form a json like below.
我无法形成如下所示的json。
[
{
"key":"test1",
"val":"val1"
},
{
"key":"test2",
"val":"val2"
},
{
"key":"test3",
"val":"val3"
}
]
so far I have this: 到目前为止,我有这个:
"responses": {
"200": {
"description": "response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/res1",
"$ref": "#/definitions/res2"
}
}
}
}
"definitions": {
"res1": {
"type": "object",
"properties": {
"key": {
"type": "string",
"example": "test1"
},
"keyURL": {
"type": "string",
"example": "val1"
}
}
},
"res2": {
"type": "object",
"properties": {
"key": {
"type": "string",
"example": "test2"
},
"val": {
"type": "string",
"example": "val2"
}
}
}
But I dont see the res2
block at all. 但是我根本看不到
res2
块。 I just see res1
我只看到
res1
JSON pointers ( $ref
) must live "alone" in an object. JSON指针(
$ref
)必须“单独”存在于对象中。 Thus you cannot have multiple pointers in your items
block: 因此,您的
items
块中不能有多个指针:
"$ref": "#/definitions/res1",
"$ref": "#/definitions/res2"
will ignore the 2nd reference ( res2
) and only apply the first. 将忽略第二个参考(
res2
),仅应用第一个。
For what you're trying to do, you have many options. 对于您想做的事情,您有很多选择。 Probably the easiest is something like this:
最简单的可能是这样的:
type: array
items:
$ref: '#/definitions/Pair'
and having definitions like such: 并具有如下定义:
definitions:
Pair:
properties:
key:
type: string
value:
type: string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.