diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-09-13 19:59:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-13 19:59:02 -0400 |
commit | 8d2847756271a1b4eb06a27b044b4096bd21f55c (patch) | |
tree | 3c2fb17a0376bd48d74fdefb335106dee844feef /ext/bg | |
parent | 8c2e078f1781e17b22b18b3550bbc971a8c07e0d (diff) |
Fix default options missing profiles (#829)
* Add minItems requirement for profiles array
* Use minItems/maxItems for default value construction
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/data/options-schema.json | 1 | ||||
-rw-r--r-- | ext/bg/js/json-schema.js | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json index 93dde1e0..71d5e7db 100644 --- a/ext/bg/data/options-schema.json +++ b/ext/bg/data/options-schema.json @@ -15,6 +15,7 @@ }, "profiles": { "type": "array", + "minItems": 1, "items": { "type": "object", "required": [ diff --git a/ext/bg/js/json-schema.js b/ext/bg/js/json-schema.js index cdfd339f..357432e5 100644 --- a/ext/bg/js/json-schema.js +++ b/ext/bg/js/json-schema.js @@ -653,6 +653,21 @@ class JsonSchemaValidator { value[i] = this.getValidValueOrDefault(propertySchema, value[i]); } + const minItems = schema.minItems; + if (typeof minItems === 'number' && value.length < minItems) { + for (let i = value.length; i < minItems; ++i) { + const propertySchema = this._getPropertySchema(schema, i, value, null); + if (propertySchema === null) { break; } + const item = this.getValidValueOrDefault(propertySchema); + value.push(item); + } + } + + const maxItems = schema.maxItems; + if (typeof maxItems === 'number' && value.length > maxItems) { + value.splice(maxItems, value.length - maxItems); + } + return value; } |