Add support for conditionals
This commit is contained in:
parent
6595715f7c
commit
203216986e
@ -154,6 +154,9 @@ class JsonSchemaProxyHandler {
|
|||||||
let result = JsonSchemaProxyHandler.validateSingleSchema(value, schema);
|
let result = JsonSchemaProxyHandler.validateSingleSchema(value, schema);
|
||||||
if (result !== null) { return result; }
|
if (result !== null) { return result; }
|
||||||
|
|
||||||
|
result = JsonSchemaProxyHandler.validateConditional(value, schema);
|
||||||
|
if (result !== null) { return result; }
|
||||||
|
|
||||||
result = JsonSchemaProxyHandler.validateAllOf(value, schema);
|
result = JsonSchemaProxyHandler.validateAllOf(value, schema);
|
||||||
if (result !== null) { return result; }
|
if (result !== null) { return result; }
|
||||||
|
|
||||||
@ -169,6 +172,25 @@ class JsonSchemaProxyHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static validateConditional(value, schema) {
|
||||||
|
const ifCondition = schema.if;
|
||||||
|
if (!JsonSchemaProxyHandler.isObject(ifCondition)) { return null; }
|
||||||
|
|
||||||
|
const thenSchema = schema.then;
|
||||||
|
if (JsonSchemaProxyHandler.isObject(thenSchema)) {
|
||||||
|
const result = JsonSchemaProxyHandler.validate(value, thenSchema);
|
||||||
|
if (result !== null) { return `then conditional didn't match: ${result}`; }
|
||||||
|
}
|
||||||
|
|
||||||
|
const elseSchema = schema.else;
|
||||||
|
if (JsonSchemaProxyHandler.isObject(elseSchema)) {
|
||||||
|
const result = JsonSchemaProxyHandler.validate(value, thenSchema);
|
||||||
|
if (result !== null) { return `else conditional didn't match: ${result}`; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
static validateAllOf(value, schema) {
|
static validateAllOf(value, schema) {
|
||||||
const subSchemas = schema.allOf;
|
const subSchemas = schema.allOf;
|
||||||
if (!Array.isArray(subSchemas)) { return null; }
|
if (!Array.isArray(subSchemas)) { return null; }
|
||||||
|
Loading…
Reference in New Issue
Block a user