diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-01-26 12:34:27 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-02-02 10:12:01 -0500 |
commit | 980a1ddf745032a790a043e8040cdb7ec5b110ad (patch) | |
tree | 36bf00e93c1fd625c9504c28a6040060fc6bba3c /ext | |
parent | a844698f153773d5255724ba48a00851418af009 (diff) |
Improve support for array schemas
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/json-schema.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/ext/bg/js/json-schema.js b/ext/bg/js/json-schema.js index 7a7f2489..f32176fd 100644 --- a/ext/bg/js/json-schema.js +++ b/ext/bg/js/json-schema.js @@ -149,7 +149,23 @@ class JsonSchemaProxyHandler { case 'array': { const items = schema.items; - return JsonSchemaProxyHandler.isObject(items) ? items : null; + if (JsonSchemaProxyHandler.isObject(items)) { + return items; + } + if (Array.isArray(items)) { + if (property >= 0 && property < items.length) { + return items[property]; + } + } + + const additionalItems = schema.additionalItems; + if (additionalItems === false) { + return null; + } else if (JsonSchemaProxyHandler.isObject(additionalItems)) { + return additionalItems; + } else { + return JsonSchemaProxyHandler._unconstrainedSchema; + } } default: return null; @@ -322,6 +338,18 @@ class JsonSchemaProxyHandler { return 'Array length too long'; } + for (let i = 0, ii = value.length; i < ii; ++i) { + const propertySchema = JsonSchemaProxyHandler.getPropertySchema(schema, i, value); + if (propertySchema === null) { + return `No schema found for array[${i}]`; + } + + const error = JsonSchemaProxyHandler.validate(value[i], propertySchema); + if (error !== null) { + return error; + } + } + return null; } |