-
Hi, I have been trying to figure out how I could add limits to datetime / date based properties / values in open api 3 schema. https://swagger.io/docs/specification/data-models/data-types/ describes that string can have min length and max length properties but I would like to provide minimum and maximum value for the date
Something similar what integer has:
Something like this?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
The short answer is 'no', as validation modifiers can be at most restricted to specific types, but not formats. That said, you can still add a regex to validate a given date range. |
Beta Was this translation helpful? Give feedback.
-
As webron said it's not possible to add such constraints using OpenAPI or JSON Schema as-is. Only with hacks like using 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 |
Beta Was this translation helpful? Give feedback.
-
This seems to have been answered pretty thoroughly, closing. |
Beta Was this translation helpful? Give feedback.
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 useminimum
andmaximum
keywords.However JSON Schema specification says it's pretty valid to add custom keywords like this:
Custom keywords
minimumDate
andmaximumDate
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…