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