Skip to content

Question: Is it possible define minimum and maximum limits for date/datetime #2827

Closed Answered by flaksp
Havunen asked this question in Q&A
Discussion options

You must be logged in to vote

As webron said it's not possible to add such constraints using OpenAPI or JSON Schema as-is. Only with hacks like using pattern keyword, or you should redesign your API to use UNIX timestamps so you will be able to use minimum and maximum keywords.

However JSON Schema specification says it's pretty valid to add custom keywords like this:

type: string
format: date
minimumDate: 1996-12-19
maximumDate: 2021-12-19

Custom keywords minimumDate and maximumDate will be ignored (treated as annotations) by most tools. But if tools you are using support some kind of extensions or plugins you may "tune" them to recognise these keywords and you may write your own logic around this. If your tools don't…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@rosdi
Comment options

Comment options

You must be logged in to vote
1 reply
@handrews
Comment options

Answer selected by handrews
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
5 participants
Converted from issue

This discussion was converted from issue #2822 on December 15, 2021 11:12.