#2503: fix out-of-memory issue with nested objects with arrays with maxItems set by limiting to max. 5 example items (#2536)

This commit is contained in:
Esteban Marin 2019-04-01 20:01:09 +02:00 committed by Jim Schubert
parent b55cdfbe53
commit ec42aca438

View File

@ -232,16 +232,8 @@ public class ExampleGenerator {
Schema innerType = ((ArraySchema) property).getItems();
if (innerType != null) {
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
if (arrayLength == Integer.MAX_VALUE) {
// swagger-jersey2-jaxrs generated spec may contain maxItem = 2147483647
// semantically this means there is no upper limit
// treating this as if the property was not present at all
LOGGER.warn("The max items allowed in property {} of {} equals Integer.MAX_VALUE. Treating this as if no max items has been specified.", property, arrayLength);
arrayLength = 2;
} else if (arrayLength > 1024) {
LOGGER.warn("The max items allowed in property {} is too large ({} items), restricting it to 1024 items", property, arrayLength);
arrayLength = 1024;
}
// avoid memory issues by limiting to max. 5 items
arrayLength = Math.min(arrayLength, 5);
Object[] objectProperties = new Object[arrayLength];
Object objProperty = resolvePropertyToExample(propertyName, mediaType, innerType, processedModels);
for (int i = 0; i < arrayLength; i++) {