Fix schema defaults not applying to arrays

This commit is contained in:
toasted-nutbread 2019-12-29 18:57:29 -05:00
parent e2a4a46e60
commit bbace4c93b

View File

@ -352,8 +352,13 @@ class JsonSchemaProxyHandler {
} }
} }
if (type === 'object') { switch (type) {
case 'object':
value = JsonSchemaProxyHandler.populateObjectDefaults(value, schema); value = JsonSchemaProxyHandler.populateObjectDefaults(value, schema);
break;
case 'array':
value = JsonSchemaProxyHandler.populateArrayDefaults(value, schema);
break;
} }
return value; return value;
@ -384,6 +389,16 @@ class JsonSchemaProxyHandler {
return value; 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 { class JsonSchema {