我正试图以这种格式形成一个招摇文件。响应是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
答案 0 :(得分:3)
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