v5.js
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
var META_SCHEMA_ID = 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json';
module.exports = {
enable: enableV5,
META_SCHEMA_ID: META_SCHEMA_ID
};
function enableV5(ajv) {
var inlineFunctions = {
'switch': require('./dotjs/switch'),
'constant': require('./dotjs/constant'),
'_formatLimit': require('./dotjs/_formatLimit'),
'patternRequired': require('./dotjs/patternRequired')
};
if (ajv._opts.meta !== false) {
var metaSchema = require('./refs/json-schema-v5.json');
ajv.addMetaSchema(metaSchema, META_SCHEMA_ID);
}
_addKeyword('constant');
ajv.addKeyword('contains', { type: 'array', macro: containsMacro });
_addKeyword('formatMaximum', 'string', inlineFunctions._formatLimit);
_addKeyword('formatMinimum', 'string', inlineFunctions._formatLimit);
ajv.addKeyword('formatExclusiveMaximum');
ajv.addKeyword('formatExclusiveMinimum');
ajv.addKeyword('patternGroups'); // implemented in properties.jst
_addKeyword('patternRequired', 'object');
_addKeyword('switch');
function _addKeyword(keyword, types, inlineFunc) {
var definition = {
inline: inlineFunc || inlineFunctions[keyword],
statements: true,
errors: 'full'
};
if (types) definition.type = types;
ajv.addKeyword(keyword, definition);
}
}
function containsMacro(schema) {
return {
not: { items: { not: schema } }
};
}