diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java index cfebef4eb6a2..30472ba30bb9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java @@ -17,10 +17,10 @@ package org.openapitools.codegen.examples; +import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.Schema; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.core.util.Json; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; @@ -191,6 +191,10 @@ private Object resolvePropertyToExample(String propertyName, String mediaType, S Schema innerType = ((ArraySchema) property).getItems(); if (innerType != null) { int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems(); + if (arrayLength > 1024) { + LOGGER.warn("The max items allowed in property {} is too large ({} items), restricting it to 1024 items", property, arrayLength); + arrayLength = 1024; + } Object[] objectProperties = new Object[arrayLength]; Object objProperty = resolvePropertyToExample(propertyName, mediaType, innerType, processedModels); for (int i = 0; i < arrayLength; i++) {