aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/json-schema.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-26 11:13:13 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-02 10:12:01 -0500
commit203216986e82d8b6c654979791d1ff5172ba83ca (patch)
treecdde5e8d7dc11a94f71a4287131669a4993825a0 /ext/bg/js/json-schema.js
parent6595715f7cdf1c4d0de743443b88eba05d7d6ae1 (diff)
Add support for conditionals
Diffstat (limited to 'ext/bg/js/json-schema.js')
-rw-r--r--ext/bg/js/json-schema.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/ext/bg/js/json-schema.js b/ext/bg/js/json-schema.js
index 8129b6d2..ab4a4817 100644
--- a/ext/bg/js/json-schema.js
+++ b/ext/bg/js/json-schema.js
@@ -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; }