Commit 07dd0ad7 authored by Boris Kocherov's avatar Boris Kocherov

tv4: add support boolean schema

parent ce1f4e38
...@@ -535,7 +535,7 @@ ValidatorContext.prototype.reset = function () { ...@@ -535,7 +535,7 @@ ValidatorContext.prototype.reset = function () {
ValidatorContext.prototype.validateAll = function (data, schema, dataPathParts, schemaPathParts, dataPointerPath) { ValidatorContext.prototype.validateAll = function (data, schema, dataPathParts, schemaPathParts, dataPointerPath) {
var topLevel; var topLevel;
if (!schema) { if (schema === undefined || schema === true) {
return null; return null;
} else if (schema instanceof ValidationError) { } else if (schema instanceof ValidationError) {
this.errors.push(schema); this.errors.push(schema);
...@@ -718,6 +718,9 @@ function recursiveCompare(A, B) { ...@@ -718,6 +718,9 @@ function recursiveCompare(A, B) {
} }
ValidatorContext.prototype.validateBasic = function validateBasic(data, schema, dataPointerPath) { ValidatorContext.prototype.validateBasic = function validateBasic(data, schema, dataPointerPath) {
if (schema === false && data !== undefined) {
return this.createError(ErrorCodes.BOOLEAN_SCHEMA_FALSE, {}, '', '', null, data, schema);
}
var error; var error;
if (error = this.validateType(data, schema, dataPointerPath)) { if (error = this.validateType(data, schema, dataPointerPath)) {
return error.prefixWith(null, "type"); return error.prefixWith(null, "type");
...@@ -1375,6 +1378,7 @@ var ErrorCodes = { ...@@ -1375,6 +1378,7 @@ var ErrorCodes = {
ONE_OF_MISSING: 11, ONE_OF_MISSING: 11,
ONE_OF_MULTIPLE: 12, ONE_OF_MULTIPLE: 12,
NOT_PASSED: 13, NOT_PASSED: 13,
BOOLEAN_SCHEMA_FALSE: 14,
// Numeric errors // Numeric errors
NUMBER_MULTIPLE_OF: 100, NUMBER_MULTIPLE_OF: 100,
NUMBER_MINIMUM: 101, NUMBER_MINIMUM: 101,
...@@ -1416,6 +1420,7 @@ var ErrorMessagesDefault = { ...@@ -1416,6 +1420,7 @@ var ErrorMessagesDefault = {
ONE_OF_MISSING: "Data does not match any schemas from \"oneOf\"", ONE_OF_MISSING: "Data does not match any schemas from \"oneOf\"",
ONE_OF_MULTIPLE: "Data is valid against more than one schema from \"oneOf\": indices {index1} and {index2}", ONE_OF_MULTIPLE: "Data is valid against more than one schema from \"oneOf\": indices {index1} and {index2}",
NOT_PASSED: "Data matches schema from \"not\"", NOT_PASSED: "Data matches schema from \"not\"",
BOOLEAN_SCHEMA_FALSE: "Schema does not allow any data",
// Numeric errors // Numeric errors
NUMBER_MULTIPLE_OF: "Value {value} is not a multiple of {multipleOf}", NUMBER_MULTIPLE_OF: "Value {value} is not a multiple of {multipleOf}",
NUMBER_MINIMUM: "Value {value} is less than minimum {minimum}", NUMBER_MINIMUM: "Value {value} is less than minimum {minimum}",
......
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