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);
|
||||
if (result !== null) { return result; }
|
||||
|
||||
result = JsonSchemaProxyHandler.validateConditional(value, schema);
|
||||
if (result !== null) { return result; }
|
||||
|
||||
result = JsonSchemaProxyHandler.validateAllOf(value, schema);
|
||||
if (result !== null) { return result; }
|
||||
|
||||
@ -169,6 +172,25 @@ class JsonSchemaProxyHandler {
|
||||
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) {
|
||||
const subSchemas = schema.allOf;
|
||||
if (!Array.isArray(subSchemas)) { return null; }
|
||||
|
Loading…
Reference in New Issue
Block a user