json-schema-vocabularies icon indicating copy to clipboard operation
json-schema-vocabularies copied to clipboard

Request: Add relative validation support and keywords for date,date-time

Open tars400 opened this issue 4 years ago • 4 comments

We need to support relative validation on json-schema for date format.

Is there any existing support where relative validations are supported for 'date' or 'date-time' formats ?, as the current schema supports only absolute validation with formatMinimum and formatMaximum.

Something like below:

{
	type: 'string',
	format: 'date',
	formatMinimum: '2019-08-16',	
	formatMaximum: '2022-08-16',	
	relativeMinimumDate: -50,	// -ve for current day - number of days
	relativeMaximumDate: 20,       //  +ve for current day + number of days 
	//  considering the above example, input date should be between last 50 days to coming 20 days.
}

relative minimum and relative maximum format would validate on date relatively example: last 1 year, last 20 days, last 12 months etc

tars400 avatar Sep 07 '21 14:09 tars400

Hi @tars400. We don't have any keywords which dynamically use content from the instance like you're proposing. We do have several proposals for accessing instance data dynamically.

I can't imagine we will get this into the spec any time soon.

You CAN now write your own extension (vocabulary), but you would be dependent on providing implementations for it to work.

Relequestual avatar Sep 07 '21 14:09 Relequestual

the current schema supports only absolute validation with formatMinimum and formatMaximum

These aren't keywords in the official JSON Schema specification. Perhaps your particular implementation added them?

karenetheridge avatar Sep 07 '21 17:09 karenetheridge

You CAN now write your own extension (vocabulary), but you would be dependent on providing implementations for it to work.

@Relequestual could you point me to the best guide explaining how to write our own extensions? I found this page but by itself doesn't point to any guide :/

sandrina-p avatar Jun 29 '23 12:06 sandrina-p

Here are a couple implementation specific guides you might find useful.

  • https://docs.json-everything.net/schema/vocabs/
  • https://github.com/hyperjump-io/json-schema#meta-schemas-keywords-vocabularies-and-dialects-experimental

jdesrosiers avatar Jul 04 '23 18:07 jdesrosiers