aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/json-schema.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-05-22 14:01:32 -0400
committerGitHub <noreply@github.com>2021-05-22 14:01:32 -0400
commit1096bbfa33a4af53ae2bfeee459c313fddb7c20d (patch)
treeda4714238cc0c7cb73a5532b78e04061467c9c7b /ext/js/data/json-schema.js
parentbe23acf499bcdb530c1b8990aa3d6211323cbdb2 (diff)
Update schema tests (#1693)
* Update helper functions * Rename file * Update deleteProperty * Add some basic proxy tests
Diffstat (limited to 'ext/js/data/json-schema.js')
-rw-r--r--ext/js/data/json-schema.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/js/data/json-schema.js b/ext/js/data/json-schema.js
index 7b6b9c53..6a590911 100644
--- a/ext/js/data/json-schema.js
+++ b/ext/js/data/json-schema.js
@@ -103,8 +103,12 @@ class JsonSchemaProxyHandler {
}
deleteProperty(target, property) {
- const required = this._schema.required;
- if (Array.isArray(required) && required.includes(property)) {
+ const required = (
+ (typeof target === 'object' && target !== null) ?
+ (Array.isArray(target) || this._jsonSchemaValidator.isObjectPropertyRequired(this._schema, property)) :
+ true
+ );
+ if (required) {
throw new Error(`${property} cannot be deleted`);
}
return Reflect.deleteProperty(target, property);
@@ -159,6 +163,11 @@ class JsonSchemaValidator {
this._regexCache.clear();
}
+ isObjectPropertyRequired(schema, property) {
+ const {required} = schema;
+ return Array.isArray(required) && required.includes(property);
+ }
+
// Private
_getPropertySchema(schema, property, value, path) {