的映射我需要使用Swagger为使用字符串键索引的对象映射使用(既作为输入又作为输出)的API文档。Swagger:<string,Object>
例子:
{
"a_property": {
"foo": {
"property_1": "a string 1",
"property_2": "a string 2"
},
"bar": {
"property_1": "a string 3",
"property_2": "a string 4"
}
}
}
“foo”和“酒吧”可以是任何字符串键,但他们应该是一组键中是唯一的。
我知道,有扬鞭,我可以定义对象的数组,但是这给不同的API,因为我们是那么就会有一些:
{
"a_property": [
{
"key": "foo"
"property_1": "a string 1",
"property_2": "a string 2"
},
{
"key": "bar"
"property_1": "a string 3",
"property_2": "a string 4"
}
]
}
我看了'Open API Specification' - 'Add support for Map data types #38'页面。据我了解,它建议使用additionalProperties,但它似乎不回答我的需要(或它不适用于我使用的Swagger UI 2.1.4)。 我错过了什么吗?
到目前为止,我已经找到了以下变通(在扬鞭JSON):
a_property: {
description: "This is a map that can contain several objects indexed by different keys.",
type: object,
properties: {
key: {
description: "map item",
type: "object",
properties: {
property_1: {
description: "first property",
type: string
},
property_2: {
description: "second property",
type: string
}
}
}
}
}
这几乎做工作,但读者必须明白“键”可以是任何字符串,可以重复多次。
有没有更好的方法来实现我所需要的?
个人情况下,我花了一些时间了解*为什么''additionalProperties'是正确答案:http://stackoverflow.com/a/41240118/110488 –