3 {{# def.setupKeyword }}
8 , $definition = 'definition' + $lvl
9 , $rDef = $rule.definition
10 , $closingBraces = '';
11 var $validate = $rDef.validate;
12 var $compile, $inline, $macro, $ruleValidate, $validateCode;
15 {{? $isData && $rDef.$data }}
17 $validateCode = 'keywordValidate' + $lvl;
18 var $validateSchema = $rDef.validateSchema;
20 var {{=$definition}} = RULES.custom['{{=$keyword}}'].definition;
21 var {{=$validateCode}} = {{=$definition}}.validate;
24 $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
25 if (!$ruleValidate) return;
26 $schemaValue = 'validate.schema' + $schemaPath;
27 $validateCode = $ruleValidate.code;
28 $compile = $rDef.compile;
29 $inline = $rDef.inline;
35 var $ruleErrs = $validateCode + '.errors'
37 , $ruleErr = 'ruleErr' + $lvl
38 , $asyncKeyword = $rDef.async;
40 if ($asyncKeyword && !it.async)
41 throw new Error('async keyword in sync schema');
45 {{? !($inline || $macro) }}{{=$ruleErrs}} = null;{{?}}
46 var {{=$errs}} = errors;
49 {{## def.callRuleValidate:
50 {{=$validateCode}}.call(
51 {{? it.opts.passContext }}this{{??}}self{{?}}
52 {{? $compile || $rDef.schema === false }}
57 , validate.schema{{=it.schemaPath}}
60 {{# def.passParentData }}
65 {{## def.extendErrors:_inline:
66 for (var {{=$i}}={{=$errs}}; {{=$i}}<errors; {{=$i}}++) {
67 var {{=$ruleErr}} = vErrors[{{=$i}}];
68 if ({{=$ruleErr}}.dataPath === undefined)
69 {{=$ruleErr}}.dataPath = (dataPath || '') + {{= it.errorPath }};
70 {{# _inline ? 'if (\{\{=$ruleErr\}\}.schemaPath === undefined) {' : '' }}
71 {{=$ruleErr}}.schemaPath = "{{=$errSchemaPath}}";
72 {{# _inline ? '}' : '' }}
73 {{? it.opts.verbose }}
74 {{=$ruleErr}}.schema = {{=$schemaValue}};
75 {{=$ruleErr}}.data = {{=$data}};
81 {{? $isData && $rDef.$data }}
82 {{ $closingBraces += '}'; }}
83 if ({{=$schemaValue}} === undefined) {
86 {{? $validateSchema }}
87 {{ $closingBraces += '}'; }}
88 {{=$valid}} = {{=$definition}}.validateSchema({{=$schemaValue}});
94 {{? $rDef.statements }}
95 {{= $ruleValidate.validate }}
97 {{=$valid}} = {{= $ruleValidate.validate }};
100 {{# def.setupNextLevel }}
102 $it.schema = $ruleValidate.validate;
105 {{# def.setCompositeRule }}
106 {{ var $code = it.validate($it).replace(/validate\.schema/g, $validateCode); }}
107 {{# def.resetCompositeRule }}
110 {{# def.beginDefOut}}
111 {{# def.callRuleValidate }}
112 {{# def.storeDefOut:def_callRuleValidate }}
114 {{? $rDef.errors === false }}
115 {{=$valid}} = {{? $asyncKeyword }}await {{?}}{{= def_callRuleValidate }};
118 {{ $ruleErrs = 'customErrors' + $lvl; }}
119 var {{=$ruleErrs}} = null;
121 {{=$valid}} = await {{= def_callRuleValidate }};
124 if (e instanceof ValidationError) {{=$ruleErrs}} = e.errors;
128 {{=$ruleErrs}} = null;
129 {{=$valid}} = {{= def_callRuleValidate }};
134 {{? $rDef.modifying }}
135 if ({{=$parentData}}) {{=$data}} = {{=$parentData}}[{{=$parentDataProperty}}];
138 {{= $closingBraces }}
140 {{## def.notValidationResult:
141 {{? $rDef.valid === undefined }}
142 !{{? $macro }}{{=$nextValid}}{{??}}{{=$valid}}{{?}}
149 {{? $breakOnError }} if (true) { {{?}}
151 if ({{# def.notValidationResult }}) {
152 {{ $errorKeyword = $rule.keyword; }}
153 {{# def.beginDefOut}}
154 {{# def.error:'custom' }}
155 {{# def.storeDefOut:def_customError }}
159 {{? $rDef.errors != 'full' }}
160 {{# def.extendErrors:true }}
163 {{? $rDef.errors === false}}
164 {{= def_customError }}
166 if ({{=$errs}} == errors) {
167 {{= def_customError }}
169 {{# def.extendErrors:true }}
174 {{# def.extraError:'custom' }}
176 {{? $rDef.errors === false}}
177 {{= def_customError }}
179 if (Array.isArray({{=$ruleErrs}})) {
180 if (vErrors === null) vErrors = {{=$ruleErrs}};
181 else vErrors = vErrors.concat({{=$ruleErrs}});
182 errors = vErrors.length;
183 {{# def.extendErrors:false }}
185 {{= def_customError }}
190 } {{? $breakOnError }} else { {{?}}