2015-06-03 03:36:59 +03:00
|
|
|
{{# def.definitions }}
|
2015-12-12 16:41:51 +03:00
|
|
|
{{# def.errors }}
|
2015-12-22 20:03:09 +03:00
|
|
|
{{# def.setupKeyword }}
|
2015-06-03 03:36:59 +03:00
|
|
|
|
2016-01-17 16:50:54 +03:00
|
|
|
{{## def._validateRef:_v:
|
2016-02-14 23:34:10 +03:00
|
|
|
{{? it.opts.passContext }}
|
|
|
|
{{=_v}}.call(this,
|
|
|
|
{{??}}
|
|
|
|
{{=_v}}(
|
|
|
|
{{?}}
|
2016-08-29 23:51:49 +03:00
|
|
|
{{=$data}}, {{# def.dataPath }}{{# def.passParentData }}, rootData)
|
2016-01-17 16:50:54 +03:00
|
|
|
#}}
|
2015-06-17 00:04:17 +03:00
|
|
|
|
2016-01-28 02:43:28 +03:00
|
|
|
{{ var $async, $refCode; }}
|
2015-06-06 21:44:07 +03:00
|
|
|
{{? $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
|
|
|
{{??}}
|
2015-08-08 14:21:41 +03:00
|
|
|
{{ var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); }}
|
2015-06-16 17:10:21 +03:00
|
|
|
{{? $refVal === undefined }}
|
2015-06-18 16:59:11 +03:00
|
|
|
{{ var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId; }}
|
2015-06-18 00:23:49 +03:00
|
|
|
{{? it.opts.missingRefs == 'fail' }}
|
2016-10-05 22:50:37 +03:00
|
|
|
{{ console.error($message); }}
|
2015-06-18 00:23:49 +03:00
|
|
|
{{# def.error:'$ref' }}
|
|
|
|
{{? $breakOnError }} if (false) { {{?}}
|
|
|
|
{{?? it.opts.missingRefs == 'ignore' }}
|
2016-10-05 22:50:37 +03:00
|
|
|
{{ console.warn($message); }}
|
2015-06-18 00:23:49 +03:00
|
|
|
{{? $breakOnError }} if (true) { {{?}}
|
|
|
|
{{??}}
|
2015-09-02 20:20:43 +03:00
|
|
|
{{
|
|
|
|
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;
|
|
|
|
}}
|
2015-06-18 00:23:49 +03:00
|
|
|
{{?}}
|
2016-01-28 02:43:28 +03:00
|
|
|
{{?? $refVal.inline }}
|
2015-08-20 00:54:05 +03:00
|
|
|
{{# def.setupNextLevel }}
|
|
|
|
{{
|
2015-08-22 00:52:29 +03:00
|
|
|
$it.schema = $refVal.schema;
|
2015-08-20 00:54:05 +03:00
|
|
|
$it.schemaPath = '';
|
2015-12-19 18:56:08 +03:00
|
|
|
$it.errSchemaPath = $schema;
|
2015-08-20 00:54:05 +03:00
|
|
|
}}
|
2015-11-27 01:49:49 +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
|
|
|
{{??}}
|
|
|
|
{{
|
2016-04-10 22:17:06 +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'); }}
|
2016-01-28 15:31:20 +03:00
|
|
|
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
|
|
|
{{?}}
|