3 module.exports = function defFunc(ajv) {
6 macro: function (schema, parentSchema) {
9 , exclusive = parentSchema.exclusiveRange;
11 validateRangeSchema(min, max, exclusive);
13 return exclusive === true
14 ? {exclusiveMinimum: min, exclusiveMaximum: max}
15 : {minimum: min, maximum: max};
21 items: { type: 'number' }
25 ajv.addKeyword('range', defFunc.definition);
26 ajv.addKeyword('exclusiveRange');
29 function validateRangeSchema(min, max, exclusive) {
30 if (exclusive !== undefined && typeof exclusive != 'boolean')
31 throw new Error('Invalid schema for exclusiveRange keyword, should be boolean');
33 if (min > max || (exclusive && min == max))
34 throw new Error('There are no numbers in range');