2017-05-03 15:35:00 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ruleModules = require('./_rules')
|
|
|
|
, toHash = require('./util').toHash;
|
|
|
|
|
|
|
|
module.exports = function rules() {
|
|
|
|
var RULES = [
|
|
|
|
{ type: 'number',
|
2017-08-14 05:01:11 +02:00
|
|
|
rules: [ { 'maximum': ['exclusiveMaximum'] },
|
|
|
|
{ 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
|
2017-05-03 15:35:00 +02:00
|
|
|
{ type: 'string',
|
|
|
|
rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
|
|
|
|
{ type: 'array',
|
2017-08-14 05:01:11 +02:00
|
|
|
rules: [ 'maxItems', 'minItems', 'uniqueItems', 'contains', 'items' ] },
|
2017-05-03 15:35:00 +02:00
|
|
|
{ type: 'object',
|
2017-08-14 05:01:11 +02:00
|
|
|
rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
|
|
|
|
{ 'properties': ['additionalProperties', 'patternProperties'] } ] },
|
|
|
|
{ rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
|
2017-05-03 15:35:00 +02:00
|
|
|
];
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
var ALL = [ 'type' ];
|
|
|
|
var KEYWORDS = [
|
|
|
|
'additionalItems', '$schema', 'id', 'title',
|
|
|
|
'description', 'default', 'definitions'
|
|
|
|
];
|
2017-05-03 15:35:00 +02:00
|
|
|
var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
|
|
|
|
RULES.all = toHash(ALL);
|
2017-08-14 05:01:11 +02:00
|
|
|
RULES.types = toHash(TYPES);
|
2017-05-03 15:35:00 +02:00
|
|
|
|
|
|
|
RULES.forEach(function (group) {
|
|
|
|
group.rules = group.rules.map(function (keyword) {
|
2017-08-14 05:01:11 +02:00
|
|
|
var implKeywords;
|
|
|
|
if (typeof keyword == 'object') {
|
|
|
|
var key = Object.keys(keyword)[0];
|
|
|
|
implKeywords = keyword[key];
|
|
|
|
keyword = key;
|
|
|
|
implKeywords.forEach(function (k) {
|
|
|
|
ALL.push(k);
|
|
|
|
RULES.all[k] = true;
|
|
|
|
});
|
|
|
|
}
|
2017-05-03 15:35:00 +02:00
|
|
|
ALL.push(keyword);
|
|
|
|
var rule = RULES.all[keyword] = {
|
|
|
|
keyword: keyword,
|
2017-08-14 05:01:11 +02:00
|
|
|
code: ruleModules[keyword],
|
|
|
|
implements: implKeywords
|
2017-05-03 15:35:00 +02:00
|
|
|
};
|
|
|
|
return rule;
|
|
|
|
});
|
2017-08-14 05:01:11 +02:00
|
|
|
|
|
|
|
if (group.type) RULES.types[group.type] = group;
|
2017-05-03 15:35:00 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
RULES.keywords = toHash(ALL.concat(KEYWORDS));
|
|
|
|
RULES.custom = {};
|
|
|
|
|
|
|
|
return RULES;
|
|
|
|
};
|