Commit 704e691d authored by Boris Kocherov's avatar Boris Kocherov

tv4: add support exclusiveMinimum and exclusiveMaximum from draft7

parent d74a7691
...@@ -814,18 +814,24 @@ ValidatorContext.prototype.validateMinMax = function validateMinMax(data, schema ...@@ -814,18 +814,24 @@ ValidatorContext.prototype.validateMinMax = function validateMinMax(data, schema
if (data < schema.minimum) { if (data < schema.minimum) {
return this.createError(ErrorCodes.NUMBER_MINIMUM, {value: data, minimum: schema.minimum}, '', '/minimum', null, data, schema); return this.createError(ErrorCodes.NUMBER_MINIMUM, {value: data, minimum: schema.minimum}, '', '/minimum', null, data, schema);
} }
if (schema.exclusiveMinimum && data === schema.minimum) { if (schema.exclusiveMinimum === true && data === schema.minimum) {
return this.createError(ErrorCodes.NUMBER_MINIMUM_EXCLUSIVE, {value: data, minimum: schema.minimum}, '', '/exclusiveMinimum', null, data, schema); return this.createError(ErrorCodes.NUMBER_MINIMUM_EXCLUSIVE, {value: data, minimum: schema.minimum}, '', '/exclusiveMinimum', null, data, schema);
} }
} }
if ((typeof schema.exclusiveMinimum === "number") && data <= schema.exclusiveMinimum) {
return this.createError(ErrorCodes.NUMBER_MINIMUM_EXCLUSIVE, {value: data, minimum: schema.exclusiveMinimum}, '', '/exclusiveMinimum', null, data, schema);
}
if (schema.maximum !== undefined) { if (schema.maximum !== undefined) {
if (data > schema.maximum) { if (data > schema.maximum) {
return this.createError(ErrorCodes.NUMBER_MAXIMUM, {value: data, maximum: schema.maximum}, '', '/maximum', null, data, schema); return this.createError(ErrorCodes.NUMBER_MAXIMUM, {value: data, maximum: schema.maximum}, '', '/maximum', null, data, schema);
} }
if (schema.exclusiveMaximum && data === schema.maximum) { if (schema.exclusiveMaximum === true && data === schema.maximum) {
return this.createError(ErrorCodes.NUMBER_MAXIMUM_EXCLUSIVE, {value: data, maximum: schema.maximum}, '', '/exclusiveMaximum', null, data, schema); return this.createError(ErrorCodes.NUMBER_MAXIMUM_EXCLUSIVE, {value: data, maximum: schema.maximum}, '', '/exclusiveMaximum', null, data, schema);
} }
} }
if ((typeof schema.exclusiveMaximum === "number") && data >= schema.exclusiveMaximum) {
return this.createError(ErrorCodes.NUMBER_MAXIMUM_EXCLUSIVE, {value: data, maximum: schema.exclusiveMaximum}, '', '/exclusiveMaximum', null, data, schema);
}
return null; return null;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment