[d565449] | 1 | {{# def.definitions }}
|
---|
| 2 | {{# def.errors }}
|
---|
| 3 | {{# def.setupKeyword }}
|
---|
| 4 | {{# def.setupNextLevel }}
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | {{## def.validateAdditional:
|
---|
| 8 | {{ /* additionalProperties is schema */
|
---|
| 9 | $it.schema = $aProperties;
|
---|
| 10 | $it.schemaPath = it.schemaPath + '.additionalProperties';
|
---|
| 11 | $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
|
---|
| 12 | $it.errorPath = it.opts._errorDataPathProperty
|
---|
| 13 | ? it.errorPath
|
---|
| 14 | : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
|
---|
| 15 | var $passData = $data + '[' + $key + ']';
|
---|
| 16 | $it.dataPathArr[$dataNxt] = $key;
|
---|
| 17 | }}
|
---|
| 18 |
|
---|
| 19 | {{# def.generateSubschemaCode }}
|
---|
| 20 | {{# def.optimizeValidate }}
|
---|
| 21 | #}}
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | {{
|
---|
| 25 | var $key = 'key' + $lvl
|
---|
| 26 | , $idx = 'idx' + $lvl
|
---|
| 27 | , $dataNxt = $it.dataLevel = it.dataLevel + 1
|
---|
| 28 | , $nextData = 'data' + $dataNxt
|
---|
| 29 | , $dataProperties = 'dataProperties' + $lvl;
|
---|
| 30 |
|
---|
| 31 | var $schemaKeys = Object.keys($schema || {}).filter(notProto)
|
---|
| 32 | , $pProperties = it.schema.patternProperties || {}
|
---|
| 33 | , $pPropertyKeys = Object.keys($pProperties).filter(notProto)
|
---|
| 34 | , $aProperties = it.schema.additionalProperties
|
---|
| 35 | , $someProperties = $schemaKeys.length || $pPropertyKeys.length
|
---|
| 36 | , $noAdditional = $aProperties === false
|
---|
| 37 | , $additionalIsSchema = typeof $aProperties == 'object'
|
---|
| 38 | && Object.keys($aProperties).length
|
---|
| 39 | , $removeAdditional = it.opts.removeAdditional
|
---|
| 40 | , $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional
|
---|
| 41 | , $ownProperties = it.opts.ownProperties
|
---|
| 42 | , $currentBaseId = it.baseId;
|
---|
| 43 |
|
---|
| 44 | var $required = it.schema.required;
|
---|
| 45 | if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) {
|
---|
| 46 | var $requiredHash = it.util.toHash($required);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | function notProto(p) { return p !== '__proto__'; }
|
---|
| 50 | }}
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | var {{=$errs}} = errors;
|
---|
| 54 | var {{=$nextValid}} = true;
|
---|
| 55 | {{? $ownProperties }}
|
---|
| 56 | var {{=$dataProperties}} = undefined;
|
---|
| 57 | {{?}}
|
---|
| 58 |
|
---|
| 59 | {{? $checkAdditional }}
|
---|
| 60 | {{# def.iterateProperties }}
|
---|
| 61 | {{? $someProperties }}
|
---|
| 62 | var isAdditional{{=$lvl}} = !(false
|
---|
| 63 | {{? $schemaKeys.length }}
|
---|
| 64 | {{? $schemaKeys.length > 8 }}
|
---|
| 65 | || validate.schema{{=$schemaPath}}.hasOwnProperty({{=$key}})
|
---|
| 66 | {{??}}
|
---|
| 67 | {{~ $schemaKeys:$propertyKey }}
|
---|
| 68 | || {{=$key}} == {{= it.util.toQuotedString($propertyKey) }}
|
---|
| 69 | {{~}}
|
---|
| 70 | {{?}}
|
---|
| 71 | {{?}}
|
---|
| 72 | {{? $pPropertyKeys.length }}
|
---|
| 73 | {{~ $pPropertyKeys:$pProperty:$i }}
|
---|
| 74 | || {{= it.usePattern($pProperty) }}.test({{=$key}})
|
---|
| 75 | {{~}}
|
---|
| 76 | {{?}}
|
---|
| 77 | );
|
---|
| 78 |
|
---|
| 79 | if (isAdditional{{=$lvl}}) {
|
---|
| 80 | {{?}}
|
---|
| 81 | {{? $removeAdditional == 'all' }}
|
---|
| 82 | delete {{=$data}}[{{=$key}}];
|
---|
| 83 | {{??}}
|
---|
| 84 | {{
|
---|
| 85 | var $currentErrorPath = it.errorPath;
|
---|
| 86 | var $additionalProperty = '\' + ' + $key + ' + \'';
|
---|
| 87 | if (it.opts._errorDataPathProperty) {
|
---|
| 88 | it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
|
---|
| 89 | }
|
---|
| 90 | }}
|
---|
| 91 | {{? $noAdditional }}
|
---|
| 92 | {{? $removeAdditional }}
|
---|
| 93 | delete {{=$data}}[{{=$key}}];
|
---|
| 94 | {{??}}
|
---|
| 95 | {{=$nextValid}} = false;
|
---|
| 96 | {{
|
---|
| 97 | var $currErrSchemaPath = $errSchemaPath;
|
---|
| 98 | $errSchemaPath = it.errSchemaPath + '/additionalProperties';
|
---|
| 99 | }}
|
---|
| 100 | {{# def.error:'additionalProperties' }}
|
---|
| 101 | {{ $errSchemaPath = $currErrSchemaPath; }}
|
---|
| 102 | {{? $breakOnError }} break; {{?}}
|
---|
| 103 | {{?}}
|
---|
| 104 | {{?? $additionalIsSchema }}
|
---|
| 105 | {{? $removeAdditional == 'failing' }}
|
---|
| 106 | var {{=$errs}} = errors;
|
---|
| 107 | {{# def.setCompositeRule }}
|
---|
| 108 |
|
---|
| 109 | {{# def.validateAdditional }}
|
---|
| 110 |
|
---|
| 111 | if (!{{=$nextValid}}) {
|
---|
| 112 | errors = {{=$errs}};
|
---|
| 113 | if (validate.errors !== null) {
|
---|
| 114 | if (errors) validate.errors.length = errors;
|
---|
| 115 | else validate.errors = null;
|
---|
| 116 | }
|
---|
| 117 | delete {{=$data}}[{{=$key}}];
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | {{# def.resetCompositeRule }}
|
---|
| 121 | {{??}}
|
---|
| 122 | {{# def.validateAdditional }}
|
---|
| 123 | {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
|
---|
| 124 | {{?}}
|
---|
| 125 | {{?}}
|
---|
| 126 | {{ it.errorPath = $currentErrorPath; }}
|
---|
| 127 | {{?}}
|
---|
| 128 | {{? $someProperties }}
|
---|
| 129 | }
|
---|
| 130 | {{?}}
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | {{# def.ifResultValid }}
|
---|
| 134 | {{?}}
|
---|
| 135 |
|
---|
| 136 | {{ var $useDefaults = it.opts.useDefaults && !it.compositeRule; }}
|
---|
| 137 |
|
---|
| 138 | {{? $schemaKeys.length }}
|
---|
| 139 | {{~ $schemaKeys:$propertyKey }}
|
---|
| 140 | {{ var $sch = $schema[$propertyKey]; }}
|
---|
| 141 |
|
---|
| 142 | {{? {{# def.nonEmptySchema:$sch}} }}
|
---|
| 143 | {{
|
---|
| 144 | var $prop = it.util.getProperty($propertyKey)
|
---|
| 145 | , $passData = $data + $prop
|
---|
| 146 | , $hasDefault = $useDefaults && $sch.default !== undefined;
|
---|
| 147 | $it.schema = $sch;
|
---|
| 148 | $it.schemaPath = $schemaPath + $prop;
|
---|
| 149 | $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
|
---|
| 150 | $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
|
---|
| 151 | $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
|
---|
| 152 | }}
|
---|
| 153 |
|
---|
| 154 | {{# def.generateSubschemaCode }}
|
---|
| 155 |
|
---|
| 156 | {{? {{# def.willOptimize }} }}
|
---|
| 157 | {{
|
---|
| 158 | $code = {{# def._optimizeValidate }};
|
---|
| 159 | var $useData = $passData;
|
---|
| 160 | }}
|
---|
| 161 | {{??}}
|
---|
| 162 | {{ var $useData = $nextData; }}
|
---|
| 163 | var {{=$nextData}} = {{=$passData}};
|
---|
| 164 | {{?}}
|
---|
| 165 |
|
---|
| 166 | {{? $hasDefault }}
|
---|
| 167 | {{= $code }}
|
---|
| 168 | {{??}}
|
---|
| 169 | {{? $requiredHash && $requiredHash[$propertyKey] }}
|
---|
| 170 | if ({{# def.noPropertyInData }}) {
|
---|
| 171 | {{=$nextValid}} = false;
|
---|
| 172 | {{
|
---|
| 173 | var $currentErrorPath = it.errorPath
|
---|
| 174 | , $currErrSchemaPath = $errSchemaPath
|
---|
| 175 | , $missingProperty = it.util.escapeQuotes($propertyKey);
|
---|
| 176 | if (it.opts._errorDataPathProperty) {
|
---|
| 177 | it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
---|
| 178 | }
|
---|
| 179 | $errSchemaPath = it.errSchemaPath + '/required';
|
---|
| 180 | }}
|
---|
| 181 | {{# def.error:'required' }}
|
---|
| 182 | {{ $errSchemaPath = $currErrSchemaPath; }}
|
---|
| 183 | {{ it.errorPath = $currentErrorPath; }}
|
---|
| 184 | } else {
|
---|
| 185 | {{??}}
|
---|
| 186 | {{? $breakOnError }}
|
---|
| 187 | if ({{# def.noPropertyInData }}) {
|
---|
| 188 | {{=$nextValid}} = true;
|
---|
| 189 | } else {
|
---|
| 190 | {{??}}
|
---|
| 191 | if ({{=$useData}} !== undefined
|
---|
| 192 | {{? $ownProperties }}
|
---|
| 193 | && {{# def.isOwnProperty }}
|
---|
| 194 | {{?}}
|
---|
| 195 | ) {
|
---|
| 196 | {{?}}
|
---|
| 197 | {{?}}
|
---|
| 198 |
|
---|
| 199 | {{= $code }}
|
---|
| 200 | }
|
---|
| 201 | {{?}} {{ /* $hasDefault */ }}
|
---|
| 202 | {{?}} {{ /* def.nonEmptySchema */ }}
|
---|
| 203 |
|
---|
| 204 | {{# def.ifResultValid }}
|
---|
| 205 | {{~}}
|
---|
| 206 | {{?}}
|
---|
| 207 |
|
---|
| 208 | {{? $pPropertyKeys.length }}
|
---|
| 209 | {{~ $pPropertyKeys:$pProperty }}
|
---|
| 210 | {{ var $sch = $pProperties[$pProperty]; }}
|
---|
| 211 |
|
---|
| 212 | {{? {{# def.nonEmptySchema:$sch}} }}
|
---|
| 213 | {{
|
---|
| 214 | $it.schema = $sch;
|
---|
| 215 | $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
|
---|
| 216 | $it.errSchemaPath = it.errSchemaPath + '/patternProperties/'
|
---|
| 217 | + it.util.escapeFragment($pProperty);
|
---|
| 218 | }}
|
---|
| 219 |
|
---|
| 220 | {{# def.iterateProperties }}
|
---|
| 221 | if ({{= it.usePattern($pProperty) }}.test({{=$key}})) {
|
---|
| 222 | {{
|
---|
| 223 | $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
|
---|
| 224 | var $passData = $data + '[' + $key + ']';
|
---|
| 225 | $it.dataPathArr[$dataNxt] = $key;
|
---|
| 226 | }}
|
---|
| 227 |
|
---|
| 228 | {{# def.generateSubschemaCode }}
|
---|
| 229 | {{# def.optimizeValidate }}
|
---|
| 230 |
|
---|
| 231 | {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
|
---|
| 232 | }
|
---|
| 233 | {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | {{# def.ifResultValid }}
|
---|
| 237 | {{?}} {{ /* def.nonEmptySchema */ }}
|
---|
| 238 | {{~}}
|
---|
| 239 | {{?}}
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | {{? $breakOnError }}
|
---|
| 243 | {{= $closingBraces }}
|
---|
| 244 | if ({{=$errs}} == errors) {
|
---|
| 245 | {{?}}
|
---|