From 803821e210865cde96cf6c31300eb7e03afc667a Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 15 May 2018 23:08:37 +0800 Subject: [PATCH] Fix an issue with example generator when array is too large (#46) * fix issue with example generator when array is too large * reformat code --- .../openapitools/codegen/examples/ExampleGenerator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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++) {