contains.jst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. {{# def.setupNextLevel }}
  5. {{
  6. var $idx = 'i' + $lvl
  7. , $dataNxt = $it.dataLevel = it.dataLevel + 1
  8. , $nextData = 'data' + $dataNxt
  9. , $currentBaseId = it.baseId
  10. , $nonEmptySchema = {{# def.nonEmptySchema:$schema }};
  11. }}
  12. var {{=$errs}} = errors;
  13. var {{=$valid}};
  14. {{? $nonEmptySchema }}
  15. {{# def.setCompositeRule }}
  16. {{
  17. $it.schema = $schema;
  18. $it.schemaPath = $schemaPath;
  19. $it.errSchemaPath = $errSchemaPath;
  20. }}
  21. var {{=$nextValid}} = false;
  22. for (var {{=$idx}} = 0; {{=$idx}} < {{=$data}}.length; {{=$idx}}++) {
  23. {{
  24. $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
  25. var $passData = $data + '[' + $idx + ']';
  26. $it.dataPathArr[$dataNxt] = $idx;
  27. }}
  28. {{# def.generateSubschemaCode }}
  29. {{# def.optimizeValidate }}
  30. if ({{=$nextValid}}) break;
  31. }
  32. {{# def.resetCompositeRule }}
  33. {{= $closingBraces }}
  34. if (!{{=$nextValid}}) {
  35. {{??}}
  36. if ({{=$data}}.length == 0) {
  37. {{?}}
  38. {{# def.error:'contains' }}
  39. } else {
  40. {{? $nonEmptySchema }}
  41. {{# def.resetErrors }}
  42. {{?}}
  43. {{? it.opts.allErrors }} } {{?}}