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