swagger-ui 如何在模式数组中形成多个响应

swagger-ui how to form multiple responses in schema array

我正在尝试以这种格式形成一个 swagger 文档。响应是下面 json 上的 200 http 代码。我无法形成如下所示的 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) 必须存在于对象中 "alone"。因此,您的 items 块中不能有多个指针:

  "$ref": "#/definitions/res1",
  "$ref": "#/definitions/res2"

将忽略第二个参考 (res2) 并且只应用第一个。

对于您想要做的事情,您有很多选择。可能最简单的是这样的:

type: array
items:
  $ref: '#/definitions/Pair'

并有这样的定义:

definitions:
  Pair:
    properties:
      key:
        type: string
      value:
        type: string