[英]swagger-ui how to form multiple responses in schema array
我正在嘗試以這種格式形成一個龐大的文檔。 響應是200 http代碼上的以下json。 我無法形成如下所示的json。
[
{
"key":"test1",
"val":"val1"
},
{
"key":"test2",
"val":"val2"
},
{
"key":"test3",
"val":"val3"
}
]
到目前為止,我有這個:
"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"
}
}
}
但是我根本看不到res2
塊。 我只看到res1
JSON指針( $ref
)必須“單獨”存在於對象中。 因此,您的items
塊中不能有多個指針:
"$ref": "#/definitions/res1",
"$ref": "#/definitions/res2"
將忽略第二個參考( res2
),僅應用第一個。
對於您想做的事情,您有很多選擇。 最簡單的可能是這樣的:
type: array
items:
$ref: '#/definitions/Pair'
並具有如下定義:
definitions:
Pair:
properties:
key:
type: string
value:
type: string
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.