如何为在swagger中未知密钥的键/值建模

Koe*_*ers 5 swagger

我有一个简单的JSON对象,可以包含前面不知道确切值的键/值.它们依赖于某些服务器端进程.如何在招摇中模拟这个?

JSON的一个例子是:

... 
,message: "invalid length. Must be in between {min} and {max}" 
,attributes: {
  min: 0
  ,max: 6
}
...
Run Code Online (Sandbox Code Playgroud)

另一个例子是:

... 
,message: "You must fill out this field as well because {field} has a value" 
,attributes: {
  field: "age"
}
...
Run Code Online (Sandbox Code Playgroud)

Ron*_*Ron 7

以下解决方案仅适用于Swagger 2.0.

如下所述定义模型:

{
    "type": "object",
    "properties": {
        "message": {
            "type": "string"
        },
        "attributes": {
            "type": "object",
            "additionalProperties": {}
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这描述attributes为属性映射,其中值可以是任何值(字符串,数字,数组甚至是对象).