ajv/lib/dot/ref.jst

87 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 }}
2015-06-18 16:59:11 +03:00
{{ var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId; }}
{{? it.opts.missingRefs == 'fail' }}
{{ console.log($message); }}
{{# def.error:'$ref' }}
{{? $breakOnError }} if (false) { {{?}}
{{?? it.opts.missingRefs == 'ignore' }}
{{ console.log($message); }}
{{? $breakOnError }} if (true) { {{?}}
{{??}}
{{
var $error = new Error($message);
$error.missingRef = it.resolve.url(it.baseId, $schema);
$error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef));
throw $error;
}}
{{?}}
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}}
if (valid{{=$it.level}}) {
{{?}}
2016-01-28 02:43:28 +03:00
{{??}}
{{
$async = $refVal.$async === true;
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'); }}
try { {{? $breakOnError }}var {{=$valid}} ={{?}} {{=it.yieldAwait}} {{=__callValidate}}; }
2016-01-28 02:43:28 +03:00
catch (e) {
if (!(e instanceof ValidationError)) throw e;
if (vErrors === null) vErrors = e.errors;
else vErrors = vErrors.concat(e.errors);
errors = vErrors.length;
}
{{? $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
{{?}}