你能在 OpenAPI 中指定两种格式吗?

Can you specify two formats in OpenAPI?

我需要 JSON 方案中的一个字段为日期或日期时间。它可以具有任何这些格式。使用 format 属性,是否可以同时使用两种格式?

在 OpenAPI 3.x 中,您可以使用 anyOf:

type: string
anyOf:
  - format: date
  - format: date-time

OpenAPI 2.0 (swagger: '2.0') 不支持 anyOf,但作为解决方法,您可以提供自定义正则表达式 pattern 而不是 format.