Can you specify two formats in OpenAPI?

I need that a field on my JSON scheme to be either date or datetime. It can have any of those formats. Using the format property, is it possible to use both formats?


In OpenAPI 3.x, you can use anyOf:

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

OpenAPI 2.0 (swagger: '2.0') does not support anyOf, but as a workaround you can provide a custom regex pattern instead of the format.