dependencies.jst 1.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{{# def.definitions }}
{{# def.errors }}
{{# def.missing }}
{{# def.setupKeyword }}
{{# def.setupNextLevel }}


{{## def.propertyInData:
  {{=$data}}{{= it.util.getProperty($property) }} !== undefined
  {{? $ownProperties }}
    && Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($property)}}')
  {{?}}
#}}


{{
  var $schemaDeps = {}
    , $propertyDeps = {}
    , $ownProperties = it.opts.ownProperties;

  for ($property in $schema) {
    if ($property == '__proto__') continue;
    var $sch = $schema[$property];
    var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
    $deps[$property] = $sch;
  }
}}

var {{=$errs}} = errors;

{{ var $currentErrorPath = it.errorPath; }}

var missing{{=$lvl}};
{{ for (var $property in $propertyDeps) { }}
  {{ $deps = $propertyDeps[$property]; }}
  {{? $deps.length }}
    if ({{# def.propertyInData }}
      {{? $breakOnError }}
          && ({{# def.checkMissingProperty:$deps }})) {
          {{# def.errorMissingProperty:'dependencies' }}
      {{??}}
        ) {
          {{~ $deps:$propertyKey }}
            {{# def.allErrorsMissingProperty:'dependencies' }}
          {{~}}
      {{?}}
    } {{# def.elseIfValid }}
  {{?}}
{{ } }}

{{
  it.errorPath = $currentErrorPath;
  var $currentBaseId = $it.baseId;
}}


{{ for (var $property in $schemaDeps) { }}
  {{ var $sch = $schemaDeps[$property]; }}
  {{? {{# def.nonEmptySchema:$sch }} }}
    {{=$nextValid}} = true;

    if ({{# def.propertyInData }}) {
      {{ 
        $it.schema = $sch;
        $it.schemaPath = $schemaPath + it.util.getProperty($property);
        $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
      }}

      {{# def.insertSubschemaCode }}
    }

    {{# def.ifResultValid }}
  {{?}}
{{ } }}

{{? $breakOnError }} 
  {{= $closingBraces }}
  if ({{=$errs}} == errors) {
{{?}}