Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

properties.jst 7.5KB

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