Initial commit
[yaffs-website] / node_modules / ajv / lib / dot / ref.jst
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 = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId; }}
29     {{? it.opts.missingRefs == 'fail' }}
30       {{ console.log($message); }}
31       {{# def.error:'$ref' }}
32       {{? $breakOnError }} if (false) { {{?}}
33     {{?? it.opts.missingRefs == 'ignore' }}
34       {{ console.log($message); }}
35       {{? $breakOnError }} if (true) { {{?}}
36     {{??}}
37       {{
38         var $error = new Error($message);
39         $error.missingRef = it.resolve.url(it.baseId, $schema);
40         $error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef));
41         throw $error;
42       }}
43     {{?}}
44   {{?? $refVal.inline }}
45     {{# def.setupNextLevel }}
46     {{
47       $it.schema = $refVal.schema;
48       $it.schemaPath = '';
49       $it.errSchemaPath = $schema;
50     }}
51     {{ var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code); }}
52     {{= $code }}
53     {{? $breakOnError}}
54       if ({{=$nextValid}}) {
55     {{?}}
56   {{??}}
57     {{
58       $async = $refVal.$async === true;
59       $refCode = $refVal.code;
60     }}
61   {{?}}
62 {{?}}
63
64 {{? $refCode }}
65   {{# def.beginDefOut}}
66     {{# def._validateRef:$refCode }}
67   {{# def.storeDefOut:__callValidate }}
68
69   {{? $async }}
70     {{ if (!it.async) throw new Error('async schema referenced by sync schema'); }}
71     try { {{? $breakOnError }}var {{=$valid}} ={{?}} {{=it.yieldAwait}} {{=__callValidate}}; }
72     catch (e) {
73       if (!(e instanceof ValidationError)) throw e;
74       if (vErrors === null) vErrors = e.errors;
75       else vErrors = vErrors.concat(e.errors);
76       errors = vErrors.length;
77     }
78     {{? $breakOnError }} if ({{=$valid}}) { {{?}}
79   {{??}}
80     if (!{{=__callValidate}}) {
81       if (vErrors === null) vErrors = {{=$refCode}}.errors;
82       else vErrors = vErrors.concat({{=$refCode}}.errors);
83       errors = vErrors.length;
84     } {{? $breakOnError }} else { {{?}}
85   {{?}}
86 {{?}}