40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
var ruleModules = require('./_rules')
|
|
, toHash = require('./util').toHash;
|
|
|
|
module.exports = function rules() {
|
|
var RULES = [
|
|
{ type: 'number',
|
|
rules: [ 'maximum', 'minimum', 'multipleOf'] },
|
|
{ type: 'string',
|
|
rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
|
|
{ type: 'array',
|
|
rules: [ 'maxItems', 'minItems', 'uniqueItems', 'items' ] },
|
|
{ type: 'object',
|
|
rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'properties' ] },
|
|
{ rules: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
|
|
];
|
|
|
|
var ALL = [ 'type', 'additionalProperties', 'patternProperties' ];
|
|
var KEYWORDS = [ 'additionalItems', '$schema', 'id', 'title', 'description', 'default' ];
|
|
var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
|
|
RULES.all = toHash(ALL);
|
|
|
|
RULES.forEach(function (group) {
|
|
group.rules = group.rules.map(function (keyword) {
|
|
ALL.push(keyword);
|
|
var rule = RULES.all[keyword] = {
|
|
keyword: keyword,
|
|
code: ruleModules[keyword]
|
|
};
|
|
return rule;
|
|
});
|
|
});
|
|
|
|
RULES.keywords = toHash(ALL.concat(KEYWORDS));
|
|
RULES.types = toHash(TYPES);
|
|
RULES.custom = {};
|
|
|
|
return RULES;
|
|
};
|