Improve support for array schemas

This commit is contained in:
toasted-nutbread 2020-01-26 12:34:27 -05:00
parent a844698f15
commit 980a1ddf74

View File

@ -149,7 +149,23 @@ class JsonSchemaProxyHandler {
case 'array': case 'array':
{ {
const items = schema.items; 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: default:
return null; return null;
@ -322,6 +338,18 @@ class JsonSchemaProxyHandler {
return 'Array length too long'; 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; return null;
} }