2016-09-27 73 views
0

我有一些API返回以下響應。我該如何使用swagger來完成文檔?我知道swagger responseContainer支持Map,但是地圖的值類型似乎必須是相同的類型。但在我的情況下,值是不同的類型:foos是List的類型,第二個鍵「count」對應於整數。swagger如何處理immutableMap(使用不同類型的值)響應?

Response.ok(ImmutableMap.of("result", foos, "count", foos.size())).build(); 

API的迴應是這樣的:

{ 
    "result": [ 
    { 
     "f1": "v1", 
     "f2": "v2" 
    }, 
    { 
     "f1": "v3", 
     "f2": "v4" 
    } 
    ], 
    "count": 2 
} 

回答

0

你的反應可以這樣描述:

definitions: 
    MyResponse: 
    type: object 
    required: 
     - result 
     - count 
    properties: 
     result: 
     type: array 
     items: 
      $ref: '#/definitions/Foo' 
     count: 
     type: integer 

    Foo: 
    type: object 
    additionalProperties: 
     type: string 
相關問題