2015-11-22 03:31:01 +03:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-13 00:18:41 +03:00
|
|
|
var META_SCHEMA_ID = 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json';
|
2015-11-22 03:31:01 +03:00
|
|
|
|
|
|
|
module.exports = {
|
2015-12-13 00:18:41 +03:00
|
|
|
enable: enableV5,
|
|
|
|
META_SCHEMA_ID: META_SCHEMA_ID
|
2015-11-22 03:31:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function enableV5(ajv) {
|
2016-02-28 01:36:11 +03:00
|
|
|
var inlineFunctions = {
|
|
|
|
'switch': require('./dotjs/switch'),
|
|
|
|
'constant': require('./dotjs/constant'),
|
|
|
|
'_formatLimit': require('./dotjs/_formatLimit'),
|
|
|
|
'patternRequired': require('./dotjs/patternRequired')
|
|
|
|
};
|
|
|
|
|
2016-01-21 01:55:14 +03:00
|
|
|
if (ajv._opts.meta !== false) {
|
2015-12-13 00:18:41 +03:00
|
|
|
var metaSchema = require('./refs/json-schema-v5.json');
|
|
|
|
ajv.addMetaSchema(metaSchema, META_SCHEMA_ID);
|
|
|
|
}
|
2016-02-28 01:36:11 +03:00
|
|
|
_addKeyword('constant');
|
2015-12-27 02:04:45 +03:00
|
|
|
ajv.addKeyword('contains', { type: 'array', macro: containsMacro });
|
2015-12-24 20:43:48 +03:00
|
|
|
|
2016-02-28 01:36:11 +03:00
|
|
|
_addKeyword('formatMaximum', 'string', inlineFunctions._formatLimit);
|
|
|
|
_addKeyword('formatMinimum', 'string', inlineFunctions._formatLimit);
|
2016-03-22 21:40:15 +03:00
|
|
|
ajv.addKeyword('formatExclusiveMaximum');
|
|
|
|
ajv.addKeyword('formatExclusiveMinimum');
|
2015-12-24 20:43:48 +03:00
|
|
|
|
2015-12-12 16:41:51 +03:00
|
|
|
ajv.addKeyword('patternGroups'); // implemented in properties.jst
|
2016-02-28 01:36:11 +03:00
|
|
|
_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);
|
|
|
|
}
|
2015-11-22 03:31:01 +03:00
|
|
|
}
|
|
|
|
|
2016-02-28 01:36:11 +03:00
|
|
|
|
2015-11-22 03:31:01 +03:00
|
|
|
function containsMacro(schema) {
|
2015-12-07 00:57:41 +03:00
|
|
|
return {
|
2016-02-02 21:55:02 +03:00
|
|
|
not: { items: { not: schema } }
|
2015-12-07 00:57:41 +03:00
|
|
|
};
|
2015-11-22 03:31:01 +03:00
|
|
|
}
|