Skip to content

Commit

Permalink
Fix an issue with example generator when array is too large (#46)
Browse files Browse the repository at this point in the history
* fix issue with example generator when array is too large

* reformat code
  • Loading branch information
wing328 authored May 15, 2018
1 parent 70e9e2f commit 803821e
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 803821e

Please # to comment.