I am trying to form a swagger document in this format. The response is the below json on 200 http code. I am unable to form a json like below.
[
{
"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. I just see res1
JSON pointers ( $ref
) must live "alone" in an object. Thus you cannot have multiple pointers in your items
block:
"$ref": "#/definitions/res1",
"$ref": "#/definitions/res2"
will ignore the 2nd reference ( res2
) and only apply the first.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.