[d565449] | 1 | {{# def.definitions }}
|
---|
| 2 | {{# def.errors }}
|
---|
| 3 | {{# def.setupKeyword }}
|
---|
| 4 |
|
---|
| 5 | {{## def._validateRef:_v:
|
---|
| 6 | {{? it.opts.passContext }}
|
---|
| 7 | {{=_v}}.call(this,
|
---|
| 8 | {{??}}
|
---|
| 9 | {{=_v}}(
|
---|
| 10 | {{?}}
|
---|
| 11 | {{=$data}}, {{# def.dataPath }}{{# def.passParentData }}, rootData)
|
---|
| 12 | #}}
|
---|
| 13 |
|
---|
| 14 | {{ var $async, $refCode; }}
|
---|
| 15 | {{? $schema == '#' || $schema == '#/' }}
|
---|
| 16 | {{
|
---|
| 17 | if (it.isRoot) {
|
---|
| 18 | $async = it.async;
|
---|
| 19 | $refCode = 'validate';
|
---|
| 20 | } else {
|
---|
| 21 | $async = it.root.schema.$async === true;
|
---|
| 22 | $refCode = 'root.refVal[0]';
|
---|
| 23 | }
|
---|
| 24 | }}
|
---|
| 25 | {{??}}
|
---|
| 26 | {{ var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); }}
|
---|
| 27 | {{? $refVal === undefined }}
|
---|
| 28 | {{ var $message = it.MissingRefError.message(it.baseId, $schema); }}
|
---|
| 29 | {{? it.opts.missingRefs == 'fail' }}
|
---|
| 30 | {{ it.logger.error($message); }}
|
---|
| 31 | {{# def.error:'$ref' }}
|
---|
| 32 | {{? $breakOnError }} if (false) { {{?}}
|
---|
| 33 | {{?? it.opts.missingRefs == 'ignore' }}
|
---|
| 34 | {{ it.logger.warn($message); }}
|
---|
| 35 | {{? $breakOnError }} if (true) { {{?}}
|
---|
| 36 | {{??}}
|
---|
| 37 | {{ throw new it.MissingRefError(it.baseId, $schema, $message); }}
|
---|
| 38 | {{?}}
|
---|
| 39 | {{?? $refVal.inline }}
|
---|
| 40 | {{# def.setupNextLevel }}
|
---|
| 41 | {{
|
---|
| 42 | $it.schema = $refVal.schema;
|
---|
| 43 | $it.schemaPath = '';
|
---|
| 44 | $it.errSchemaPath = $schema;
|
---|
| 45 | }}
|
---|
| 46 | {{ var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code); }}
|
---|
| 47 | {{= $code }}
|
---|
| 48 | {{? $breakOnError}}
|
---|
| 49 | if ({{=$nextValid}}) {
|
---|
| 50 | {{?}}
|
---|
| 51 | {{??}}
|
---|
| 52 | {{
|
---|
| 53 | $async = $refVal.$async === true || (it.async && $refVal.$async !== false);
|
---|
| 54 | $refCode = $refVal.code;
|
---|
| 55 | }}
|
---|
| 56 | {{?}}
|
---|
| 57 | {{?}}
|
---|
| 58 |
|
---|
| 59 | {{? $refCode }}
|
---|
| 60 | {{# def.beginDefOut}}
|
---|
| 61 | {{# def._validateRef:$refCode }}
|
---|
| 62 | {{# def.storeDefOut:__callValidate }}
|
---|
| 63 |
|
---|
| 64 | {{? $async }}
|
---|
| 65 | {{ if (!it.async) throw new Error('async schema referenced by sync schema'); }}
|
---|
| 66 | {{? $breakOnError }} var {{=$valid}}; {{?}}
|
---|
| 67 | try {
|
---|
| 68 | await {{=__callValidate}};
|
---|
| 69 | {{? $breakOnError }} {{=$valid}} = true; {{?}}
|
---|
| 70 | } catch (e) {
|
---|
| 71 | if (!(e instanceof ValidationError)) throw e;
|
---|
| 72 | if (vErrors === null) vErrors = e.errors;
|
---|
| 73 | else vErrors = vErrors.concat(e.errors);
|
---|
| 74 | errors = vErrors.length;
|
---|
| 75 | {{? $breakOnError }} {{=$valid}} = false; {{?}}
|
---|
| 76 | }
|
---|
| 77 | {{? $breakOnError }} if ({{=$valid}}) { {{?}}
|
---|
| 78 | {{??}}
|
---|
| 79 | if (!{{=__callValidate}}) {
|
---|
| 80 | if (vErrors === null) vErrors = {{=$refCode}}.errors;
|
---|
| 81 | else vErrors = vErrors.concat({{=$refCode}}.errors);
|
---|
| 82 | errors = vErrors.length;
|
---|
| 83 | } {{? $breakOnError }} else { {{?}}
|
---|
| 84 | {{?}}
|
---|
| 85 | {{?}}
|
---|