没有名称的 Swagger 字符串数组

Swagger array of strings without name

目前我正在尝试为我的软件创建一个 swagger 文件。 现在我想为 timeRange 创建一个定义。 我的问题是这个数组看起来像这样:

timeRange: {
  "2016-01-15T09:00:00.000Z", // this is the start date
  "2017-01-15T09:00:00.000Z" // this is the end date
}

如何创建开箱即用的示例值? 是一个"array of strings",最少有两个。

"timeRange": {
  "type": "array",
  "items": {
    "type": "string",
    "example": "2017-01-15T09:00:00.000Z,2017-01-15T09:00:00.000Z"
  }
}

这会生成如下示例:

"timeRange": [
  "2017-01-15T09:00:00.000Z,2017-01-15T09:00:00.000Z"
]

这个例子不起作用,因为它是一个数组而不是一个对象。 全部一起: 我如何实现一个存在于两个不同字符串(没有名称)中的示例值。

希望你能帮助我! 干杯!

timeRange: {
  "2016-01-15T09:00:00.000Z", // this is the start date
  "2017-01-15T09:00:00.000Z" // this is the end date
}

无效 JSON – "timeRange" 需要用引号引起来,object/array 语法应该不同。

如果使用对象语法 {},值需要命名为属性:

"timeRange": {
  "start_date": "2016-01-15T09:00:00.000Z",
  "end_date": "2017-01-15T09:00:00.000Z"
}

否则timeRange需要是一个[]数组:

"timeRange": [
  "2016-01-15T09:00:00.000Z",
  "2017-01-15T09:00:00.000Z"
]


在第一个示例({} 对象)中,您的 Swagger 将如下所示,每个名为 属性:

的单独 example
"timeRange": {
  "type": "object",
  "properties": {
    "start_date": {
      "type": "string",
      "format": "date-time",
      "example": "2016-01-15T09:00:00.000Z"
    },
    "end_date": {
      "type": "string",
      "format": "date-time",
      "example": "2017-01-15T09:00:00.000Z"
    }
  },
  "required": ["start_date", "end_date"]
}

如果是 [] 数组,您可以指定一个数组级 example,它是一个多项目数组:

"timeRange": {
  "type": "array",
  "items": {
    "type": "string",
    "format": "date-time"
  },
  "example": [
    "2016-01-15T09:00:00.000Z",
    "2017-01-15T09:00:00.000Z"
  ]
}