cleanup formatMaximum/formatMinimum
parent
1c16707ee5
commit
7141f1375e
20
lib/v5.js
20
lib/v5.js
|
@ -9,29 +9,33 @@ module.exports = {
|
|||
function enableV5(ajv) {
|
||||
ajv.addKeyword('constant', { macro: constantMacro });
|
||||
ajv.addKeyword('contains', { macro: containsMacro });
|
||||
ajv.addKeyword('formatMaximum', { type: 'string', inline: inlineFormatLimit('maximum'), errors: false });
|
||||
ajv.addKeyword('formatMinimum', { type: 'string', inline: inlineFormatLimit('minimum'), errors: false });
|
||||
ajv.addKeyword('formatMaximum', { type: 'string', inline: formatLimit('maximum'), errors: false });
|
||||
ajv.addKeyword('formatMinimum', { type: 'string', inline: formatLimit('minimum'), errors: false });
|
||||
ajv.addKeyword('exclusiveFormatMaximum');
|
||||
ajv.addKeyword('exclusiveFormatMinimum');
|
||||
ajv.addKeyword('patternGroups');
|
||||
}
|
||||
|
||||
function constantMacro(schema) {
|
||||
return { enum: [schema] };
|
||||
return { "enum": [schema] };
|
||||
}
|
||||
|
||||
function containsMacro(schema) {
|
||||
return { not: { items: { not: schema } } };
|
||||
return { "not": { "items": { "not": schema } } };
|
||||
}
|
||||
|
||||
function inlineFormatLimit(limit) {
|
||||
function formatLimit(limit) {
|
||||
var operation = limit == 'maximum' ? '<' : '>';
|
||||
var exclusiveLimit = 'exclusiveFormat' +
|
||||
(limit == 'maximum' ? 'Maximum' : 'Minimum');
|
||||
|
||||
return function(it, schema, parentSchema) {
|
||||
var format = parentSchema.format;
|
||||
var compare = it.formats[format].compare;
|
||||
if (!compare) throw new Error('No format or no comparison for the format');
|
||||
var exclusive = parentSchema[limit == 'minimum' ? 'exclusiveFormatMinimum' : 'exclusiveFormatMaximum'];
|
||||
if (!compare) return 'true';
|
||||
var exclusive = parentSchema[exclusiveLimit];
|
||||
var data = 'data' + (it.dataLevel || '');
|
||||
var op = limit == 'minimum' ? '>' : '<';
|
||||
var op = operation;
|
||||
if (!exclusive) op += '=';
|
||||
return 'formats' + it.util.getProperty(format) + '.compare('
|
||||
+ data + ', ' + it.util.toQuotedString(schema)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ajv",
|
||||
"version": "2.2.0",
|
||||
"version": "2.2.1",
|
||||
"description": "Another JSON Schema Validator",
|
||||
"main": "lib/ajv.js",
|
||||
"files": [
|
||||
|
|
Loading…
Reference in New Issue