Fix default options missing profiles (#829)

* Add minItems requirement for profiles array

* Use minItems/maxItems for default value construction
This commit is contained in:
toasted-nutbread 2020-09-13 19:59:02 -04:00 committed by GitHub
parent 8c2e078f17
commit 8d28477562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -15,6 +15,7 @@
},
"profiles": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [

View File

@ -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;
}