source: imaps-frontend/node_modules/ajv/lib/compile/rules.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.0 KB
Line 
1'use strict';
2
3var ruleModules = require('../dotjs')
4 , toHash = require('./util').toHash;
5
6module.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', 'items', 'contains', 'uniqueItems' ] },
15 { type: 'object',
16 rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
17 { 'properties': ['additionalProperties', 'patternProperties'] } ] },
18 { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
19 ];
20
21 var ALL = [ 'type', '$comment' ];
22 var KEYWORDS = [
23 '$schema', '$id', 'id', '$data', '$async', 'title',
24 'description', 'default', 'definitions',
25 'examples', 'readOnly', 'writeOnly',
26 'contentMediaType', 'contentEncoding',
27 'additionalItems', 'then', 'else'
28 ];
29 var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
30 RULES.all = toHash(ALL);
31 RULES.types = toHash(TYPES);
32
33 RULES.forEach(function (group) {
34 group.rules = group.rules.map(function (keyword) {
35 var implKeywords;
36 if (typeof keyword == 'object') {
37 var key = Object.keys(keyword)[0];
38 implKeywords = keyword[key];
39 keyword = key;
40 implKeywords.forEach(function (k) {
41 ALL.push(k);
42 RULES.all[k] = true;
43 });
44 }
45 ALL.push(keyword);
46 var rule = RULES.all[keyword] = {
47 keyword: keyword,
48 code: ruleModules[keyword],
49 implements: implKeywords
50 };
51 return rule;
52 });
53
54 RULES.all.$comment = {
55 keyword: '$comment',
56 code: ruleModules.$comment
57 };
58
59 if (group.type) RULES.types[group.type] = group;
60 });
61
62 RULES.keywords = toHash(ALL.concat(KEYWORDS));
63 RULES.custom = {};
64
65 return RULES;
66};
Note: See TracBrowser for help on using the repository browser.