allOf.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. module.exports = function generate_allOf(it, $keyword, $ruleType) {
  3. var out = ' ';
  4. var $schema = it.schema[$keyword];
  5. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  6. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  7. var $breakOnError = !it.opts.allErrors;
  8. var $it = it.util.copy(it);
  9. var $closingBraces = '';
  10. $it.level++;
  11. var $nextValid = 'valid' + $it.level;
  12. var $currentBaseId = $it.baseId,
  13. $allSchemasEmpty = true;
  14. var arr1 = $schema;
  15. if (arr1) {
  16. var $sch, $i = -1,
  17. l1 = arr1.length - 1;
  18. while ($i < l1) {
  19. $sch = arr1[$i += 1];
  20. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  21. $allSchemasEmpty = false;
  22. $it.schema = $sch;
  23. $it.schemaPath = $schemaPath + '[' + $i + ']';
  24. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  25. out += ' ' + (it.validate($it)) + ' ';
  26. $it.baseId = $currentBaseId;
  27. if ($breakOnError) {
  28. out += ' if (' + ($nextValid) + ') { ';
  29. $closingBraces += '}';
  30. }
  31. }
  32. }
  33. }
  34. if ($breakOnError) {
  35. if ($allSchemasEmpty) {
  36. out += ' if (true) { ';
  37. } else {
  38. out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
  39. }
  40. }
  41. out = it.util.cleanUpCode(out);
  42. return out;
  43. }