See regular expressions used for format validation and the sources that were used in formats.ts.
Please note: JSON Schema draft-07 also defines formats iri, iri-reference, idn-hostname and idn-email for URLs, hostnames and emails with international characters. These formats are available in ajv-formats-draft2019 plugin.
Keywords to compare values: formatMaximum / formatMinimum and formatExclusiveMaximum / formatExclusiveMinimum
These keywords allow to define minimum/maximum constraints when the format keyword defines ordering (compare function in format definition).
These keywords are added to ajv instance when ajv-formats is used without options or with option keywords: true.
These keywords apply only to strings. If the data is not a string, the validation succeeds.
The value of keywords formatMaximum/formatMinimum and formatExclusiveMaximum/formatExclusiveMinimum should be a string or $data reference. This value is the maximum (minimum) allowed value for the data to be valid as determined by format keyword. If format keyword is not present schema compilation will throw exception.
When these keyword are added, they also add comparison functions to formats "date", "time" and "date-time". User-defined formats also can have comparison functions. See addFormat method.
Options can be passed via the second parameter. Options value can be
The list of format names that will be added to ajv instance:
addFormats(ajv, ["date", "time"])
Please note: when ajv encounters an undefined format it throws exception (unless ajv instance was configured with strict: false option). To allow specific undefined formats they have to be passed to ajv instance via formats option with true value:
const ajv = new Ajv({formats: {date: true, time: true}}) // to ignore "date" and "time" formats in schemas.
Format validation mode (default is "full") with optional list of format names and keywords option to add additional format comparison keywords:
In "fast" mode the following formats are simplified: "date", "time", "date-time", "iso-time", "iso-date-time", "uri", "uri-reference", "email". For example, "date", "time" and "date-time" do not validate ranges in "fast" mode, only string structure, and other formats have simplified regular expressions.
ajv-formats
JSON Schema formats for Ajv
Usage
Formats
The package defines these formats:
See regular expressions used for format validation and the sources that were used in formats.ts.
Please note: JSON Schema draft-07 also defines formats
iri,iri-reference,idn-hostnameandidn-emailfor URLs, hostnames and emails with international characters. These formats are available in ajv-formats-draft2019 plugin.Keywords to compare values:
formatMaximum/formatMinimumandformatExclusiveMaximum/formatExclusiveMinimumThese keywords allow to define minimum/maximum constraints when the format keyword defines ordering (
comparefunction in format definition).These keywords are added to ajv instance when ajv-formats is used without options or with option
keywords: true.These keywords apply only to strings. If the data is not a string, the validation succeeds.
The value of keywords
formatMaximum/formatMinimumandformatExclusiveMaximum/formatExclusiveMinimumshould be a string or $data reference. This value is the maximum (minimum) allowed value for the data to be valid as determined byformatkeyword. Ifformatkeyword is not present schema compilation will throw exception.When these keyword are added, they also add comparison functions to formats
"date","time"and"date-time". User-defined formats also can have comparison functions. See addFormat method.Options
Options can be passed via the second parameter. Options value can be
Please note: when ajv encounters an undefined format it throws exception (unless ajv instance was configured with
strict: falseoption). To allow specific undefined formats they have to be passed to ajv instance viaformatsoption withtruevalue:"full") with optional list of format names andkeywordsoption to add additional format comparison keywords:or
In
"fast"mode the following formats are simplified:"date","time","date-time","iso-time","iso-date-time","uri","uri-reference","email". For example,"date","time"and"date-time"do not validate ranges in"fast"mode, only string structure, and other formats have simplified regular expressions.Tests
License
MIT