Traverse JSON Schema passing each schema object to callback

\href{https://travis-ci.org/epoberezkin/json-schema-traverse}{\texttt{ }} \href{https://www.npmjs.com/package/json-schema-traverse}{\texttt{ }} \href{https://coveralls.io/github/epoberezkin/json-schema-traverse?branch=master}{\texttt{ }}\hypertarget{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14303}{}\doxysection{Install}\label{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14303}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install json-\/schema-\/traverse }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14304}{}\doxysection{Usage}\label{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14304}

\begin{DoxyCode}{0}
\DoxyCodeLine{const traverse = require('json-\/schema-\/traverse');}
\DoxyCodeLine{const schema = \{}
\DoxyCodeLine{  properties: \{}
\DoxyCodeLine{    foo: \{type: 'string'\},}
\DoxyCodeLine{    bar: \{type: 'integer'\}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{traverse(schema, \{cb\});}
\DoxyCodeLine{// cb is called 3 times with:}
\DoxyCodeLine{// 1. root schema}
\DoxyCodeLine{// 2. \{type: 'string'\}}
\DoxyCodeLine{// 3. \{type: 'integer'\}}
\DoxyCodeLine{}
\DoxyCodeLine{// Or:}
\DoxyCodeLine{}
\DoxyCodeLine{traverse(schema, \{cb: \{pre, post\}\});}
\DoxyCodeLine{// pre is called 3 times with:}
\DoxyCodeLine{// 1. root schema}
\DoxyCodeLine{// 2. \{type: 'string'\}}
\DoxyCodeLine{// 3. \{type: 'integer'\}}
\DoxyCodeLine{//}
\DoxyCodeLine{// post is called 3 times with:}
\DoxyCodeLine{// 1. \{type: 'string'\}}
\DoxyCodeLine{// 2. \{type: 'integer'\}}
\DoxyCodeLine{// 3. root schema}

\end{DoxyCode}


Callback function {\ttfamily cb} is called for each schema object (not including draft-\/06 boolean schemas), including the root schema, in pre-\/order traversal. Schema references (\$ref) are not resolved, they are passed as is. Alternatively, you can pass a {\ttfamily \{pre, post\}} object as {\ttfamily cb}, and then {\ttfamily pre} will be called before traversing child elements, and {\ttfamily post} will be called after all child elements have been traversed.

Callback is passed these parameters\+:


\begin{DoxyItemize}
\item {\itshape schema}\+: the current schema object
\item {\itshape JSON pointer}\+: from the root schema to the current schema object
\item {\itshape root schema}\+: the schema passed to {\ttfamily traverse} object
\item {\itshape parent JSON pointer}\+: from the root schema to the parent schema object (see below)
\item {\itshape parent keyword}\+: the keyword inside which this schema appears (e.\+g. {\ttfamily properties}, {\ttfamily any\+Of}, etc.)
\item {\itshape parent schema}\+: not necessarily parent object/array; in the example above the parent schema for `\{type\+: \textquotesingle{}string'\}{\ttfamily is the root schema}
\item {\ttfamily \+\_\+index/property\+\_\+\+: index or property name in the array/object containing multiple schemas; in the example above for}\{type\+: \textquotesingle{}string\textquotesingle{}\}{\ttfamily the property name is}\textquotesingle{}foo\textquotesingle{}\`{}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14305}{}\doxysection{Traverse objects in all unknown keywords}\label{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14305}

\begin{DoxyCode}{0}
\DoxyCodeLine{const traverse = require('json-\/schema-\/traverse');}
\DoxyCodeLine{const schema = \{}
\DoxyCodeLine{  mySchema: \{}
\DoxyCodeLine{    minimum: 1,}
\DoxyCodeLine{    maximum: 2}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{traverse(schema, \{allKeys: true, cb\});}
\DoxyCodeLine{// cb is called 2 times with:}
\DoxyCodeLine{// 1. root schema}
\DoxyCodeLine{// 2. mySchema }

\end{DoxyCode}


Without option {\ttfamily all\+Keys\+: true} callback will be called only with root schema.\hypertarget{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14306}{}\doxysection{License}\label{md_sfcode_node_modules_json_schema_traverse_README_autotoc_md14306}
\href{https://github.com/epoberezkin/json-schema-traverse/blob/master/LICENSE}{\texttt{ MIT}} 