2

我正在尝试以这种格式形成一个招摇的文档。响应是 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

4

1 回答 1

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
于 2015-09-09T04:52:33.810 回答