oneOf.jst 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. {{# def.setupNextLevel }}
  5. {{
  6. var $currentBaseId = $it.baseId
  7. , $prevValid = 'prevValid' + $lvl
  8. , $passingSchemas = 'passingSchemas' + $lvl;
  9. }}
  10. var {{=$errs}} = errors
  11. , {{=$prevValid}} = false
  12. , {{=$valid}} = false
  13. , {{=$passingSchemas}} = null;
  14. {{# def.setCompositeRule }}
  15. {{~ $schema:$sch:$i }}
  16. {{? {{# def.nonEmptySchema:$sch }} }}
  17. {{
  18. $it.schema = $sch;
  19. $it.schemaPath = $schemaPath + '[' + $i + ']';
  20. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  21. }}
  22. {{# def.insertSubschemaCode }}
  23. {{??}}
  24. var {{=$nextValid}} = true;
  25. {{?}}
  26. {{? $i }}
  27. if ({{=$nextValid}} && {{=$prevValid}}) {
  28. {{=$valid}} = false;
  29. {{=$passingSchemas}} = [{{=$passingSchemas}}, {{=$i}}];
  30. } else {
  31. {{ $closingBraces += '}'; }}
  32. {{?}}
  33. if ({{=$nextValid}}) {
  34. {{=$valid}} = {{=$prevValid}} = true;
  35. {{=$passingSchemas}} = {{=$i}};
  36. }
  37. {{~}}
  38. {{# def.resetCompositeRule }}
  39. {{= $closingBraces }}
  40. if (!{{=$valid}}) {
  41. {{# def.extraError:'oneOf' }}
  42. } else {
  43. {{# def.resetErrors }}
  44. {{? it.opts.allErrors }} } {{?}}