rules.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var ruleModules = require('./_rules')
  3. , toHash = require('./util').toHash;
  4. module.exports = function rules() {
  5. var RULES = [
  6. { type: 'number',
  7. rules: [ 'maximum', 'minimum', 'multipleOf'] },
  8. { type: 'string',
  9. rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
  10. { type: 'array',
  11. rules: [ 'maxItems', 'minItems', 'uniqueItems', 'items' ] },
  12. { type: 'object',
  13. rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'properties' ] },
  14. { rules: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
  15. ];
  16. var ALL = [ 'type', 'additionalProperties', 'patternProperties' ];
  17. var KEYWORDS = [ 'additionalItems', '$schema', 'id', 'title', 'description', 'default' ];
  18. var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
  19. RULES.all = toHash(ALL);
  20. RULES.forEach(function (group) {
  21. group.rules = group.rules.map(function (keyword) {
  22. ALL.push(keyword);
  23. var rule = RULES.all[keyword] = {
  24. keyword: keyword,
  25. code: ruleModules[keyword]
  26. };
  27. return rule;
  28. });
  29. });
  30. RULES.keywords = toHash(ALL.concat(KEYWORDS));
  31. RULES.types = toHash(TYPES);
  32. RULES.custom = {};
  33. return RULES;
  34. };