Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

rules.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. var ruleModules = require('../dotjs')
  3. , toHash = require('./util').toHash;
  4. module.exports = function rules() {
  5. var RULES = [
  6. { type: 'number',
  7. rules: [ { 'maximum': ['exclusiveMaximum'] },
  8. { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
  9. { type: 'string',
  10. rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
  11. { type: 'array',
  12. rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
  13. { type: 'object',
  14. rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
  15. { 'properties': ['additionalProperties', 'patternProperties'] } ] },
  16. { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
  17. ];
  18. var ALL = [ 'type', '$comment' ];
  19. var KEYWORDS = [
  20. '$schema', '$id', 'id', '$data', '$async', 'title',
  21. 'description', 'default', 'definitions',
  22. 'examples', 'readOnly', 'writeOnly',
  23. 'contentMediaType', 'contentEncoding',
  24. 'additionalItems', 'then', 'else'
  25. ];
  26. var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
  27. RULES.all = toHash(ALL);
  28. RULES.types = toHash(TYPES);
  29. RULES.forEach(function (group) {
  30. group.rules = group.rules.map(function (keyword) {
  31. var implKeywords;
  32. if (typeof keyword == 'object') {
  33. var key = Object.keys(keyword)[0];
  34. implKeywords = keyword[key];
  35. keyword = key;
  36. implKeywords.forEach(function (k) {
  37. ALL.push(k);
  38. RULES.all[k] = true;
  39. });
  40. }
  41. ALL.push(keyword);
  42. var rule = RULES.all[keyword] = {
  43. keyword: keyword,
  44. code: ruleModules[keyword],
  45. implements: implKeywords
  46. };
  47. return rule;
  48. });
  49. RULES.all.$comment = {
  50. keyword: '$comment',
  51. code: ruleModules.$comment
  52. };
  53. if (group.type) RULES.types[group.type] = group;
  54. });
  55. RULES.keywords = toHash(ALL.concat(KEYWORDS));
  56. RULES.custom = {};
  57. return RULES;
  58. };