aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-29 18:57:29 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-29 18:57:29 -0500
commitbbace4c93bfa110a3a0c282bd72a6d9737465f4f (patch)
treec08369e976a33ed94234417a991d5395b55c5b5b /ext/bg/js
parente2a4a46e6006b9a85a3b6e5e26f55076afb16919 (diff)
Fix schema defaults not applying to arrays
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/json-schema.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/ext/bg/js/json-schema.js b/ext/bg/js/json-schema.js
index b059d757..3238bc3e 100644
--- a/ext/bg/js/json-schema.js
+++ b/ext/bg/js/json-schema.js
@@ -352,8 +352,13 @@ class JsonSchemaProxyHandler {
}
}
- if (type === 'object') {
- value = JsonSchemaProxyHandler.populateObjectDefaults(value, schema);
+ switch (type) {
+ case 'object':
+ value = JsonSchemaProxyHandler.populateObjectDefaults(value, schema);
+ break;
+ case 'array':
+ value = JsonSchemaProxyHandler.populateArrayDefaults(value, schema);
+ break;
}
return value;
@@ -384,6 +389,16 @@ class JsonSchemaProxyHandler {
return value;
}
+
+ static populateArrayDefaults(value, schema) {
+ for (let i = 0, ii = value.length; i < ii; ++i) {
+ const propertySchema = JsonSchemaProxyHandler.getPropertySchema(schema, i);
+ if (propertySchema === null) { continue; }
+ value[i] = JsonSchemaProxyHandler.getValidValueOrDefault(propertySchema, value[i]);
+ }
+
+ return value;
+ }
}
class JsonSchema {