3 {{# def.setupKeyword }}
8 , $definition = 'definition' + $lvl
9 , $rDef = $rule.definition
10 , $validate = $rDef.validate
18 {{? $isData && $rDef.$data }}
20 $validateCode = 'keywordValidate' + $lvl;
21 var $validateSchema = $rDef.validateSchema;
23 var {{=$definition}} = RULES.custom['{{=$keyword}}'].definition;
24 var {{=$validateCode}} = {{=$definition}}.validate;
27 $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
28 $schemaValue = 'validate.schema' + $schemaPath;
29 $validateCode = $ruleValidate.code;
30 $compile = $rDef.compile;
31 $inline = $rDef.inline;
37 var $ruleErrs = $validateCode + '.errors'
39 , $ruleErr = 'ruleErr' + $lvl
40 , $asyncKeyword = $rDef.async;
42 if ($asyncKeyword && !it.async)
43 throw new Error('async keyword in sync schema');
47 {{? !($inline || $macro) }}{{=$ruleErrs}} = null;{{?}}
48 var {{=$errs}} = errors;
51 {{## def.callRuleValidate:
52 {{=$validateCode}}.call(
53 {{? it.opts.passContext }}this{{??}}self{{?}}
54 {{? $compile || $rDef.schema === false }}
59 , validate.schema{{=it.schemaPath}}
62 {{# def.passParentData }}
67 {{## def.extendErrors:_inline:
68 for (var {{=$i}}={{=$errs}}; {{=$i}}<errors; {{=$i}}++) {
69 var {{=$ruleErr}} = vErrors[{{=$i}}];
70 if ({{=$ruleErr}}.dataPath === undefined)
71 {{=$ruleErr}}.dataPath = (dataPath || '') + {{= it.errorPath }};
72 {{# _inline ? 'if (\{\{=$ruleErr\}\}.schemaPath === undefined) {' : '' }}
73 {{=$ruleErr}}.schemaPath = "{{=$errSchemaPath}}";
74 {{# _inline ? '}' : '' }}
75 {{? it.opts.verbose }}
76 {{=$ruleErr}}.schema = {{=$schemaValue}};
77 {{=$ruleErr}}.data = {{=$data}};
83 {{? $validateSchema }}
84 {{=$valid}} = {{=$definition}}.validateSchema({{=$schemaValue}});
89 {{? $rDef.statements }}
90 {{= $ruleValidate.validate }}
92 {{=$valid}} = {{= $ruleValidate.validate }};
95 {{# def.setupNextLevel }}
97 $it.schema = $ruleValidate.validate;
100 {{# def.setCompositeRule }}
101 {{ var $code = it.validate($it).replace(/validate\.schema/g, $validateCode); }}
102 {{# def.resetCompositeRule }}
105 {{# def.beginDefOut}}
106 {{# def.callRuleValidate }}
107 {{# def.storeDefOut:def_callRuleValidate }}
109 {{? $rDef.errors === false }}
110 {{=$valid}} = {{? $asyncKeyword }}{{=it.yieldAwait}}{{?}}{{= def_callRuleValidate }};
113 {{ $ruleErrs = 'customErrors' + $lvl; }}
114 var {{=$ruleErrs}} = null;
116 {{=$valid}} = {{=it.yieldAwait}}{{= def_callRuleValidate }};
119 if (e instanceof ValidationError) {{=$ruleErrs}} = e.errors;
123 {{=$ruleErrs}} = null;
124 {{=$valid}} = {{= def_callRuleValidate }};
129 {{? $rDef.modifying }}
130 {{=$data}} = {{=$parentData}}[{{=$parentDataProperty}}];
133 {{? $validateSchema }}
137 {{## def.notValidationResult:
138 {{? $rDef.valid === undefined }}
139 !{{? $macro }}{{=$nextValid}}{{??}}{{=$valid}}{{?}}
146 {{? $breakOnError }} if (true) { {{?}}
148 if ({{# def.notValidationResult }}) {
149 {{ $errorKeyword = $rule.keyword; }}
150 {{# def.beginDefOut}}
151 {{# def.error:'custom' }}
152 {{# def.storeDefOut:def_customError }}
156 {{? $rDef.errors != 'full' }}
157 {{# def.extendErrors:true }}
160 {{? $rDef.errors === false}}
161 {{= def_customError }}
163 if ({{=$errs}} == errors) {
164 {{= def_customError }}
166 {{# def.extendErrors:true }}
171 {{# def.extraError:'custom' }}
173 {{? $rDef.errors === false}}
174 {{= def_customError }}
176 if (Array.isArray({{=$ruleErrs}})) {
177 if (vErrors === null) vErrors = {{=$ruleErrs}};
178 else vErrors = vErrors.concat({{=$ruleErrs}});
179 errors = vErrors.length;
180 {{# def.extendErrors:false }}
182 {{= def_customError }}
187 } {{? $breakOnError }} else { {{?}}