Fix schema defaults not applying to arrays
This commit is contained in:
parent
e2a4a46e60
commit
bbace4c93b
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user