2016-09-27 72 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 
相关问题