| 1 | {{# def.definitions }} |
| 2 | {{# def.errors }} |
| 3 | {{# def.missing }} |
| 4 | {{# def.setupKeyword }} |
| 5 | {{# def.$data }} |
| 6 | |
| 7 | {{ var $vSchema = 'schema' + $lvl; }} |
| 8 | |
| 9 | {{## def.setupLoop: |
| 10 | {{? !$isData }} |
| 11 | var {{=$vSchema}} = validate.schema{{=$schemaPath}}; |
| 12 | {{?}} |
| 13 | |
| 14 | {{ |
| 15 | var $i = 'i' + $lvl |
| 16 | , $propertyPath = 'schema' + $lvl + '[' + $i + ']' |
| 17 | , $missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 18 | if (it.opts._errorDataPathProperty) { |
| 19 | it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers); |
| 20 | } |
| 21 | }} |
| 22 | #}} |
| 23 | |
| 24 | |
| 25 | {{## def.isRequiredOwnProperty: |
| 26 | Object.prototype.hasOwnProperty.call({{=$data}}, {{=$vSchema}}[{{=$i}}]) |
| 27 | #}} |
| 28 | |
| 29 | |
| 30 | {{? !$isData }} |
| 31 | {{? $schema.length < it.opts.loopRequired && |
| 32 | it.schema.properties && Object.keys(it.schema.properties).length }} |
| 33 | {{ var $required = []; }} |
| 34 | {{~ $schema:$property }} |
| 35 | {{ var $propertySch = it.schema.properties[$property]; }} |
| 36 | {{? !($propertySch && {{# def.nonEmptySchema:$propertySch}}) }} |
| 37 | {{ $required[$required.length] = $property; }} |
| 38 | {{?}} |
| 39 | {{~}} |
| 40 | {{??}} |
| 41 | {{ var $required = $schema; }} |
| 42 | {{?}} |
| 43 | {{?}} |
| 44 | |
| 45 | |
| 46 | {{? $isData || $required.length }} |
| 47 | {{ |
| 48 | var $currentErrorPath = it.errorPath |
| 49 | , $loopRequired = $isData || $required.length >= it.opts.loopRequired |
| 50 | , $ownProperties = it.opts.ownProperties; |
| 51 | }} |
| 52 | |
| 53 | {{? $breakOnError }} |
| 54 | var missing{{=$lvl}}; |
| 55 | {{? $loopRequired }} |
| 56 | {{# def.setupLoop }} |
| 57 | var {{=$valid}} = true; |
| 58 | |
| 59 | {{?$isData}}{{# def.check$dataIsArray }}{{?}} |
| 60 | |
| 61 | for (var {{=$i}} = 0; {{=$i}} < {{=$vSchema}}.length; {{=$i}}++) { |
| 62 | {{=$valid}} = {{=$data}}[{{=$vSchema}}[{{=$i}}]] !== undefined |
| 63 | {{? $ownProperties }} |
| 64 | && {{# def.isRequiredOwnProperty }} |
| 65 | {{?}}; |
| 66 | if (!{{=$valid}}) break; |
| 67 | } |
| 68 | |
| 69 | {{? $isData }} } {{?}} |
| 70 | |
| 71 | {{# def.checkError:'required' }} |
| 72 | else { |
| 73 | {{??}} |
| 74 | if ({{# def.checkMissingProperty:$required }}) { |
| 75 | {{# def.errorMissingProperty:'required' }} |
| 76 | } else { |
| 77 | {{?}} |
| 78 | {{??}} |
| 79 | {{? $loopRequired }} |
| 80 | {{# def.setupLoop }} |
| 81 | {{? $isData }} |
| 82 | if ({{=$vSchema}} && !Array.isArray({{=$vSchema}})) { |
| 83 | {{# def.addError:'required' }} |
| 84 | } else if ({{=$vSchema}} !== undefined) { |
| 85 | {{?}} |
| 86 | |
| 87 | for (var {{=$i}} = 0; {{=$i}} < {{=$vSchema}}.length; {{=$i}}++) { |
| 88 | if ({{=$data}}[{{=$vSchema}}[{{=$i}}]] === undefined |
| 89 | {{? $ownProperties }} |
| 90 | || !{{# def.isRequiredOwnProperty }} |
| 91 | {{?}}) { |
| 92 | {{# def.addError:'required' }} |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | {{? $isData }} } {{?}} |
| 97 | {{??}} |
| 98 | {{~ $required:$propertyKey }} |
| 99 | {{# def.allErrorsMissingProperty:'required' }} |
| 100 | {{~}} |
| 101 | {{?}} |
| 102 | {{?}} |
| 103 | |
| 104 | {{ it.errorPath = $currentErrorPath; }} |
| 105 | |
| 106 | {{?? $breakOnError }} |
| 107 | if (true) { |
| 108 | {{?}} |