Custom JSON-\/\+Schema keywords for \href{https://github.com/epoberezkin/ajv}{\texttt{ Ajv}} validator

\href{https://travis-ci.org/ajv-validator/ajv-keywords}{\texttt{ }} \href{https://www.npmjs.com/package/ajv-keywords}{\texttt{ }} \href{https://www.npmjs.com/package/ajv-keywords}{\texttt{ }} \href{https://coveralls.io/github/ajv-validator/ajv-keywords?branch=master}{\texttt{ }} \href{https://app.dependabot.com/accounts/ajv-validator/repos/60477053}{\texttt{ }} \href{https://gitter.im/ajv-validator/ajv}{\texttt{ }}\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2692}{}\doxysection{Contents}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2692}

\begin{DoxyItemize}
\item \href{\#install}{\texttt{ Install}}
\item \href{\#usage}{\texttt{ Usage}}
\item \href{\#keywords}{\texttt{ Keywords}}
\begin{DoxyItemize}
\item \href{\#types}{\texttt{ Types}}
\begin{DoxyItemize}
\item \href{\#typeof}{\texttt{ typeof}}
\item \href{\#instanceof}{\texttt{ instanceof}}
\end{DoxyItemize}
\item \href{\#keywords-for-numbers}{\texttt{ Keywords for numbers}}
\begin{DoxyItemize}
\item \href{\#range-and-exclusiverange}{\texttt{ range and exclusive\+Range}}
\end{DoxyItemize}
\item \href{\#keywords-for-strings}{\texttt{ Keywords for strings}}
\begin{DoxyItemize}
\item \href{\#regexp}{\texttt{ regexp}}
\item \href{\#formatmaximum--formatminimum-and-formatexclusivemaximum--formatexclusiveminimum}{\texttt{ format\+Maximum / format\+Minimum and format\+Exclusive\+Maximum / format\+Exclusive\+Minimum}}
\item \href{\#transform}{\texttt{ transform}}\textsuperscript{$\ast$}
\end{DoxyItemize}
\item \href{\#keywords-for-arrays}{\texttt{ Keywords for arrays}}
\begin{DoxyItemize}
\item \href{\#uniqueitemproperties}{\texttt{ unique\+Item\+Properties}}
\end{DoxyItemize}
\item \href{\#keywords-for-objects}{\texttt{ Keywords for objects}}
\begin{DoxyItemize}
\item \href{\#allrequired}{\texttt{ all\+Required}}
\item \href{\#anyrequired}{\texttt{ any\+Required}}
\item \href{\#onerequired}{\texttt{ one\+Required}}
\item \href{\#patternrequired}{\texttt{ pattern\+Required}}
\item \href{\#prohibited}{\texttt{ prohibited}}
\item \href{\#deepproperties}{\texttt{ deep\+Properties}}
\item \href{\#deeprequired}{\texttt{ deep\+Required}}
\end{DoxyItemize}
\item \href{\#compound-keywords}{\texttt{ Compound keywords}}
\begin{DoxyItemize}
\item \href{\#switch}{\texttt{ switch}} (deprecated)
\item \href{\#selectselectcasesselectdefault}{\texttt{ select/select\+Cases/select\+Default}} (BETA)
\end{DoxyItemize}
\item \href{\#keywords-for-all-types}{\texttt{ Keywords for all types}}
\begin{DoxyItemize}
\item \href{\#dynamicdefaults}{\texttt{ dynamic\+Defaults}}\textsuperscript{$\ast$}
\end{DoxyItemize}
\end{DoxyItemize}
\item \href{\#security-contact}{\texttt{ Security contact}}
\item \href{\#open-source-software-support}{\texttt{ Open-\/source software support}}
\item \href{\#license}{\texttt{ License}}
\end{DoxyItemize}

\textsuperscript{$\ast$} -\/ keywords that modify data\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2693}{}\doxysection{Install}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2693}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install ajv-\/keywords }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2694}{}\doxysection{Usage}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2694}
To add all available keywords\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var Ajv = require('ajv');}
\DoxyCodeLine{var ajv = new Ajv;}
\DoxyCodeLine{require('ajv-\/keywords')(ajv);}
\DoxyCodeLine{}
\DoxyCodeLine{ajv.validate(\{ instanceof: 'RegExp' \}, /.*/); // true}
\DoxyCodeLine{ajv.validate(\{ instanceof: 'RegExp' \}, '.*'); // false }

\end{DoxyCode}


To add a single keyword\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords')(ajv, 'instanceof'); }

\end{DoxyCode}


To add multiple keywords\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords')(ajv, ['typeof', 'instanceof']); }

\end{DoxyCode}


To add a single keyword in browser (to avoid adding unused code)\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords/keywords/instanceof')(ajv); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2695}{}\doxysection{Keywords}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2695}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2696}{}\doxysubsection{Types}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2696}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2697}{}\doxysubsubsection{$<$tt$>$typeof$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2697}
Based on Java\+Script {\ttfamily typeof} operation.

The value of the keyword should be a string ({\ttfamily \char`\"{}undefined\char`\"{}}, {\ttfamily \char`\"{}string\char`\"{}}, {\ttfamily \char`\"{}number\char`\"{}}, {\ttfamily \char`\"{}object\char`\"{}}, {\ttfamily \char`\"{}function\char`\"{}}, {\ttfamily \char`\"{}boolean\char`\"{}} or {\ttfamily \char`\"{}symbol\char`\"{}}) or array of strings.

To pass validation the result of {\ttfamily typeof} operation on the value should be equal to the string (or one of the strings in the array).


\begin{DoxyCode}{0}
\DoxyCodeLine{ajv.validate(\{ typeof: 'undefined' \}, undefined); // true}
\DoxyCodeLine{ajv.validate(\{ typeof: 'undefined' \}, null); // false}
\DoxyCodeLine{ajv.validate(\{ typeof: ['undefined', 'object'] \}, null); // true }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2698}{}\doxysubsubsection{$<$tt$>$instanceof$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2698}
Based on Java\+Script {\ttfamily instanceof} operation.

The value of the keyword should be a string ({\ttfamily \char`\"{}\+Object\char`\"{}}, {\ttfamily \char`\"{}\+Array\char`\"{}}, {\ttfamily \char`\"{}\+Function\char`\"{}}, {\ttfamily \char`\"{}\+Number\char`\"{}}, {\ttfamily \char`\"{}\+String\char`\"{}}, {\ttfamily \char`\"{}\+Date\char`\"{}}, {\ttfamily \char`\"{}\+Reg\+Exp\char`\"{}}, {\ttfamily \char`\"{}\+Promise\char`\"{}} or {\ttfamily \char`\"{}\+Buffer\char`\"{}}) or array of strings.

To pass validation the result of {\ttfamily data instanceof ...} operation on the value should be true\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{ajv.validate(\{ instanceof: 'Array' \}, []); // true}
\DoxyCodeLine{ajv.validate(\{ instanceof: 'Array' \}, \{\}); // false}
\DoxyCodeLine{ajv.validate(\{ instanceof: ['Array', 'Function'] \}, function()\{\}); // true }

\end{DoxyCode}


You can add your own constructor function to be recognised by this keyword\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{function MyClass() \{\}}
\DoxyCodeLine{var instanceofDefinition = require('ajv-\/keywords').get('instanceof').definition;}
\DoxyCodeLine{// or require('ajv-\/keywords/keywords/instanceof').definition;}
\DoxyCodeLine{instanceofDefinition.CONSTRUCTORS.MyClass = MyClass;}
\DoxyCodeLine{}
\DoxyCodeLine{ajv.validate(\{ instanceof: 'MyClass' \}, new MyClass); // true }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2699}{}\doxysubsection{Keywords for numbers}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2699}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2700}{}\doxysubsubsection{$<$tt$>$range$<$/tt$>$ and $<$tt$>$exclusive\+Range$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2700}
Syntax sugar for the combination of minimum and maximum keywords, also fails schema compilation if there are no numbers in the range.

The value of this keyword must be the array consisting of two numbers, the second must be greater or equal than the first one.

If the validated value is not a number the validation passes, otherwise to pass validation the value should be greater (or equal) than the first number and smaller (or equal) than the second number in the array. If {\ttfamily exclusive\+Range} keyword is present in the same schema and its value is true, the validated value must not be equal to the range boundaries.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{ range: [1, 3] \};}
\DoxyCodeLine{ajv.validate(schema, 1); // true}
\DoxyCodeLine{ajv.validate(schema, 2); // true}
\DoxyCodeLine{ajv.validate(schema, 3); // true}
\DoxyCodeLine{ajv.validate(schema, 0.99); // false}
\DoxyCodeLine{ajv.validate(schema, 3.01); // false}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{ range: [1, 3], exclusiveRange: true \};}
\DoxyCodeLine{ajv.validate(schema, 1.01); // true}
\DoxyCodeLine{ajv.validate(schema, 2); // true}
\DoxyCodeLine{ajv.validate(schema, 2.99); // true}
\DoxyCodeLine{ajv.validate(schema, 1); // false}
\DoxyCodeLine{ajv.validate(schema, 3); // false }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2701}{}\doxysubsection{Keywords for strings}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2701}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2702}{}\doxysubsubsection{$<$tt$>$regexp$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2702}
This keyword allows to use regular expressions with flags in schemas (the standard {\ttfamily pattern} keyword does not support flags).

This keyword applies only to strings. If the data is not a string, the validation succeeds.

The value of this keyword can be either a string (the result of {\ttfamily regexp.\+to\+String()}) or an object with the properties {\ttfamily pattern} and {\ttfamily flags} (the same strings that should be passed to Reg\+Exp constructor).


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: 'object',}
\DoxyCodeLine{  properties: \{}
\DoxyCodeLine{    foo: \{ regexp: '/foo/i' \},}
\DoxyCodeLine{    bar: \{ regexp: \{ pattern: 'bar', flags: 'i' \} \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{}
\DoxyCodeLine{  foo: 'Food',}
\DoxyCodeLine{  bar: 'Barmen'}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidData = \{}
\DoxyCodeLine{  foo: 'fog',}
\DoxyCodeLine{  bar: 'bad'}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2703}{}\doxysubsubsection{$<$tt$>$format\+Maximum$<$/tt$>$ / $<$tt$>$format\+Minimum$<$/tt$>$ and $<$tt$>$format\+Exclusive\+Maximum$<$/tt$>$ / $<$tt$>$format\+Exclusive\+Minimum$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2703}
These keywords allow to define minimum/maximum constraints when the format keyword defines ordering.

These keywords apply only to strings. If the data is not a string, the validation succeeds.

The value of keyword {\ttfamily format\+Maximum} ({\ttfamily format\+Minimum}) should be a string. This value is the maximum (minimum) allowed value for the data to be valid as determined by {\ttfamily format} keyword. If {\ttfamily format} is not present schema compilation will throw exception.

When this keyword is added, it defines comparison rules for formats {\ttfamily \char`\"{}date\char`\"{}}, {\ttfamily \char`\"{}time\char`\"{}} and {\ttfamily \char`\"{}date-\/time\char`\"{}}. Custom formats also can have comparison rules. See \href{https://github.com/epoberezkin/ajv\#api-addformat}{\texttt{ add\+Format}} method.

The value of keyword {\ttfamily format\+Exclusive\+Maximum} ({\ttfamily format\+Exclusive\+Minimum}) should be a boolean value. These keyword cannot be used without {\ttfamily format\+Maximum} ({\ttfamily format\+Minimum}). If this keyword value is equal to {\ttfamily true}, the data to be valid should not be equal to the value in {\ttfamily format\+Maximum} ({\ttfamily format\+Minimum}) keyword.


\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords')(ajv, ['formatMinimum', 'formatMaximum']);}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  format: 'date',}
\DoxyCodeLine{  formatMinimum: '2016-\/02-\/06',}
\DoxyCodeLine{  formatMaximum: '2016-\/12-\/27',}
\DoxyCodeLine{  formatExclusiveMaximum: true}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{var validDataList = ['2016-\/02-\/06', '2016-\/12-\/26', 1];}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidDataList = ['2016-\/02-\/05', '2016-\/12-\/27', 'abc']; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2704}{}\doxysubsubsection{$<$tt$>$transform$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2704}
This keyword allows a string to be modified before validation.

These keywords apply only to strings. If the data is not a string, the transform is skipped.

There are limitation due to how ajv is written\+:
\begin{DoxyItemize}
\item a stand alone string cannot be transformed. ie `data = \textquotesingle{}a'; ajv.\+validate(schema, data);{\ttfamily }
\item {\ttfamily currently cannot work with}ajv-\/pack\`{}
\end{DoxyItemize}

{\bfseries{Supported options\+:}}
\begin{DoxyItemize}
\item {\ttfamily trim}\+: remove whitespace from start and end
\item {\ttfamily trim\+Left}\+: remove whitespace from start
\item {\ttfamily trim\+Right}\+: remove whitespace from end
\item {\ttfamily to\+Lower\+Case}\+: case string to all lower case
\item {\ttfamily to\+Upper\+Case}\+: case string to all upper case
\item {\ttfamily to\+Enum\+Case}\+: case string to match case in schema
\end{DoxyItemize}

Options are applied in the order they are listed.

Note\+: {\ttfamily to\+Enum\+Case} requires that all allowed values are unique when case insensitive.

{\bfseries{Example\+: multiple options}} 
\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords')(ajv, ['transform']);}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: 'array',}
\DoxyCodeLine{  items: \{}
\DoxyCodeLine{    type:'string',}
\DoxyCodeLine{    transform:['trim','toLowerCase']}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var data = ['  MixCase  '];}
\DoxyCodeLine{ajv.validate(schema, data);}
\DoxyCodeLine{console.log(data); // ['mixcase']}

\end{DoxyCode}


{\bfseries{Example\+: {\ttfamily enumcase}}} 
\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords')(ajv, ['transform']);}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: 'array',}
\DoxyCodeLine{  items: \{}
\DoxyCodeLine{    type:'string',}
\DoxyCodeLine{    transform:['trim','toEnumCase'],}
\DoxyCodeLine{    enum:['pH']}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var data = ['ph',' Ph','PH','pH '];}
\DoxyCodeLine{ajv.validate(schema, data);}
\DoxyCodeLine{console.log(data); // ['pH','pH','pH','pH'] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2705}{}\doxysubsection{Keywords for arrays}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2705}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2706}{}\doxysubsubsection{$<$tt$>$unique\+Item\+Properties$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2706}
The keyword allows to check that some properties in array items are unique.

This keyword applies only to arrays. If the data is not an array, the validation succeeds.

The value of this keyword must be an array of strings -\/ property names that should have unique values across all items.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{ uniqueItemProperties: [ "{}id"{}, "{}name"{} ] \};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = [}
\DoxyCodeLine{  \{ id: 1 \},}
\DoxyCodeLine{  \{ id: 2 \},}
\DoxyCodeLine{  \{ id: 3 \}}
\DoxyCodeLine{];}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidData1 = [}
\DoxyCodeLine{  \{ id: 1 \},}
\DoxyCodeLine{  \{ id: 1 \}, // duplicate "{}id"{}}
\DoxyCodeLine{  \{ id: 3 \}}
\DoxyCodeLine{];}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidData2 = [}
\DoxyCodeLine{  \{ id: 1, name: "{}taco"{} \},}
\DoxyCodeLine{  \{ id: 2, name: "{}taco"{} \}, // duplicate "{}name"{}}
\DoxyCodeLine{  \{ id: 3, name: "{}salsa"{} \}}
\DoxyCodeLine{]; }

\end{DoxyCode}


This keyword is contributed by \href{https://github.com/blainesch}{\texttt{ @blainesch}}.\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2707}{}\doxysubsection{Keywords for objects}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2707}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2708}{}\doxysubsubsection{$<$tt$>$all\+Required$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2708}
This keyword allows to require the presence of all properties used in {\ttfamily properties} keyword in the same schema object.

This keyword applies only to objects. If the data is not an object, the validation succeeds.

The value of this keyword must be boolean.

If the value of the keyword is {\ttfamily false}, the validation succeeds.

If the value of the keyword is {\ttfamily true}, the validation succeeds if the data contains all properties defined in {\ttfamily properties} keyword (in the same schema object).

If the {\ttfamily properties} keyword is not present in the same schema object, schema compilation will throw exception.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  properties: \{}
\DoxyCodeLine{    foo: \{type: 'number'\},}
\DoxyCodeLine{    bar: \{type: 'number'\}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{  allRequired: true}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{ foo: 1, bar: 2 \};}
\DoxyCodeLine{var alsoValidData = \{ foo: 1, bar: 2, baz: 3 \};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidDataList = [ \{\}, \{ foo: 1 \}, \{ bar: 2 \} ]; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2709}{}\doxysubsubsection{$<$tt$>$any\+Required$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2709}
This keyword allows to require the presence of any (at least one) property from the list.

This keyword applies only to objects. If the data is not an object, the validation succeeds.

The value of this keyword must be an array of strings, each string being a property name. For data object to be valid at least one of the properties in this array should be present in the object.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  anyRequired: ['foo', 'bar']}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{ foo: 1 \};}
\DoxyCodeLine{var alsoValidData = \{ foo: 1, bar: 2 \};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidDataList = [ \{\}, \{ baz: 3 \} ]; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2710}{}\doxysubsubsection{$<$tt$>$one\+Required$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2710}
This keyword allows to require the presence of only one property from the list.

This keyword applies only to objects. If the data is not an object, the validation succeeds.

The value of this keyword must be an array of strings, each string being a property name. For data object to be valid exactly one of the properties in this array should be present in the object.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  oneRequired: ['foo', 'bar']}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{ foo: 1 \};}
\DoxyCodeLine{var alsoValidData = \{ bar: 2, baz: 3 \};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidDataList = [ \{\}, \{ baz: 3 \}, \{ foo: 1, bar: 2 \} ]; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2711}{}\doxysubsubsection{$<$tt$>$pattern\+Required$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2711}
This keyword allows to require the presence of properties that match some pattern(s).

This keyword applies only to objects. If the data is not an object, the validation succeeds.

The value of this keyword should be an array of strings, each string being a regular expression. For data object to be valid each regular expression in this array should match at least one property name in the data object.

If the array contains multiple regular expressions, more than one expression can match the same property name.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{ patternRequired: [ 'f.*o', 'b.*r' ] \};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{ foo: 1, bar: 2 \};}
\DoxyCodeLine{var alsoValidData = \{ foobar: 3 \};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidDataList = [ \{\}, \{ foo: 1 \}, \{ bar: 2 \} ]; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2712}{}\doxysubsubsection{$<$tt$>$prohibited$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2712}
This keyword allows to prohibit that any of the properties in the list is present in the object.

This keyword applies only to objects. If the data is not an object, the validation succeeds.

The value of this keyword should be an array of strings, each string being a property name. For data object to be valid none of the properties in this array should be present in the object.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{ prohibited: ['foo', 'bar']\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{ baz: 1 \};}
\DoxyCodeLine{var alsoValidData = \{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidDataList = [}
\DoxyCodeLine{  \{ foo: 1 \},}
\DoxyCodeLine{  \{ bar: 2 \},}
\DoxyCodeLine{  \{ foo: 1, bar: 2\}}
\DoxyCodeLine{]; }

\end{DoxyCode}


{\bfseries{Please note}}\+: `\{prohibited\+: \mbox{[}\textquotesingle{}foo', \textquotesingle{}bar\textquotesingle{}\mbox{]}\}{\ttfamily is equivalent to}\{not\+: \{any\+Required\+: \mbox{[}\textquotesingle{}foo\textquotesingle{}, \textquotesingle{}bar\textquotesingle{}\mbox{]}\}\}\`{} (i.\+e. it has the same validation result for any data).\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2713}{}\doxysubsubsection{$<$tt$>$deep\+Properties$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2713}
This keyword allows to validate deep properties (identified by JSON pointers).

This keyword applies only to objects. If the data is not an object, the validation succeeds.

The value should be an object, where keys are JSON pointers to the data, starting from the current position in data, and the values are JSON schemas. For data object to be valid the value of each JSON pointer should be valid according to the corresponding schema.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: 'object',}
\DoxyCodeLine{  deepProperties: \{}
\DoxyCodeLine{    "{}/users/1/role"{}: \{ "{}enum"{}: ["{}admin"{}] \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{}
\DoxyCodeLine{  users: [}
\DoxyCodeLine{    \{\},}
\DoxyCodeLine{    \{}
\DoxyCodeLine{      id: 123,}
\DoxyCodeLine{      role: 'admin'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var alsoValidData = \{}
\DoxyCodeLine{  users: \{}
\DoxyCodeLine{    "{}1"{}: \{}
\DoxyCodeLine{      id: 123,}
\DoxyCodeLine{      role: 'admin'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidData = \{}
\DoxyCodeLine{  users: [}
\DoxyCodeLine{    \{\},}
\DoxyCodeLine{    \{}
\DoxyCodeLine{      id: 123,}
\DoxyCodeLine{      role: 'user'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var alsoInvalidData = \{}
\DoxyCodeLine{  users: \{}
\DoxyCodeLine{    "{}1"{}: \{}
\DoxyCodeLine{      id: 123,}
\DoxyCodeLine{      role: 'user'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2714}{}\doxysubsubsection{$<$tt$>$deep\+Required$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2714}
This keyword allows to check that some deep properties (identified by JSON pointers) are available.

This keyword applies only to objects. If the data is not an object, the validation succeeds.

The value should be an array of JSON pointers to the data, starting from the current position in data. For data object to be valid each JSON pointer should be some existing part of the data.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: 'object',}
\DoxyCodeLine{  deepRequired: ["{}/users/1/role"{}]}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validData = \{}
\DoxyCodeLine{  users: [}
\DoxyCodeLine{    \{\},}
\DoxyCodeLine{    \{}
\DoxyCodeLine{      id: 123,}
\DoxyCodeLine{      role: 'admin'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidData = \{}
\DoxyCodeLine{  users: [}
\DoxyCodeLine{    \{\},}
\DoxyCodeLine{    \{}
\DoxyCodeLine{      id: 123}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\}; }

\end{DoxyCode}


See \href{https://github.com/json-schema-org/json-schema-spec/issues/203\#issue-197211916}{\texttt{ json-\/schema-\/org/json-\/schema-\/spec\#203}} for an example of the equivalent schema without {\ttfamily deep\+Required} keyword.\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2715}{}\doxysubsection{Compound keywords}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2715}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2716}{}\doxysubsubsection{$<$tt$>$switch$<$/tt$>$ (deprecated)}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2716}
{\bfseries{Please note}}\+: this keyword is provided to preserve backward compatibility with previous versions of Ajv. It is strongly recommended to use {\ttfamily if}/{\ttfamily then}/{\ttfamily else} keywords instead, as they have been added to the draft-\/07 of JSON Schema specification.

This keyword allows to perform advanced conditional validation.

The value of the keyword is the array of if/then clauses. Each clause is the object with the following properties\+:


\begin{DoxyItemize}
\item {\ttfamily if} (optional) -\/ the value is JSON-\/schema
\item {\ttfamily then} (required) -\/ the value is JSON-\/schema or boolean
\item {\ttfamily continue} (optional) -\/ the value is boolean
\end{DoxyItemize}

The validation process is dynamic; all clauses are executed sequentially in the following way\+:


\begin{DoxyEnumerate}
\item {\ttfamily if}\+:
\begin{DoxyEnumerate}
\item {\ttfamily if} property is JSON-\/schema according to which the data is\+:
\begin{DoxyEnumerate}
\item valid =$>$ go to step 2.
\item invalid =$>$ go to the NEXT clause, if this was the last clause the validation of {\ttfamily switch} SUCCEEDS.
\end{DoxyEnumerate}
\item {\ttfamily if} property is absent =$>$ go to step 2.
\end{DoxyEnumerate}
\item {\ttfamily then}\+:
\begin{DoxyEnumerate}
\item {\ttfamily then} property is {\ttfamily true} or it is JSON-\/schema according to which the data is valid =$>$ go to step 3.
\item {\ttfamily then} property is {\ttfamily false} or it is JSON-\/schema according to which the data is invalid =$>$ the validation of {\ttfamily switch} FAILS.
\end{DoxyEnumerate}
\item {\ttfamily continue}\+:
\begin{DoxyEnumerate}
\item {\ttfamily continue} property is {\ttfamily true} =$>$ go to the NEXT clause, if this was the last clause the validation of {\ttfamily switch} SUCCEEDS.
\item {\ttfamily continue} property is {\ttfamily false} or absent =$>$ validation of {\ttfamily switch} SUCCEEDS.
\end{DoxyEnumerate}
\end{DoxyEnumerate}


\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords')(ajv, 'switch');}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: 'array',}
\DoxyCodeLine{  items: \{}
\DoxyCodeLine{    type: 'integer',}
\DoxyCodeLine{    'switch': [}
\DoxyCodeLine{      \{ if: \{ not: \{ minimum: 1 \} \}, then: false \},}
\DoxyCodeLine{      \{ if: \{ maximum: 10 \}, then: true \},}
\DoxyCodeLine{      \{ if: \{ maximum: 100 \}, then: \{ multipleOf: 10 \} \},}
\DoxyCodeLine{      \{ if: \{ maximum: 1000 \}, then: \{ multipleOf: 100 \} \},}
\DoxyCodeLine{      \{ then: false \}}
\DoxyCodeLine{    ]}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validItems = [1, 5, 10, 20, 50, 100, 200, 500, 1000];}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidItems = [1, 0, 2000, 11, 57, 123, 'foo']; }

\end{DoxyCode}


The above schema is equivalent to (for example)\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  type: 'array',}
\DoxyCodeLine{  items: \{}
\DoxyCodeLine{    type: 'integer',}
\DoxyCodeLine{    if: \{ minimum: 1, maximum: 10 \},}
\DoxyCodeLine{    then: true,}
\DoxyCodeLine{    else: \{}
\DoxyCodeLine{      if: \{ maximum: 100 \},}
\DoxyCodeLine{      then: \{ multipleOf: 10 \},}
\DoxyCodeLine{      else: \{}
\DoxyCodeLine{        if: \{ maximum: 1000 \},}
\DoxyCodeLine{        then: \{ multipleOf: 100 \},}
\DoxyCodeLine{        else: false}
\DoxyCodeLine{      \}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2717}{}\doxysubsubsection{$<$tt$>$select$<$/tt$>$/$<$tt$>$select\+Cases$<$/tt$>$/$<$tt$>$select\+Default$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2717}
These keywords allow to choose the schema to validate the data based on the value of some property in the validated data.

These keywords must be present in the same schema object ({\ttfamily select\+Default} is optional).

The value of {\ttfamily select} keyword should be a \href{https://github.com/epoberezkin/ajv/tree/5.0.2-beta.0\#data-reference}{\texttt{ \$data reference}} that points to any primitive JSON type (string, number, boolean or null) in the data that is validated. You can also use a constant of primitive type as the value of this keyword (e.\+g., for debugging purposes).

The value of {\ttfamily select\+Cases} keyword must be an object where each property name is a possible string representation of the value of {\ttfamily select} keyword and each property value is a corresponding schema (from draft-\/06 it can be boolean) that must be used to validate the data.

The value of {\ttfamily select\+Default} keyword is a schema (from draft-\/06 it can be boolean) that must be used to validate the data in case {\ttfamily select\+Cases} has no key equal to the stringified value of {\ttfamily select} keyword.

The validation succeeds in one of the following cases\+:
\begin{DoxyItemize}
\item the validation of data using selected schema succeeds,
\item none of the schemas is selected for validation,
\item the value of select is undefined (no property in the data that the data reference points to).
\end{DoxyItemize}

If {\ttfamily select} value (in data) is not a primitive type the validation fails.

{\bfseries{Please note}}\+: these keywords require Ajv {\ttfamily \$data} option to support \href{https://github.com/epoberezkin/ajv/tree/5.0.2-beta.0\#data-reference}{\texttt{ \$data reference}}.


\begin{DoxyCode}{0}
\DoxyCodeLine{require('ajv-\/keywords')(ajv, 'select');}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: object,}
\DoxyCodeLine{  required: ['kind'],}
\DoxyCodeLine{  properties: \{}
\DoxyCodeLine{    kind: \{ type: 'string' \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  select: \{ \$data: '0/kind' \},}
\DoxyCodeLine{  selectCases: \{}
\DoxyCodeLine{    foo: \{}
\DoxyCodeLine{      required: ['foo'],}
\DoxyCodeLine{      properties: \{}
\DoxyCodeLine{        kind: \{\},}
\DoxyCodeLine{        foo: \{ type: 'string' \}}
\DoxyCodeLine{      \},}
\DoxyCodeLine{      additionalProperties: false}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    bar: \{}
\DoxyCodeLine{      required: ['bar'],}
\DoxyCodeLine{      properties: \{}
\DoxyCodeLine{        kind: \{\},}
\DoxyCodeLine{        bar: \{ type: 'number' \}}
\DoxyCodeLine{      \},}
\DoxyCodeLine{      additionalProperties: false}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  selectDefault: \{}
\DoxyCodeLine{    propertyNames: \{}
\DoxyCodeLine{      not: \{ enum: ['foo', 'bar'] \}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var validDataList = [}
\DoxyCodeLine{  \{ kind: 'foo', foo: 'any' \},}
\DoxyCodeLine{  \{ kind: 'bar', bar: 1 \},}
\DoxyCodeLine{  \{ kind: 'anything\_else', not\_bar\_or\_foo: 'any value' \}}
\DoxyCodeLine{];}
\DoxyCodeLine{}
\DoxyCodeLine{var invalidDataList = [}
\DoxyCodeLine{  \{ kind: 'foo' \}, // no propery foo}
\DoxyCodeLine{  \{ kind: 'bar' \}, // no propery bar}
\DoxyCodeLine{  \{ kind: 'foo', foo: 'any', another: 'any value' \}, // additional property}
\DoxyCodeLine{  \{ kind: 'bar', bar: 1, another: 'any value' \}, // additional property}
\DoxyCodeLine{  \{ kind: 'anything\_else', foo: 'any' \} // property foo not allowed}
\DoxyCodeLine{  \{ kind: 'anything\_else', bar: 1 \} // property bar not allowed}
\DoxyCodeLine{]; }

\end{DoxyCode}


{\bfseries{Please note}}\+: the current implementation is BETA. It does not allow using relative URIs in \$ref keywords in schemas in {\ttfamily select\+Cases} and {\ttfamily select\+Default} that point outside of these schemas. The workaround is to use absolute URIs (that can point to any (sub-\/)schema added to Ajv, including those inside the current root schema where {\ttfamily select} is used). See \href{https://github.com/epoberezkin/ajv-keywords/blob/v2.0.0/spec/tests/select.json\#L314}{\texttt{ tests}}.\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2718}{}\doxysubsection{Keywords for all types}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2718}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2719}{}\doxysubsubsection{$<$tt$>$dynamic\+Defaults$<$/tt$>$}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2719}
This keyword allows to assign dynamic defaults to properties, such as timestamps, unique IDs etc.

This keyword only works if {\ttfamily use\+Defaults} options is used and not inside {\ttfamily any\+Of} keywords etc., in the same way as \href{https://github.com/epoberezkin/ajv\#assigning-defaults}{\texttt{ default keyword treated by Ajv}}.

The keyword should be added on the object level. Its value should be an object with each property corresponding to a property name, in the same way as in standard {\ttfamily properties} keyword. The value of each property can be\+:


\begin{DoxyItemize}
\item an identifier of default function (a string)
\item an object with properties {\ttfamily func} (an identifier) and {\ttfamily args} (an object with parameters that will be passed to this function during schema compilation -\/ see examples).
\end{DoxyItemize}

The properties used in {\ttfamily dynamic\+Defaults} should not be added to {\ttfamily required} keyword (or validation will fail), because unlike {\ttfamily default} this keyword is processed after validation.

There are several predefined dynamic default functions\+:


\begin{DoxyItemize}
\item {\ttfamily \char`\"{}timestamp\char`\"{}} -\/ current timestamp in milliseconds
\item {\ttfamily \char`\"{}datetime\char`\"{}} -\/ current date and time as string (ISO, valid according to {\ttfamily date-\/time} format)
\item {\ttfamily \char`\"{}date\char`\"{}} -\/ current date as string (ISO, valid according to {\ttfamily date} format)
\item {\ttfamily \char`\"{}time\char`\"{}} -\/ current time as string (ISO, valid according to {\ttfamily time} format)
\item {\ttfamily \char`\"{}random\char`\"{}} -\/ pseudo-\/random number in \mbox{[}0, 1) interval
\item {\ttfamily \char`\"{}randomint\char`\"{}} -\/ pseudo-\/random integer number. If string is used as a property value, the function will randomly return 0 or 1. If object `\{ func\+: \textquotesingle{}randomint', args\+: \{ max\+: N \} \}{\ttfamily is used then the default will be an integer number in \mbox{[}0, N) interval. -\/}\char`\"{}seq\char`\"{}{\ttfamily -\/ sequential integer number starting from 0. If string is used as a property value, the default sequence will be used. If object}\{ func\+: \textquotesingle{}seq\textquotesingle{}, args\+: \{ name\+: \textquotesingle{}foo\textquotesingle{}\} \}{\ttfamily is used then the sequence with name}\char`\"{}foo\char`\"{}\`{} will be used. Sequences are global, even if different ajv instances are used.
\end{DoxyItemize}


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  type: 'object',}
\DoxyCodeLine{  dynamicDefaults: \{}
\DoxyCodeLine{    ts: 'datetime',}
\DoxyCodeLine{    r: \{ func: 'randomint', args: \{ max: 100 \} \},}
\DoxyCodeLine{    id: \{ func: 'seq', args: \{ name: 'id' \} \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  properties: \{}
\DoxyCodeLine{    ts: \{}
\DoxyCodeLine{      type: 'string',}
\DoxyCodeLine{      format: 'date-\/time'}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    r: \{}
\DoxyCodeLine{      type: 'integer',}
\DoxyCodeLine{      minimum: 0,}
\DoxyCodeLine{      exclusiveMaximum: 100}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    id: \{}
\DoxyCodeLine{      type: 'integer',}
\DoxyCodeLine{      minimum: 0}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var data = \{\};}
\DoxyCodeLine{ajv.validate(data); // true}
\DoxyCodeLine{data; // \{ ts: '2016-\/12-\/01T22:07:28.829Z', r: 25, id: 0 \}}
\DoxyCodeLine{}
\DoxyCodeLine{var data1 = \{\};}
\DoxyCodeLine{ajv.validate(data1); // true}
\DoxyCodeLine{data1; // \{ ts: '2016-\/12-\/01T22:07:29.832Z', r: 68, id: 1 \}}
\DoxyCodeLine{}
\DoxyCodeLine{ajv.validate(data1); // true}
\DoxyCodeLine{data1; // didn't change, as all properties were defined }

\end{DoxyCode}


When using the {\ttfamily use\+Defaults} option value {\ttfamily \char`\"{}empty\char`\"{}}, properties and items equal to {\ttfamily null} or {\ttfamily \char`\"{}\char`\"{}} (empty string) will be considered missing and assigned defaults. Use the {\ttfamily all\+Of} \href{https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md\#compound-keywords}{\texttt{ compound keyword}} to execute {\ttfamily dynamic\+Defaults} before validation.


\begin{DoxyCode}{0}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  allOf: [}
\DoxyCodeLine{    \{}
\DoxyCodeLine{      dynamicDefaults: \{}
\DoxyCodeLine{        ts: 'datetime',}
\DoxyCodeLine{        r: \{ func: 'randomint', args: \{ min: 5, max: 100 \} \},}
\DoxyCodeLine{        id: \{ func: 'seq', args: \{ name: 'id' \} \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    \{}
\DoxyCodeLine{      type: 'object',}
\DoxyCodeLine{      properties: \{}
\DoxyCodeLine{        ts: \{}
\DoxyCodeLine{          type: 'string'}
\DoxyCodeLine{        \},}
\DoxyCodeLine{        r: \{}
\DoxyCodeLine{          type: 'number',}
\DoxyCodeLine{          minimum: 5,}
\DoxyCodeLine{          exclusiveMaximum: 100}
\DoxyCodeLine{        \},}
\DoxyCodeLine{        id: \{}
\DoxyCodeLine{          type: 'integer',}
\DoxyCodeLine{          minimum: 0}
\DoxyCodeLine{        \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var data = \{ ts: '', r: null \};}
\DoxyCodeLine{ajv.validate(data); // true}
\DoxyCodeLine{data; // \{ ts: '2016-\/12-\/01T22:07:28.829Z', r: 25, id: 0 \} }

\end{DoxyCode}


You can add your own dynamic default function to be recognised by this keyword\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var uuid = require('uuid');}
\DoxyCodeLine{}
\DoxyCodeLine{function uuidV4() \{ return uuid.v4(); \}}
\DoxyCodeLine{}
\DoxyCodeLine{var definition = require('ajv-\/keywords').get('dynamicDefaults').definition;}
\DoxyCodeLine{// or require('ajv-\/keywords/keywords/dynamicDefaults').definition;}
\DoxyCodeLine{definition.DEFAULTS.uuid = uuidV4;}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  dynamicDefaults: \{ id: 'uuid' \},}
\DoxyCodeLine{  properties: \{ id: \{ type: 'string', format: 'uuid' \} \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{var data = \{\};}
\DoxyCodeLine{ajv.validate(schema, data); // true}
\DoxyCodeLine{data; // \{ id: 'a1183fbe-\/697b-\/4030-\/9bcc-\/cfeb282a9150' \};}
\DoxyCodeLine{}
\DoxyCodeLine{var data1 = \{\};}
\DoxyCodeLine{ajv.validate(schema, data1); // true}
\DoxyCodeLine{data1; // \{ id: '5b008de7-\/1669-\/467a-\/a5c6-\/70fa244d7209' \} }

\end{DoxyCode}


You also can define dynamic default that accepts parameters, e.\+g. version of uuid\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var uuid = require('uuid');}
\DoxyCodeLine{}
\DoxyCodeLine{function getUuid(args) \{}
\DoxyCodeLine{  var version = 'v' + (arvs \&\& args.v || 4);}
\DoxyCodeLine{  return function() \{}
\DoxyCodeLine{    return uuid[version]();}
\DoxyCodeLine{  \};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{var definition = require('ajv-\/keywords').get('dynamicDefaults').definition;}
\DoxyCodeLine{definition.DEFAULTS.uuid = getUuid;}
\DoxyCodeLine{}
\DoxyCodeLine{var schema = \{}
\DoxyCodeLine{  dynamicDefaults: \{}
\DoxyCodeLine{    id1: 'uuid', // v4}
\DoxyCodeLine{    id2: \{ func: 'uuid', v: 4 \}, // v4}
\DoxyCodeLine{    id3: \{ func: 'uuid', v: 1 \} // v1}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2720}{}\doxysection{Security contact}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2720}
To report a security vulnerability, please use the \href{https://tidelift.com/security}{\texttt{ Tidelift security contact}}. Tidelift will coordinate the fix and disclosure.

Please do NOT report security vulnerabilities via Git\+Hub issues.\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2721}{}\doxysection{Open-\/source software support}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2721}
Ajv-\/keywords is a part of \href{https://tidelift.com/subscription/pkg/npm-ajv-keywords?utm_source=npm-ajv-keywords&utm_medium=referral&utm_campaign=readme}{\texttt{ Tidelift subscription}} -\/ it provides a centralised support to open-\/source software users, in addition to the support provided by software maintainers.\hypertarget{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2722}{}\doxysection{License}\label{md_sfcode_node_modules_ajv_keywords_README_autotoc_md2722}
\href{https://github.com/epoberezkin/ajv-keywords/blob/master/LICENSE}{\texttt{ MIT}} 