6

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?

1
  • I myself asked the same question. However is it even good to use such a pattern? Wouldn't it make more sense to always transmit a datetime and an allday boolean flag instead? I am not sure, its 50:50, maybe you can give me a better opinion on that. Commented May 21, 2022 at 17:32

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.