如何为 Swagger 中的密钥未知的 key/value 建模

How do I model a key/value for which the key is not known in Swagger

我有一个简单的 JSON 对象,它可以包含 key/values 的确切值事先不知道。它们依赖于某些服务器端进程。我如何在 Swagger 中对此建模?

JSON 的一个例子是:

... 
,message: "invalid length. Must be in between {min} and {max}" 
,attributes: {
  min: 0
  ,max: 6
}
...

另一个例子是:

... 
,message: "You must fill out this field as well because {field} has a value" 
,attributes: {
  field: "age"
}
...

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

按如下所述定义模型:

{
    "type": "object",
    "properties": {
        "message": {
            "type": "string"
        },
        "attributes": {
            "type": "object",
            "additionalProperties": {}
        }
    }
}

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