items.jst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. {{# def.setupNextLevel }}
  5. {{## def.validateItems:startFrom:
  6. for (var {{=$idx}} = {{=startFrom}}; {{=$idx}} < {{=$data}}.length; {{=$idx}}++) {
  7. {{
  8. $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
  9. var $passData = $data + '[' + $idx + ']';
  10. $it.dataPathArr[$dataNxt] = $idx;
  11. }}
  12. {{# def.generateSubschemaCode }}
  13. {{# def.optimizeValidate }}
  14. {{? $breakOnError }}
  15. if (!{{=$nextValid}}) break;
  16. {{?}}
  17. }
  18. #}}
  19. {{
  20. var $idx = 'i' + $lvl
  21. , $dataNxt = $it.dataLevel = it.dataLevel + 1
  22. , $nextData = 'data' + $dataNxt
  23. , $currentBaseId = it.baseId;
  24. }}
  25. var {{=$errs}} = errors;
  26. var {{=$valid}};
  27. {{? Array.isArray($schema) }}
  28. {{ /* 'items' is an array of schemas */}}
  29. {{ var $additionalItems = it.schema.additionalItems; }}
  30. {{? $additionalItems === false }}
  31. {{=$valid}} = {{=$data}}.length <= {{= $schema.length }};
  32. {{
  33. var $currErrSchemaPath = $errSchemaPath;
  34. $errSchemaPath = it.errSchemaPath + '/additionalItems';
  35. }}
  36. {{# def.checkError:'additionalItems' }}
  37. {{ $errSchemaPath = $currErrSchemaPath; }}
  38. {{# def.elseIfValid}}
  39. {{?}}
  40. {{~ $schema:$sch:$i }}
  41. {{? {{# def.nonEmptySchema:$sch }} }}
  42. {{=$nextValid}} = true;
  43. if ({{=$data}}.length > {{=$i}}) {
  44. {{
  45. var $passData = $data + '[' + $i + ']';
  46. $it.schema = $sch;
  47. $it.schemaPath = $schemaPath + '[' + $i + ']';
  48. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  49. $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
  50. $it.dataPathArr[$dataNxt] = $i;
  51. }}
  52. {{# def.generateSubschemaCode }}
  53. {{# def.optimizeValidate }}
  54. }
  55. {{# def.ifResultValid }}
  56. {{?}}
  57. {{~}}
  58. {{? typeof $additionalItems == 'object' && {{# def.nonEmptySchema:$additionalItems }} }}
  59. {{
  60. $it.schema = $additionalItems;
  61. $it.schemaPath = it.schemaPath + '.additionalItems';
  62. $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
  63. }}
  64. {{=$nextValid}} = true;
  65. if ({{=$data}}.length > {{= $schema.length }}) {
  66. {{# def.validateItems: $schema.length }}
  67. }
  68. {{# def.ifResultValid }}
  69. {{?}}
  70. {{?? {{# def.nonEmptySchema:$schema }} }}
  71. {{ /* 'items' is a single schema */}}
  72. {{
  73. $it.schema = $schema;
  74. $it.schemaPath = $schemaPath;
  75. $it.errSchemaPath = $errSchemaPath;
  76. }}
  77. {{# def.validateItems: 0 }}
  78. {{?}}
  79. {{? $breakOnError }}
  80. {{= $closingBraces }}
  81. if ({{=$errs}} == errors) {
  82. {{?}}
  83. {{# def.cleanUp }}