2015-09-08 38 views
1

我想以這種格式形成一個swagger文檔。響應是下面的200個http代碼的json。我無法形成如下所示的json。swagger-ui如何在模式數組中形成多個響應

[ 
    { 
    "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

回答

2

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 
相關問題