mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 06:00:52 +00:00
#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:
parent
b55cdfbe53
commit
ec42aca438
@ -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++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user