如何定义一个未知名称的swagger属性?

时间:2016-06-22 18:08:38

标签: swagger

我需要定义一个没有已知名称的swagger属性。

{
  "type": "object",
  "properties": {
      "?????": {
          "type": "array",
          "items": { "$ref": "#/definitions/ModelRelease" }
      }
}

?????我定义的一部分是一个未知值的整数。有什么想法吗?

2 个答案:

答案 0 :(得分:11)

你可以使用additionalProperties定义一个hashmap(“?????”是这个hashmap中的一个键而不需要定义它):

{ 
  "type": "object", 
  "additionalProperties": { 
    "type": "array", 
    "items": { 
      "$ref": "#/definitions/ModelRelease" 
    }
  }
} 

在一般情况下,哈希地图可以包含任意数量的项目,但您可以使用minPropertiesmaxProperties来限制项目数。例如,如果您的对象必须只有一个属性:

{ 
  "type": "object",
  "additionalProperties": {
    "type": "array",
    "items": {
      "$ref": "#/definitions/ModelRelease" 
    }
  },
  "minProperties": 1,
  "maxProperties": 1
}

答案 1 :(得分:0)

我认为您想要定义一个任意的自由格式对象,它表示为OpenAPI / Swagger规范:

{
    "type": "object"
}