mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
Fix an issue with example generator when array is too large (#46)
* fix issue with example generator when array is too large * reformat code
This commit is contained in:
parent
70e9e2fb7e
commit
803821e210
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.examples;
|
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.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
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.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -191,6 +191,10 @@ public class ExampleGenerator {
|
|||||||
Schema innerType = ((ArraySchema) property).getItems();
|
Schema innerType = ((ArraySchema) property).getItems();
|
||||||
if (innerType != null) {
|
if (innerType != null) {
|
||||||
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
|
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[] objectProperties = new Object[arrayLength];
|
||||||
Object objProperty = resolvePropertyToExample(propertyName, mediaType, innerType, processedModels);
|
Object objProperty = resolvePropertyToExample(propertyName, mediaType, innerType, processedModels);
|
||||||
for (int i = 0; i < arrayLength; i++) {
|
for (int i = 0; i < arrayLength; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user