ajv/lib/dot/ref.jst

86 lines
2.4 KiB
Plaintext
Raw Normal View History

{{# def.definitions }}
2015-12-12 16:41:51 +03:00
{{# def.errors }}
2015-12-22 20:03:09 +03:00
{{# def.setupKeyword }}
{{## def._validateRef:_v:
{{? it.opts.passContext }}
{{=_v}}.call(this,
{{??}}
{{=_v}}(
{{?}}
{{=$data}}, {{# def.dataPath }}{{# def.passParentData }}, rootData)
#}}
2015-06-17 00:04:17 +03:00
2016-01-28 02:43:28 +03:00
{{ var $async, $refCode; }}
{{? $schema == '#' || $schema == '#/' }}
2016-01-28 02:43:28 +03:00
{{
if (it.isRoot) {
$async = it.async;
$refCode = 'validate';
} else {
$async = it.root.schema.$async === true;
$refCode = 'root.refVal[0]';
}
}}
2015-05-31 20:39:12 +03:00
{{??}}
{{ var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); }}
{{? $refVal === undefined }}
{{ var $message = it.MissingRefError.message(it.baseId, $schema); }}
{{? it.opts.missingRefs == 'fail' }}
2017-11-19 12:18:40 +03:00
{{ it.logger.error($message); }}
{{# def.error:'$ref' }}
{{? $breakOnError }} if (false) { {{?}}
{{?? it.opts.missingRefs == 'ignore' }}
2017-11-19 12:18:40 +03:00
{{ it.logger.warn($message); }}
{{? $breakOnError }} if (true) { {{?}}
{{??}}
{{ throw new it.MissingRefError(it.baseId, $schema, $message); }}
{{?}}
2016-01-28 02:43:28 +03:00
{{?? $refVal.inline }}
2015-08-20 00:54:05 +03:00
{{# def.setupNextLevel }}
{{
$it.schema = $refVal.schema;
2015-08-20 00:54:05 +03:00
$it.schemaPath = '';
$it.errSchemaPath = $schema;
2015-08-20 00:54:05 +03:00
}}
{{ var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code); }}
{{= $code }}
2015-08-20 00:54:05 +03:00
{{? $breakOnError}}
2016-12-24 01:02:41 +03:00
if ({{=$nextValid}}) {
2015-08-20 00:54:05 +03:00
{{?}}
2016-01-28 02:43:28 +03:00
{{??}}
{{
$async = $refVal.$async === true || (it.async && $refVal.$async !== false);
2016-01-28 02:43:28 +03:00
$refCode = $refVal.code;
}}
{{?}}
{{?}}
{{? $refCode }}
{{# def.beginDefOut}}
{{# def._validateRef:$refCode }}
{{# def.storeDefOut:__callValidate }}
{{? $async }}
{{ if (!it.async) throw new Error('async schema referenced by sync schema'); }}
{{? $breakOnError }} var {{=$valid}}; {{?}}
try {
await {{=__callValidate}};
{{? $breakOnError }} {{=$valid}} = true; {{?}}
} catch (e) {
2016-01-28 02:43:28 +03:00
if (!(e instanceof ValidationError)) throw e;
if (vErrors === null) vErrors = e.errors;
else vErrors = vErrors.concat(e.errors);
errors = vErrors.length;
{{? $breakOnError }} {{=$valid}} = false; {{?}}
2016-01-28 02:43:28 +03:00
}
{{? $breakOnError }} if ({{=$valid}}) { {{?}}
{{??}}
if (!{{=__callValidate}}) {
if (vErrors === null) vErrors = {{=$refCode}}.errors;
else vErrors = vErrors.concat({{=$refCode}}.errors);
errors = vErrors.length;
} {{? $breakOnError }} else { {{?}}
2015-06-06 18:18:52 +03:00
{{?}}
2015-05-31 20:39:12 +03:00
{{?}}