diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index 6e115b043d85..ad33493416cd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -18,9 +18,7 @@ package org.openapitools.codegen.languages; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -87,7 +85,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code private final Logger LOGGER = LoggerFactory.getLogger(AbstractJavaCodegen.class); private static final String ARTIFACT_VERSION_DEFAULT_VALUE = "1.0.0"; private static final ZoneId UTC = ZoneId.of("UTC"); - public static final String DEFAULT_LIBRARY = ""; public static final String DATE_LIBRARY = "dateLibrary"; public static final String SUPPORT_ASYNC = "supportAsync"; @@ -1442,7 +1439,17 @@ public String toArrayDefaultValue(CodegenProperty cp, Schema schema) { @Override public String toDefaultValue(CodegenProperty cp, Schema schema) { - schema = ModelUtils.getReferencedSchema(this.openAPI, schema); + Schema originalSchema = schema; + Schema resolvedSchema = ModelUtils.getReferencedSchema(this.openAPI, schema); + if (hasOptionalNullableExplicitNullDefault(cp, originalSchema, resolvedSchema)) { + return null; + } + String complexDefault = renderComplexDefaultValue(cp, originalSchema, resolvedSchema); + if (complexDefault != null) { + return complexDefault; + } + + schema = resolvedSchema; if (ModelUtils.isArraySchema(schema)) { if (defaultToEmptyContainer) { // if default to empty container option is set, respect the default values provided in the spec @@ -1564,7 +1571,7 @@ public String toDefaultValue(CodegenProperty cp, Schema schema) { return null; } else if (ModelUtils.isObjectSchema(schema)) { if (schema.getDefault() != null) { - return toObjectDefaultValue(cp, schema.getDefault(), schema.getProperties()); + return renderComplexDefaultValue(cp, schema, schema); } return null; } else if (ModelUtils.isComposedSchema(schema)) { @@ -1576,11 +1583,11 @@ public String toDefaultValue(CodegenProperty cp, Schema schema) { // default (e.g. `{"one":"one"}`) as Java, which does not compile (see #23795). Map propertySchemas = getComposedSchemaProperties(schema); if (!propertySchemas.isEmpty()) { - return toObjectDefaultValue(cp, schema.getDefault(), propertySchemas); + return renderComplexDefaultValue(cp, schema, schema); } // No object properties resolved: the composition wraps a non-object, e.g. an `allOf` // to an enum or scalar (`allOf: [{$ref: '#/.../CurrencyCode'}]` + sibling `default`). - // There is nothing to build via toObjectDefaultValue, so defer to the base behavior, + // There is nothing to build via the complex default renderer, so defer to the base behavior, // which emits the raw default for later enum var-name / scalar conversion. Returning // null here dropped the default and regressed enum defaults (see #24384). return super.toDefaultValue(schema); @@ -1591,102 +1598,33 @@ public String toDefaultValue(CodegenProperty cp, Schema schema) { return super.toDefaultValue(schema); } - /** - * Renders the default value of an object-typed property as a Java fluent builder expression, e.g. - * {@code new Pet().name("doggie").id(1l)}. Only scalar (value node) default properties for which a - * matching property schema is known are rendered; nested objects are skipped. - * - * @param cp the codegen property carrying the target Java type ({@code datatypeWithEnum}) - * @param defaultValue the raw default value from the schema (a {@code Map}/{@code ObjectNode}) - * @param propertySchemas the resolved property schemas used to type each default entry - * @return the Java expression, or {@code null} if it cannot be resolved - */ - private String toObjectDefaultValue(CodegenProperty cp, Object defaultValue, Map propertySchemas) { - try { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("new " + cp.datatypeWithEnum + "()"); - if (propertySchemas != null) { - // With `parseOptions.setResolve(true)`, objects with 1 key-value pair are LinkedHashMap and objects with more than 1 are ObjectNode - // When not set, objects of any size are ObjectNode - ObjectMapper objectMapper = new ObjectMapper(); - ObjectNode objectNode; - if(!(defaultValue instanceof ObjectNode)) { - objectNode = objectMapper.valueToTree(defaultValue); - } else { - objectNode = (ObjectNode) defaultValue; + private String renderComplexDefaultValue(CodegenProperty property, Schema schema, Schema resolvedSchema) { + JavaDefaultValueRenderer.Context context = new JavaDefaultValueRenderer.Context( + openAPI, + dateLibrary, + useOneOfInterfaces, + this::escapeText, + this::toVarName, + this::toEnumVarName, + this::fromProperty, + this::getDefaultCollectionType, + this::getComposedSchemaProperties); + return new JavaDefaultValueRenderer(context).render(property, schema, resolvedSchema); + } - } - Set> defaultProperties = objectNode.properties(); - for (Map.Entry defaultProperty : defaultProperties) { - String key = defaultProperty.getKey(); - JsonNode value = defaultProperty.getValue(); - Schema propertySchema = propertySchemas.get(key); - if (!value.isValueNode() || propertySchema == null) { //Skip complex objects for now - continue; - } + private boolean hasOptionalNullableExplicitNullDefault(CodegenProperty property, Schema originalSchema, + Schema resolvedSchema) { + return openApiNullable && property != null && !property.required && property.isNullable + && isExplicitNullDefault(originalSchema, resolvedSchema); + } - String defaultPropertyExpression = null; - if(ModelUtils.isEnumSchema(ModelUtils.getReferencedSchema(this.openAPI, propertySchema))) { - // Enum-typed property: render the enum constant (e.g. `OutputFormat.OrderEnum.SIMILARITY`) - // rather than a raw quoted string, which would not compile (see #24298). - CodegenProperty enumProperty = fromProperty(key, propertySchema); - String enumType = enumProperty.isEnum - // an inline enum is generated as a nested class of the containing object type - ? cp.datatypeWithEnum + "." + enumProperty.datatypeWithEnum - // a `$ref` to a named enum is a top-level type - : enumProperty.datatypeWithEnum; - defaultPropertyExpression = enumType + "." + toEnumVarName(value.asText(), enumProperty.dataType); - } else if(ModelUtils.isLongSchema(propertySchema)) { - defaultPropertyExpression = value.asText()+"l"; - } else if(ModelUtils.isIntegerSchema(propertySchema)) { - defaultPropertyExpression = value.asText(); - } else if(ModelUtils.isDoubleSchema(propertySchema)) { - defaultPropertyExpression = value.asText()+"d"; - } else if(ModelUtils.isFloatSchema(propertySchema)) { - defaultPropertyExpression = value.asText()+"f"; - } else if(ModelUtils.isNumberSchema(propertySchema)) { - defaultPropertyExpression = "new java.math.BigDecimal(\"" + value.asText() + "\")"; - } else if(ModelUtils.isURISchema(propertySchema)) { - defaultPropertyExpression = "java.net.URI.create(\"" + escapeText(value.asText()) + "\")"; - } else if(ModelUtils.isDateSchema(propertySchema)) { - if("java8".equals(getDateLibrary())) { - defaultPropertyExpression = String.format(Locale.ROOT, "java.time.LocalDate.parse(\"%s\")", value.asText()); - } - } else if(ModelUtils.isDateTimeSchema(propertySchema)) { - if("java8".equals(getDateLibrary())) { - defaultPropertyExpression = String.format(Locale.ROOT, "java.time.OffsetDateTime.parse(\"%s\", %s)", - value.asText(), - "java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(java.time.ZoneId.systemDefault())"); - } - } else if(ModelUtils.isTimeLocalSchema(propertySchema)) { - if("java8".equals(getDateLibrary())) { - defaultPropertyExpression = String.format(Locale.ROOT, "java.time.LocalTime.parse(\"%s\")", value.asText()); - } - } else if(ModelUtils.isDateTimeLocalSchema(propertySchema)) { - if("java8".equals(getDateLibrary())) { - defaultPropertyExpression = String.format(Locale.ROOT, "java.time.LocalDateTime.parse(\"%s\")", value.asText()); - } - } else if(ModelUtils.isUUIDSchema(propertySchema)) { - defaultPropertyExpression = "java.util.UUID.fromString(\"" + value.asText() + "\")"; - } else if(ModelUtils.isStringSchema(propertySchema)) { - defaultPropertyExpression = "\"" + value.asText() + "\""; - } else if(ModelUtils.isBooleanSchema(propertySchema)) { - defaultPropertyExpression = value.asText(); - } - if(defaultPropertyExpression != null) { - stringBuilder -// .append(System.lineSeparator()) - .append(".") - .append(toVarName(key)) - .append("(").append(defaultPropertyExpression).append(")"); - } - } - } - return stringBuilder.toString(); - } catch (ClassCastException e) { - LOGGER.error("Can't resolve default value: "+defaultValue, e); - return null; - } + private boolean isExplicitNullDefault(Schema originalSchema, Schema resolvedSchema) { + return isNullNode(originalSchema == null ? null : originalSchema.getDefault()) + || isNullNode(resolvedSchema == null ? null : resolvedSchema.getDefault()); + } + + private boolean isNullNode(Object defaultValue) { + return defaultValue instanceof JsonNode && ((JsonNode) defaultValue).isNull(); } /** @@ -1702,15 +1640,31 @@ private Map getComposedSchemaProperties(Schema schema) { if (schema.getProperties() != null) { propertySchemas.putAll(schema.getProperties()); } - if (schema.getAllOf() != null) { - for (Object member : schema.getAllOf()) { - Schema resolved = ModelUtils.getReferencedSchema(this.openAPI, (Schema) member); - if (resolved != null && resolved.getProperties() != null) { - propertySchemas.putAll(resolved.getProperties()); - } + Set visitedSchemas = Collections.newSetFromMap(new IdentityHashMap<>()); + visitedSchemas.add(schema); + addComposedSchemaProperties(propertySchemas, schema.getAllOf(), visitedSchemas); + addComposedSchemaProperties(propertySchemas, schema.getOneOf(), visitedSchemas); + addComposedSchemaProperties(propertySchemas, schema.getAnyOf(), visitedSchemas); + return propertySchemas; + } + + private void addComposedSchemaProperties(Map propertySchemas, List members, + Set visitedSchemas) { + if (members == null) { + return; + } + for (Schema member : members) { + Schema resolved = ModelUtils.getReferencedSchema(this.openAPI, member); + if (resolved == null || !visitedSchemas.add(resolved)) { + continue; } + if (resolved.getProperties() != null) { + propertySchemas.putAll(resolved.getProperties()); + } + addComposedSchemaProperties(propertySchemas, resolved.getAllOf(), visitedSchemas); + addComposedSchemaProperties(propertySchemas, resolved.getOneOf(), visitedSchemas); + addComposedSchemaProperties(propertySchemas, resolved.getAnyOf(), visitedSchemas); } - return propertySchemas; } private String getDefaultCollectionType(Schema schema) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaDefaultValueRenderer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaDefaultValueRenderer.java new file mode 100644 index 000000000000..c86d28219510 --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaDefaultValueRenderer.java @@ -0,0 +1,364 @@ +package org.openapitools.codegen.languages; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.media.Schema; +import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.utils.ModelUtils; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; + +/** + * Renders Java expressions for complex OpenAPI property defaults. + */ +public final class JavaDefaultValueRenderer { + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + private final Context context; + + public JavaDefaultValueRenderer(Context context) { + this.context = context; + } + + /** + * Renders a complex default value, or {@code null} when this renderer does not + * support the value. + * + * @param property + * codegen property + * @param schema + * original property schema + * @param resolvedSchema + * referenced property schema + * @return Java expression or {@code null} + */ + public String render(CodegenProperty property, Schema schema, Schema resolvedSchema) { + final Object defaultValue = schema != null && schema.getDefault() != null + ? schema.getDefault() + : resolvedSchema == null ? null : resolvedSchema.getDefault(); + if (defaultValue == null) { + return null; + } + + final JsonNode defaultNode = this.toJsonNode(defaultValue); + if (defaultNode == null) { + return null; + } + if (defaultNode.isNull()) { + return "null"; + } + + if (ModelUtils.isArraySchema(resolvedSchema) && defaultNode.isArray() && property != null + && property.items != null) { + return this.renderArrayDefault(property, resolvedSchema, defaultNode); + } + if (defaultNode.isValueNode() + && (ModelUtils.isByteArraySchema(resolvedSchema) || ModelUtils.isBinarySchema(resolvedSchema))) { + return this.renderDefaultScalar(property, resolvedSchema, defaultNode, null); + } + if (this.isObjectLike(resolvedSchema) && defaultNode.isObject()) { + return this.renderObjectDefault(property, resolvedSchema, defaultNode); + } + + return null; + } + + private String renderArrayDefault(CodegenProperty property, Schema schema, JsonNode defaultNode) { + if (defaultNode.isEmpty()) { + return this.context.defaultCollectionType().apply(schema, ""); + } + + final List values = new ArrayList<>(); + for (final JsonNode item : defaultNode) { + final String value = this.renderDefaultValue(property.items, schema.getItems(), item, null); + if (value == null) { + return null; + } + values.add(value); + } + return this.context.defaultCollectionType().apply(schema, this.formatDefaultValues(values)); + } + + private String formatDefaultValues(List values) { + final boolean nested = values.stream() + .anyMatch(value -> value.startsWith("new ") && value.contains("Arrays.asList(")); + if (!nested) { + return String.join(", ", values); + } + return "\n " + String.join(",\n ", values) + "\n "; + } + + private String renderDefaultValue(CodegenProperty property, Schema schema, JsonNode value, String ownerType) { + if (value == null || value.isNull()) { + return "null"; + } + + final Schema resolvedSchema = ModelUtils.getReferencedSchema(this.context.openAPI(), schema); + if (resolvedSchema == null) { + return null; + } + if (ModelUtils.isArraySchema(resolvedSchema) && value.isArray() && property != null && property.items != null) { + return this.renderArrayDefault(property, resolvedSchema, value); + } + if (this.isObjectLike(resolvedSchema) && value.isObject()) { + return this.renderObjectDefault(property, resolvedSchema, value); + } + if (ModelUtils.isMapSchema(resolvedSchema)) { + return null; + } + return this.renderDefaultScalar(property, resolvedSchema, value, ownerType); + } + + private String renderObjectDefault(CodegenProperty property, Schema schema, JsonNode defaultNode) { + if (defaultNode == null || defaultNode.isNull()) { + return "null"; + } + + Schema targetSchema = schema; + CodegenProperty targetProperty = property; + boolean needsOneOfWrapper = false; + if (ModelUtils.hasOneOf(schema)) { + final Schema selectedMember = this.firstObjectMember(schema, defaultNode); + if (selectedMember == null) { + return null; + } + targetSchema = ModelUtils.getReferencedSchema(this.context.openAPI(), selectedMember); + targetProperty = this.context.fromProperty().apply(property.baseName, selectedMember); + needsOneOfWrapper = !this.context.useOneOfInterfaces(); + } + if (targetProperty == null || targetProperty.datatypeWithEnum == null) { + return null; + } + + final Map propertySchemas = this.context.composedSchemaProperties().apply(targetSchema); + final StringBuilder expression = new StringBuilder("new ").append(targetProperty.datatypeWithEnum).append("()"); + for (final Map.Entry defaultProperty : iterable(defaultNode.fields())) { + final Schema propertySchema = propertySchemas.get(defaultProperty.getKey()); + if (propertySchema == null) { + continue; + } + final CodegenProperty nestedProperty = this.context.fromProperty().apply(defaultProperty.getKey(), + propertySchema); + final String propertyExpression = this.renderDefaultValue(nestedProperty, propertySchema, + defaultProperty.getValue(), targetProperty.datatypeWithEnum); + if (propertyExpression != null) { + expression.append(".").append(this.context.toVarName().apply(defaultProperty.getKey())).append("(") + .append(propertyExpression).append(")"); + } + } + + if (needsOneOfWrapper) { + return "new " + property.datatypeWithEnum + "(" + expression + ")"; + } + return expression.toString(); + } + + private String renderDefaultScalar(CodegenProperty property, Schema schema, JsonNode value, String ownerType) { + if (ModelUtils.isByteArraySchema(schema)) { + return "java.util.Base64.getDecoder().decode(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + if (ModelUtils.isBinarySchema(schema)) { + if (property != null && ("Resource".equals(property.datatypeWithEnum) + || "org.springframework.core.io.Resource".equals(property.datatypeWithEnum))) { + return "new org.springframework.core.io.ByteArrayResource(java.util.Base64.getDecoder().decode(\"" + + this.context.escapeText().apply(value.asText()) + "\"))"; + } + if (property != null + && ("File".equals(property.datatypeWithEnum) || "java.io.File".equals(property.datatypeWithEnum))) { + return "null"; + } + return null; + } + if (ModelUtils.isEnumSchema(schema)) { + final CodegenProperty enumProperty = property; + final String enumType = enumProperty != null && enumProperty.isEnum && ownerType != null + ? ownerType + "." + enumProperty.datatypeWithEnum + : enumProperty == null ? null : enumProperty.datatypeWithEnum; + return enumType == null + ? null + : enumType + "." + this.context.toEnumVarName().apply(value.asText(), enumProperty.dataType); + } + if (ModelUtils.isLongSchema(schema)) { + return value.asText() + "l"; + } + if (ModelUtils.isIntegerSchema(schema)) { + return value.asText(); + } + if (ModelUtils.isDoubleSchema(schema)) { + return value.asText() + "d"; + } + if (ModelUtils.isFloatSchema(schema)) { + return value.asText() + "f"; + } + if (ModelUtils.isNumberSchema(schema)) { + return "new java.math.BigDecimal(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + if (ModelUtils.isURISchema(schema)) { + return "java.net.URI.create(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + if (ModelUtils.isDateSchema(schema)) { + if (this.context.dateLibrary().startsWith("java8")) { + return "java.time.LocalDate.parse(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + if ("joda".equals(this.context.dateLibrary())) { + return "org.joda.time.LocalDate.parse(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + return null; + } + if (ModelUtils.isDateTimeSchema(schema)) { + if ("java8".equals(this.context.dateLibrary())) { + return "java.time.OffsetDateTime.parse(\"" + this.context.escapeText().apply(value.asText()) + "\", " + + "java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(java.time.ZoneId.systemDefault()))"; + } + if ("java8-localdatetime".equals(this.context.dateLibrary())) { + return "java.time.OffsetDateTime.parse(\"" + this.context.escapeText().apply(value.asText()) + + "\").toLocalDateTime()"; + } + if ("joda".equals(this.context.dateLibrary())) { + return "org.joda.time.DateTime.parse(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + return null; + } + if (ModelUtils.isTimeLocalSchema(schema) && this.context.dateLibrary().startsWith("java8")) { + return "java.time.LocalTime.parse(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + if (ModelUtils.isDateTimeLocalSchema(schema) && this.context.dateLibrary().startsWith("java8")) { + return "java.time.LocalDateTime.parse(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + if (ModelUtils.isUUIDSchema(schema)) { + return "java.util.UUID.fromString(\"" + this.context.escapeText().apply(value.asText()) + "\")"; + } + if (ModelUtils.isBooleanSchema(schema)) { + return value.asText(); + } + if (ModelUtils.isStringSchema(schema)) { + return "\"" + this.context.escapeText().apply(value.asText()) + "\""; + } + return null; + } + + private Schema firstObjectMember(Schema schema, JsonNode defaultNode) { + final List members = schema.getOneOf() != null ? schema.getOneOf() : schema.getAnyOf(); + if (members == null) { + return null; + } + Schema firstMember = null; + for (final Schema member : members) { + final Schema resolved = ModelUtils.getReferencedSchema(this.context.openAPI(), member); + if (this.isObjectLike(resolved)) { + if (firstMember == null) { + firstMember = member; + } + if (defaultNode != null && defaultNode.isObject() + && this.matchesDefaultProperties(resolved, defaultNode)) { + return member; + } + } + } + return firstMember; + } + + private boolean matchesDefaultProperties(Schema schema, JsonNode defaultNode) { + final Map propertySchemas = this.context.composedSchemaProperties().apply(schema); + final Iterator propertyNames = defaultNode.fieldNames(); + while (propertyNames.hasNext()) { + if (!propertySchemas.containsKey(propertyNames.next())) { + return false; + } + } + return true; + } + + private boolean isObjectLike(Schema schema) { + return ModelUtils.isObjectSchema(schema) || ModelUtils.isComposedSchema(schema); + } + + private JsonNode toJsonNode(Object value) { + if (value instanceof JsonNode) { + return (JsonNode) value; + } + if (value instanceof java.time.temporal.TemporalAccessor) { + return OBJECT_MAPPER.getNodeFactory().textNode(value.toString()); + } + try { + return OBJECT_MAPPER.valueToTree(value); + } catch (final IllegalArgumentException e) { + return null; + } + } + + private static Iterable iterable(Iterator iterator) { + return () -> iterator; + } + + public static final class Context { + private final OpenAPI openAPI; + private final String dateLibrary; + private final boolean useOneOfInterfaces; + private final Function escapeText; + private final Function toVarName; + private final BiFunction toEnumVarName; + private final BiFunction fromProperty; + private final BiFunction defaultCollectionType; + private final Function> composedSchemaProperties; + + public Context(OpenAPI openAPI, String dateLibrary, boolean useOneOfInterfaces, + Function escapeText, Function toVarName, + BiFunction toEnumVarName, + BiFunction fromProperty, + BiFunction defaultCollectionType, + Function> composedSchemaProperties) { + this.openAPI = openAPI; + this.dateLibrary = dateLibrary; + this.useOneOfInterfaces = useOneOfInterfaces; + this.escapeText = escapeText; + this.toVarName = toVarName; + this.toEnumVarName = toEnumVarName; + this.fromProperty = fromProperty; + this.defaultCollectionType = defaultCollectionType; + this.composedSchemaProperties = composedSchemaProperties; + } + + private OpenAPI openAPI() { + return this.openAPI; + } + + private String dateLibrary() { + return this.dateLibrary; + } + + private boolean useOneOfInterfaces() { + return this.useOneOfInterfaces; + } + + private Function escapeText() { + return this.escapeText; + } + + private Function toVarName() { + return this.toVarName; + } + + private BiFunction toEnumVarName() { + return this.toEnumVarName; + } + + private BiFunction fromProperty() { + return this.fromProperty; + } + + private BiFunction defaultCollectionType() { + return this.defaultCollectionType; + } + + private Function> composedSchemaProperties() { + return this.composedSchemaProperties; + } + } +} diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java index 77e694a2711f..6d52479ec776 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java @@ -27,6 +27,7 @@ import org.openapitools.codegen.model.ModelMap; import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationsMap; +import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -112,6 +113,29 @@ public JavaPlayFrameworkCodegen() { cliOptions.add(createBooleanCliWithDefault(SUPPORT_ASYNC, "Support Async operations", supportAsync)); } + @Override + public String toDefaultValue(CodegenProperty property, Schema schema) { + Schema resolvedSchema = ModelUtils.getReferencedSchema(this.openAPI, schema); + if (property != null && !property.required + && (ModelUtils.isMapSchema(schema) || ModelUtils.isMapSchema(resolvedSchema))) { + boolean hasExplicitDefault = schema.getDefault() != null + || resolvedSchema != null && resolvedSchema.getDefault() != null; + if (hasExplicitDefault) { + // Map defaults are not rendered as Java expressions by the base generator. Do not emit + // the raw map value or replace its contents with an empty map. + return null; + } + } + if (property != null && !property.required + && (ModelUtils.isArraySchema(schema) || ModelUtils.isMapSchema(schema) + || ModelUtils.isArraySchema(resolvedSchema) || ModelUtils.isMapSchema(resolvedSchema)) + && schema.getDefault() == null && (resolvedSchema == null || resolvedSchema.getDefault() == null) + && !defaultToEmptyContainer) { + return null; + } + return super.toDefaultValue(property, schema); + } + @Override public CodegenType getTag() { return CodegenType.SERVER; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/pojo.mustache index dd8bdc7d0371..530c033c2ada 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/pojo.mustache @@ -126,7 +126,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -137,7 +137,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -149,7 +149,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -161,7 +161,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{^vendorExtensions.x-is-jackson-optional-nullable}} {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } {{/required}} this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache index 4c6f9bf697e4..107b0fe6d6b7 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache @@ -136,7 +136,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -147,7 +147,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -159,7 +159,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -170,7 +170,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache index 4c6f9bf697e4..8d84786642dc 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache @@ -70,7 +70,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{#deprecated}} @Deprecated {{/deprecated}} - private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined(); + private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}}; {{/isContainer}} {{^isContainer}} {{#deprecated}} @@ -136,7 +136,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -147,7 +147,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -159,7 +159,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -170,7 +170,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pojo.mustache index 290136042bda..fb50f5c091fa 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pojo.mustache @@ -132,7 +132,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#ve public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -142,7 +142,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#ve public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache index 7994cc2d1181..9efc986c5c65 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache @@ -127,7 +127,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -138,7 +138,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -150,7 +150,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -161,7 +161,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache index 0224febae000..07df46b7d032 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache @@ -123,7 +123,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -133,7 +133,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/pojo.mustache index c720bbd89223..9ecd618ac896 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/pojo.mustache @@ -152,7 +152,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -163,7 +163,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -175,7 +175,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -187,7 +187,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v {{^vendorExtensions.x-is-jackson-optional-nullable}} {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } {{/required}} this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pojo.mustache index b45c6b5007b1..8c438877253d 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pojo.mustache @@ -152,7 +152,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -163,7 +163,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -175,7 +175,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -187,7 +187,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{^vendorExtensions.x-is-jackson-optional-nullable}} {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } {{/required}} this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/pojo.mustache index 95d6986ff4c6..6170edc45cbd 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/pojo.mustache @@ -152,7 +152,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -163,7 +163,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -175,7 +175,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -187,7 +187,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v {{^vendorExtensions.x-is-jackson-optional-nullable}} {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } {{/required}} this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/Java/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/pojo.mustache index 14d2228aa97d..b2e3ae6073f0 100644 --- a/modules/openapi-generator/src/main/resources/Java/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/pojo.mustache @@ -155,7 +155,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -166,7 +166,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -178,7 +178,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -190,7 +190,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{^vendorExtensions.x-is-jackson-optional-nullable}} {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } {{/required}} this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache index 887c728178ed..8c3150905786 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache @@ -52,7 +52,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -63,7 +63,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pojo.mustache index b44a4068f4d0..f0b367ca3e62 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -171,7 +171,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensi public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent()) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } this.{{name}}.get().add({{name}}Item); return this; @@ -187,7 +187,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensi public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent()) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } this.{{name}}.get().put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/libraries/jersey3/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/libraries/jersey3/pojo.mustache index bd0c341e726d..a2549e542422 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/libraries/jersey3/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/libraries/jersey3/pojo.mustache @@ -50,7 +50,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -60,7 +60,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/pojo.mustache index b17a9ee3d8f8..c2023d51c857 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/pojo.mustache @@ -50,7 +50,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -60,7 +60,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache index 759d8d083cb3..6e4659ee27ca 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache @@ -72,12 +72,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#v @Deprecated {{/deprecated}} {{#vendorExtensions.x-is-jackson-optional-nullable}} - {{#isContainer}} - private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined(); - {{/isContainer}} - {{^isContainer}} private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}}; - {{/isContainer}} {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} private {{#useJspecify}}{{>nullable_var_annotations}}{{/useJspecify}}{{>nullableDatatypeWithEnum}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}; @@ -208,7 +203,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#v public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -219,7 +214,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#v {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); @@ -262,7 +257,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#v public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent() || this.{{name}}.get() == null) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -273,7 +268,7 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#v {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/JavaPlayFramework/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaPlayFramework/pojo.mustache index 75c441b76a75..01726235706c 100644 --- a/modules/openapi-generator/src/main/resources/JavaPlayFramework/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaPlayFramework/pojo.mustache @@ -38,7 +38,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens {{#useBeanValidation}} {{>beanValidation}}{{! prevent indent}} {{/useBeanValidation}} - private {{{datatypeWithEnum}}} {{name}}{{#required}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{^required}} = null{{/required}}; + private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}; {{/isContainer}} {{^isContainer}} {{#useBeanValidation}} @@ -57,7 +57,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -67,7 +67,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache index 99dc720a635d..f90ff34b3934 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache @@ -168,13 +168,13 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}} public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#openApiNullable}} if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent() || this.{{name}}.get() == null{{/isNullable}}) { - this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}}; + this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{#isNullable}}){{/isNullable}}; } this.{{name}}{{#isNullable}}.get(){{/isNullable}}.add({{name}}Item); {{/openApiNullable}} {{^openApiNullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); {{/openApiNullable}} @@ -186,13 +186,13 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}} public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#openApiNullable}} if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent() || this.{{name}}.get() == null{{/isNullable}}) { - this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}}; + this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{#isNullable}}){{/isNullable}}; } this.{{name}}{{#isNullable}}.get(){{/isNullable}}.put(key, {{name}}Item); {{/openApiNullable}} {{^openApiNullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(); } this.{{name}}.put(key, {{name}}Item); {{/openApiNullable}} diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/pojo.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/pojo.mustache index ad3b59815a83..58dccb6cfc85 100644 --- a/modules/openapi-generator/src/main/resources/java-camel-server/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/java-camel-server/pojo.mustache @@ -179,13 +179,13 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#openApiNullable}} if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) { - this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}}; + this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{#isNullable}}){{/isNullable}}; } this.{{name}}{{#isNullable}}.get(){{/isNullable}}.add({{name}}Item); {{/openApiNullable}} {{^openApiNullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); {{/openApiNullable}} @@ -197,13 +197,13 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#openApiNullable}} if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) { - this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}}; + this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{#isNullable}}){{/isNullable}}; } this.{{name}}{{#isNullable}}.get(){{/isNullable}}.put(key, {{name}}Item); {{/openApiNullable}} {{^openApiNullable}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(); } this.{{name}}.put(key, {{name}}Item); {{/openApiNullable}} diff --git a/modules/openapi-generator/src/main/resources/java-micronaut/common/model/pojo.mustache b/modules/openapi-generator/src/main/resources/java-micronaut/common/model/pojo.mustache index 472ea9b71ac3..2879a5f30f47 100644 --- a/modules/openapi-generator/src/main/resources/java-micronaut/common/model/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/java-micronaut/common/model/pojo.mustache @@ -110,7 +110,7 @@ Declare the class with extends and implements public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent()) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>()); } try { this.{{name}}.get().add({{name}}Item); @@ -122,7 +122,7 @@ Declare the class with extends and implements {{^vendorExtensions.x-is-jackson-optional-nullable}} {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } {{/required}} this.{{name}}.add({{name}}Item); @@ -135,7 +135,7 @@ Declare the class with extends and implements public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent()) { - this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of(new HashMap<>()); } try { this.{{name}}.get().put(key, {{name}}Item); @@ -147,7 +147,7 @@ Declare the class with extends and implements {{^vendorExtensions.x-is-jackson-optional-nullable}} {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; + this.{{name}} = new HashMap<>(); } {{/required}} this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/java-msf4j-server/pojo.mustache b/modules/openapi-generator/src/main/resources/java-msf4j-server/pojo.mustache index 052df3b5a26e..5b5cf32dab12 100644 --- a/modules/openapi-generator/src/main/resources/java-msf4j-server/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/java-msf4j-server/pojo.mustache @@ -42,7 +42,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } {{/required}} this.{{name}}.add({{name}}Item); @@ -54,7 +54,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{^required}} if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}; + this.{{name}} = new HashMap<>(); } {{/required}} this.{{name}}.put(key, {{name}}Item); diff --git a/modules/openapi-generator/src/main/resources/java-pkmst/pojo.mustache b/modules/openapi-generator/src/main/resources/java-pkmst/pojo.mustache index 3b1734420fc3..441dee6845d5 100644 --- a/modules/openapi-generator/src/main/resources/java-pkmst/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/java-pkmst/pojo.mustache @@ -52,7 +52,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; + this.{{name}} = new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(); } this.{{name}}.add({{name}}Item); return this; @@ -62,7 +62,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { if (this.{{name}} == null) { - this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); + this.{{name}} = new HashMap<>(); } this.{{name}}.put(key, {{name}}Item); return this; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java index 07718b95c148..07f6e461de48 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java @@ -652,6 +652,95 @@ public void toDefaultValueForComposedObjectWithDefaultTest() { Assert.assertEquals(rendered, "new " + cp.datatypeWithEnum + "().one(\"one\").two(\"two\")"); } + @Test + public void toDefaultValueForComposedOneOfSelectsMatchingMemberTest() { + ObjectSchema first = new ObjectSchema(); + first.addProperty("firstOnly", new StringSchema()); + ObjectSchema later = new ObjectSchema(); + later.addProperty("laterOnly", new StringSchema()); + OpenAPI openAPI = new OpenAPI().components(new Components() + .addSchemas("First", first) + .addSchemas("Later", later)); + codegen.setOpenAPI(openAPI); + + ComposedSchema composed = new ComposedSchema(); + composed.addOneOfItem(new Schema<>().$ref("#/components/schemas/First")); + composed.addOneOfItem(new Schema<>().$ref("#/components/schemas/Later")); + composed.setDefault(Map.of("laterOnly", "later")); + + CodegenProperty cp = codegen.fromProperty("choice", composed); + String rendered = codegen.toDefaultValue(cp, composed); + + Assert.assertTrue(rendered.contains("new Later().laterOnly(\"later\")"), rendered); + Assert.assertFalse(rendered.contains("new First()"), rendered); + } + + @Test + public void toDefaultValueForRecursiveComposedSchemaDoesNotOverflow() { + ComposedSchema recursive = new ComposedSchema(); + recursive.addProperty("name", new StringSchema()); + recursive.addAllOfItem(new Schema<>().$ref("#/components/schemas/Recursive")); + recursive.setDefault(Map.of("name", "recursive")); + codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("Recursive", recursive))); + + CodegenProperty property = codegen.fromProperty("recursive", recursive); + String rendered = codegen.toDefaultValue(property, recursive); + + Assert.assertEquals(rendered, "new " + property.datatypeWithEnum + "().name(\"recursive\")"); + } + + @Test + public void toDefaultValueForNestedDatesUsesConfiguredDateLibraryTest() { + ObjectSchema nested = new ObjectSchema(); + nested.addProperty("date", new DateSchema()); + nested.addProperty("dateTime", new DateTimeSchema()); + StringSchema timeLocal = new StringSchema(); + timeLocal.setFormat("time-local"); + nested.addProperty("timeLocal", timeLocal); + StringSchema dateTimeLocal = new StringSchema(); + dateTimeLocal.setFormat("date-time-local"); + nested.addProperty("dateTimeLocal", dateTimeLocal); + Map defaultValue = new LinkedHashMap<>(); + defaultValue.put("date", "2019-02-15"); + defaultValue.put("dateTime", "1984-12-19T03:39:57-08:00"); + defaultValue.put("timeLocal", "10:15:30"); + defaultValue.put("dateTimeLocal", "2007-12-03T10:15:30"); + nested.setDefault(defaultValue); + codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("Nested", nested))); + + codegen.setDateLibrary("java8"); + CodegenProperty java8Property = codegen.fromProperty("nested", nested); + String java8Rendered = codegen.toDefaultValue(java8Property, nested); + Assert.assertTrue(java8Rendered.contains(".date(java.time.LocalDate.parse(\"2019-02-15\"))"), java8Rendered); + Assert.assertTrue(java8Rendered.contains(".dateTime(java.time.OffsetDateTime.parse(\"1984-12-19T03:39:57-08:00\""), + java8Rendered); + Assert.assertTrue(java8Rendered.contains(".timeLocal(java.time.LocalTime.parse(\"10:15:30\"))"), java8Rendered); + Assert.assertTrue(java8Rendered.contains(".dateTimeLocal(java.time.LocalDateTime.parse(\"2007-12-03T10:15:30\"))"), + java8Rendered); + + codegen.setDateLibrary("java8-localdatetime"); + CodegenProperty localDateTimeProperty = codegen.fromProperty("nested", nested); + String localDateTimeRendered = codegen.toDefaultValue(localDateTimeProperty, nested); + Assert.assertTrue(localDateTimeRendered.contains(".dateTime(java.time.OffsetDateTime.parse(\"1984-12-19T03:39:57-08:00\").toLocalDateTime())"), + localDateTimeRendered); + + codegen.setDateLibrary("joda"); + CodegenProperty jodaProperty = codegen.fromProperty("nested", nested); + String jodaRendered = codegen.toDefaultValue(jodaProperty, nested); + Assert.assertTrue(jodaRendered.contains(".date(org.joda.time.LocalDate.parse(\"2019-02-15\"))"), jodaRendered); + Assert.assertTrue(jodaRendered.contains(".dateTime(org.joda.time.DateTime.parse(\"1984-12-19T03:39:57-08:00\"))"), + jodaRendered); + Assert.assertFalse(jodaRendered.contains("java.time"), jodaRendered); + + codegen.setDateLibrary("legacy"); + CodegenProperty legacyProperty = codegen.fromProperty("nested", nested); + String legacyRendered = codegen.toDefaultValue(legacyProperty, nested); + Assert.assertFalse(legacyRendered.contains("java.time"), legacyRendered); + Assert.assertFalse(legacyRendered.contains("org.joda.time"), legacyRendered); + Assert.assertEquals(legacyRendered, "new " + legacyProperty.datatypeWithEnum + + "().timeLocal(\"10:15:30\").dateTimeLocal(\"2007-12-03T10:15:30\")"); + } + @Test public void toDefaultValueForObjectWithEnumPropertyDefaultTest() { // An object default that contains an enum property must render the enum constant diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index 43f9b8d6ec18..33e78b1e4847 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -511,6 +511,83 @@ public void testGeneratePing() { .contains("public class DefaultApi"); } + @Test + public void testComplexDefaultsGenerateValidJava() { + final Path output = newTempFolder(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName(JAVA_GENERATOR) + .setLibrary(JavaClientCodegen.RESTTEMPLATE) + .setInputSpec("src/test/resources/bugs/issue_24993.yaml") + .setOutputDir(output.toString().replace("\\", "/")); + + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + validateJavaSourceFiles(files); + assertThat(output.resolve("src/main/java/org/openapitools/client/model/ComplexDefaults.java")) + .content() + .contains( + "new ArrayList<>(Arrays.asList(new DefaultObject().name(\"first\").count(1).status(Status.ACTIVE), " + + "new DefaultObject().name(\"second\").count(2).status(Status.INACTIVE)))", + "new ArrayList<>(Arrays.asList(10l, 20l))", + "new DefaultObject().name(\"all-of\").count(3).status(Status.ACTIVE)", + "new ComplexDefaultsObjectOneOf(new DefaultObject().name(\"one-of\").count(4).status(Status.ACTIVE))", + "new ComplexDefaultsObjectAnyOf().name(\"any-of\").count(5).status(Status.INACTIVE)", + "java.util.Base64.getDecoder().decode(\"ZGVmYXVsdA==\")", + "private File binaryValue = null;") + .containsPattern("new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "\\\"h1\\\"\\s*,\\s*\\\"Header 1\\\"\\s*\\)\\s*\\)\\s*,\\s*" + + "new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "\\\"h2\\\"\\s*,\\s*\\\"Header 2\\\"\\s*\\)\\s*\\)\\s*\\)\\s*\\)") + .doesNotContain("Arrays.asList(, )", "= {", "[B@"); + } + + @Test + public void testNestedArrayDefaultDoesNotSeedAddItemWithDefault() { + final Map files = generateFromContract( + "src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml", + JavaClientCodegen.OKHTTP_GSON); + + assertThat(files.get("NestedArrayWithDefaultValues.java").toPath()).content() + .containsPattern("private\\s+List\\s*<\\s*List\\s*<\\s*String\\s*>\\s*>\\s+nestedArray\\s*=\\s*" + + "new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "\\\"h1\\\"\\s*,\\s*\\\"Header 1\\\"\\s*\\)\\s*\\)\\s*,") + .containsPattern("if\\s*\\(\\s*this\\.nestedArray\\s*==\\s*null\\s*\\)\\s*\\{\\s*" + + "this\\.nestedArray\\s*=\\s*new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*\\)\\s*;") + .doesNotContainPattern("this\\.nestedArray\\s*=\\s*new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\("); + } + + @Test + public void testJersey3NullableContainerDefaultIsDeclared() { + final Map files = generateFromContract( + "src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml", + "jersey3", + Map.of(JavaClientCodegen.OPENAPI_NULLABLE, true)); + + validateJavaSourceFiles(List.copyOf(files.values())); + assertThat(files.get("ContainerDefaultValue.java").toPath()).content() + .contains("private JsonNullable> nullableArrayWithDefault = " + + "JsonNullable.>of(new ArrayList<>(Arrays.asList(\"foo\", \"bar\")));" + ) + .contains("this.nullableArrayWithDefault = JsonNullable.>of(new ArrayList<>());") + .doesNotContain("this.nullableArrayWithDefault = JsonNullable.>of(new ArrayList<>(Arrays.asList("); + } + + @Test + public void testJersey3NullableNullDefaultRemainsUndefined() { + final Map files = generateFromContract( + "src/test/resources/bugs/issue_24993.yaml", + "jersey3", + Map.of(JavaClientCodegen.OPENAPI_NULLABLE, true)); + + assertThat(files.get("ComplexDefaults.java").toPath()).content() + .containsPattern("nullableObject\\s*=\\s*JsonNullable\\.<[^>]+>undefined\\(\\);") + .containsPattern("nullableArrayWithNullDefault\\s*=\\s*JsonNullable\\.>undefined\\(\\);") + .doesNotContain("JsonNullable.of(null)") + .doesNotContain("JsonNullable.>of(null)"); + } + @Test public void testGeneratePingSomeObj() { final Path output = newTempFolder(); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java index bcdb5f19896c..879132b927e2 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java @@ -4,6 +4,7 @@ import io.swagger.parser.OpenAPIParser; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.parser.core.models.ParseOptions; import org.openapitools.codegen.*; @@ -1669,6 +1670,63 @@ public void testGenerateJsonNullableListFieldsHelperMethodReferences_issue23251( output.deleteOnExit(); } + @Test + public void testJsonNullableContainerDefaultIsDeclared() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml", + null, new ParseOptions()).getOpenAPI(); + Schema nullableArray = (Schema) openAPI.getComponents().getSchemas().get("ContainerDefaultValue") + .getProperties().get("nullable_array_with_default"); + nullableArray.addExtension("x-is-jackson-optional-nullable", true); + + codegen.setOutputDir(output.getAbsolutePath()); + codegen.setOpenApiNullable(true); + codegen.additionalProperties().put(CodegenConstants.OPENAPI_NULLABLE, "true"); + + ClientOptInput input = new ClientOptInput().openAPI(openAPI).config(codegen); + + List files = new DefaultGenerator().opts(input).generate(); + validateJavaSourceFiles(files); + + Path model = output.toPath().resolve("src/gen/java/org/openapitools/model/ContainerDefaultValue.java"); + assertFileContains(model, + "private JsonNullable> nullableArrayWithDefault = " + + "JsonNullable.>of(new ArrayList<>(Arrays.asList(\"foo\", \"bar\")));", + "this.nullableArrayWithDefault = JsonNullable.>of(new ArrayList<>());"); + assertFileNotContains(model, + "this.nullableArrayWithDefault = JsonNullable.>of(new ArrayList<>(Arrays.asList("); + } + + @Test + public void testJsonNullableExplicitNullContainerDefaultRemainsUndefined() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/bugs/issue_24993.yaml", null, new ParseOptions()).getOpenAPI(); + Schema nullableArray = (Schema) openAPI.getComponents().getSchemas().get("ComplexDefaults") + .getProperties().get("nullableArrayWithNullDefault"); + nullableArray.addExtension("x-is-jackson-optional-nullable", true); + + codegen.setOutputDir(output.getAbsolutePath()); + codegen.setOpenApiNullable(true); + codegen.additionalProperties().put(CodegenConstants.OPENAPI_NULLABLE, "true"); + + ClientOptInput input = new ClientOptInput().openAPI(openAPI).config(codegen); + + List files = new DefaultGenerator().opts(input).generate(); + validateJavaSourceFiles(files); + + Path model = output.toPath().resolve("src/gen/java/org/openapitools/model/ComplexDefaults.java"); + assertFileContains(model, + "private JsonNullable> nullableArrayWithNullDefault = " + + "JsonNullable.>undefined();"); + assertFileNotContains(model, "JsonNullable.>of(null)"); + } + /** * OpenAPI {@code deprecated} should surface as {@code @Deprecated} in jaxrs-spec output. */ diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/play/JavaPlayFrameworkCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/play/JavaPlayFrameworkCodegenTest.java index ff8cbcca8c1c..78efaa838112 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/play/JavaPlayFrameworkCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/play/JavaPlayFrameworkCodegenTest.java @@ -19,6 +19,9 @@ import io.swagger.parser.OpenAPIParser; import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.media.MapSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import io.swagger.v3.parser.core.models.ParseOptions; import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.CodegenConstants; @@ -30,6 +33,8 @@ import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; public class JavaPlayFrameworkCodegenTest { @@ -115,4 +120,94 @@ public void testExtraAnnotations() throws Exception { TestUtils.assertExtraAnnotationFiles(outputPath + "/app/apimodels"); } + + @Test + public void testOptionalContainerDefaultIsGenerated() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml", + null, new ParseOptions()).getOpenAPI(); + + JavaPlayFrameworkCodegen codegen = new JavaPlayFrameworkCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); + generator.opts(input).generate(); + + Path model = output.toPath().resolve("app/apimodels/ContainerDefaultValue.java"); + TestUtils.assertValidJavaSourceCode(Files.readString(model)); + TestUtils.assertFileContains(model, + "private List nullableArrayWithDefault = new ArrayList<>(Arrays.asList(\"foo\", \"bar\"));"); + TestUtils.assertFileNotContains(model, + "this.nullableArrayWithDefault = new ArrayList<>(Arrays.asList(\"foo\", \"bar\"));"); + } + + @Test + public void testOptionalMapDefaultIsNotEmittedAsEmptyMap() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml", + null, new ParseOptions()).getOpenAPI(); + Schema container = openAPI.getComponents().getSchemas().get("ContainerDefaultValue"); + MapSchema mapWithDefault = new MapSchema(); + mapWithDefault.setAdditionalProperties(new StringSchema()); + mapWithDefault.setDefault(Map.of("foo", "bar")); + container.addProperties("mapWithDefault", mapWithDefault); + + JavaPlayFrameworkCodegen codegen = new JavaPlayFrameworkCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + + ClientOptInput input = new ClientOptInput().openAPI(openAPI).config(codegen); + DefaultGenerator generator = new DefaultGenerator(); + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); + generator.opts(input).generate(); + + Path model = output.toPath().resolve("app/apimodels/ContainerDefaultValue.java"); + TestUtils.assertFileContains(model, "private Map mapWithDefault = null;"); + TestUtils.assertFileNotContains(model, "private Map mapWithDefault = new HashMap<>()"); + TestUtils.assertFileNotContains(model, "foo=bar"); + } + + @Test + public void testOptionalContainersWithoutDefaultsRemainNull() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml", + null, new ParseOptions()).getOpenAPI(); + JavaPlayFrameworkCodegen codegen = new JavaPlayFrameworkCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + + ClientOptInput input = new ClientOptInput().openAPI(openAPI).config(codegen); + DefaultGenerator generator = new DefaultGenerator(); + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); + generator.opts(input).generate(); + + Path pet = output.toPath().resolve("app/apimodels/Pet.java"); + Path maps = output.toPath().resolve("app/apimodels/AdditionalPropertiesClass.java"); + TestUtils.assertFileContains(pet, "private List<@Valid Tag> tags = null;"); + TestUtils.assertFileContains(maps, "private Map mapString = null;"); + } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 2a6bab8cee27..ed8c0964c47e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -85,6 +85,31 @@ public void clientOptsUnicity() { .forEach((k, v) -> assertEquals(v.size(), 1, k + " is described multiple times")); } + @Test + public void testComplexDefaultsGenerateValidJava() throws IOException { + Map files = generateFromContract("src/test/resources/bugs/issue_24993.yaml", SPRING_BOOT); + + validateJavaSourceFiles(List.copyOf(files.values())); + assertThat(files).containsKey("ComplexDefaults.java"); + assertThat(files.get("ComplexDefaults.java").toPath()) + .content() + .contains( + "new ArrayList<>(Arrays.asList(new DefaultObject().name(\"first\").count(1).status(Status.ACTIVE), " + + "new DefaultObject().name(\"second\").count(2).status(Status.INACTIVE)))", + "new ArrayList<>(Arrays.asList(10l, 20l))", + "new DefaultObject().name(\"all-of\").count(3).status(Status.ACTIVE)", + "new DefaultObject().name(\"one-of\").count(4).status(Status.ACTIVE)", + "new ComplexDefaultsObjectAnyOf().name(\"any-of\").count(5).status(Status.INACTIVE)", + "java.util.Base64.getDecoder().decode(\"ZGVmYXVsdA==\")", + "private org.springframework.core.io.Resource binaryValue = new org.springframework.core.io.ByteArrayResource") + .containsPattern("new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "\\\"h1\\\"\\s*,\\s*\\\"Header 1\\\"\\s*\\)\\s*\\)\\s*,\\s*" + + "new\\s+ArrayList\\s*<\\s*>\\s*\\(\\s*Arrays\\.asList\\s*\\(\\s*" + + "\\\"h2\\\"\\s*,\\s*\\\"Header 2\\\"\\s*\\)\\s*\\)\\s*\\)\\s*\\)") + .doesNotContain("Arrays.asList(, )", "= {", "[B@"); + } + @Test public void doAnnotateDatesOnModelParameters() throws IOException { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); diff --git a/modules/openapi-generator/src/test/resources/bugs/issue_24993.yaml b/modules/openapi-generator/src/test/resources/bugs/issue_24993.yaml new file mode 100644 index 000000000000..3cf3758962d5 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/bugs/issue_24993.yaml @@ -0,0 +1,127 @@ +openapi: 3.0.3 +info: + title: Complex defaults + version: 1.0.0 +paths: + /defaults: + post: + operationId: createDefaults + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ComplexDefaults' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ComplexDefaults' +components: + schemas: + ComplexDefaults: + type: object + properties: + objectArray: + type: array + default: + - name: first + count: 1 + status: ACTIVE + - name: second + count: 2 + status: INACTIVE + items: + $ref: '#/components/schemas/DefaultObject' + nestedStringArray: + type: array + default: + - - h1 + - Header 1 + - - h2 + - Header 2 + items: + type: array + items: + type: string + nullableArrayWithNullDefault: + type: array + nullable: true + default: null + items: + type: string + longArray: + type: array + default: + - 10 + - 20 + items: + type: integer + format: int64 + objectAllOf: + allOf: + - $ref: '#/components/schemas/DefaultObject' + default: + name: all-of + count: 3 + status: ACTIVE + objectOneOf: + oneOf: + - $ref: '#/components/schemas/DefaultObject' + - $ref: '#/components/schemas/OtherDefaultObject' + default: + name: one-of + count: 4 + status: ACTIVE + objectAnyOf: + anyOf: + - $ref: '#/components/schemas/DefaultObject' + - $ref: '#/components/schemas/OtherDefaultObject' + default: + name: any-of + count: 5 + status: INACTIVE + byteValue: + type: string + format: byte + default: ZGVmYXVsdA== + binaryValue: + type: string + format: binary + default: ZGVmYXVsdA== + nullableObject: + nullable: true + allOf: + - $ref: '#/components/schemas/DefaultObject' + default: null + DefaultObject: + type: object + required: + - name + - count + - status + properties: + name: + type: string + count: + type: integer + format: int32 + status: + $ref: '#/components/schemas/Status' + OtherDefaultObject: + type: object + properties: + name: + type: string + count: + type: integer + format: int32 + status: + $ref: '#/components/schemas/Status' + Status: + type: string + enum: + - ACTIVE + - INACTIVE diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java index ad2de1a2fa1f..6959512c3b6c 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -129,7 +129,7 @@ public DefaultValue arrayStringEnumRefDefault(@javax.annotation.Nullable List(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE)); + this.arrayStringEnumRefDefault = new ArrayList<>(); } this.arrayStringEnumRefDefault.add(arrayStringEnumRefDefaultItem); return this; @@ -162,7 +162,7 @@ public DefaultValue arrayStringEnumDefault(@javax.annotation.Nullable List(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE)); + this.arrayStringEnumDefault = new ArrayList<>(); } this.arrayStringEnumDefault.add(arrayStringEnumDefaultItem); return this; @@ -195,7 +195,7 @@ public DefaultValue arrayStringDefault(@javax.annotation.Nullable List a public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) { if (this.arrayStringDefault == null) { - this.arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped")); + this.arrayStringDefault = new ArrayList<>(); } this.arrayStringDefault.add(arrayStringDefaultItem); return this; @@ -228,7 +228,7 @@ public DefaultValue arrayIntegerDefault(@javax.annotation.Nullable List public DefaultValue addArrayIntegerDefaultItem(Integer arrayIntegerDefaultItem) { if (this.arrayIntegerDefault == null) { - this.arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3)); + this.arrayIntegerDefault = new ArrayList<>(); } this.arrayIntegerDefault.add(arrayIntegerDefaultItem); return this; diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/Query.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/Query.java index b09483a5d89c..0c79e5bbf95b 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/Query.java +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/model/Query.java @@ -119,7 +119,7 @@ public Query outcomes(@javax.annotation.Nullable List outcomes) { public Query addOutcomesItem(OutcomesEnum outcomesItem) { if (this.outcomes == null) { - this.outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE)); + this.outcomes = new ArrayList<>(); } this.outcomes.add(outcomesItem); return this; diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java index 1d48fe3d9ec6..7254f33e8180 100644 --- a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -132,7 +132,7 @@ public DefaultValue arrayStringEnumRefDefault(@javax.annotation.Nullable List(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE)); + this.arrayStringEnumRefDefault = new ArrayList<>(); } this.arrayStringEnumRefDefault.add(arrayStringEnumRefDefaultItem); return this; @@ -162,7 +162,7 @@ public DefaultValue arrayStringEnumDefault(@javax.annotation.Nullable List(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE)); + this.arrayStringEnumDefault = new ArrayList<>(); } this.arrayStringEnumDefault.add(arrayStringEnumDefaultItem); return this; @@ -192,7 +192,7 @@ public DefaultValue arrayStringDefault(@javax.annotation.Nullable List a public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) { if (this.arrayStringDefault == null) { - this.arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped")); + this.arrayStringDefault = new ArrayList<>(); } this.arrayStringDefault.add(arrayStringDefaultItem); return this; @@ -222,7 +222,7 @@ public DefaultValue arrayIntegerDefault(@javax.annotation.Nullable List public DefaultValue addArrayIntegerDefaultItem(Integer arrayIntegerDefaultItem) { if (this.arrayIntegerDefault == null) { - this.arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3)); + this.arrayIntegerDefault = new ArrayList<>(); } this.arrayIntegerDefault.add(arrayIntegerDefaultItem); return this; diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Query.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Query.java index ebd170c8e1a7..7c3affd97594 100644 --- a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Query.java +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/model/Query.java @@ -122,7 +122,7 @@ public Query outcomes(@javax.annotation.Nullable List outcomes) { public Query addOutcomesItem(OutcomesEnum outcomesItem) { if (this.outcomes == null) { - this.outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE)); + this.outcomes = new ArrayList<>(); } this.outcomes.add(outcomesItem); return this; diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java index 9a790b47ffd8..7edd8338f526 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -127,7 +127,7 @@ public DefaultValue arrayStringEnumRefDefault(@javax.annotation.Nullable List(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE)); + this.arrayStringEnumRefDefault = new ArrayList<>(); } this.arrayStringEnumRefDefault.add(arrayStringEnumRefDefaultItem); return this; @@ -159,7 +159,7 @@ public DefaultValue arrayStringEnumDefault(@javax.annotation.Nullable List(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE)); + this.arrayStringEnumDefault = new ArrayList<>(); } this.arrayStringEnumDefault.add(arrayStringEnumDefaultItem); return this; @@ -191,7 +191,7 @@ public DefaultValue arrayStringDefault(@javax.annotation.Nullable List a public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) { if (this.arrayStringDefault == null) { - this.arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped")); + this.arrayStringDefault = new ArrayList<>(); } this.arrayStringDefault.add(arrayStringDefaultItem); return this; @@ -223,7 +223,7 @@ public DefaultValue arrayIntegerDefault(@javax.annotation.Nullable List public DefaultValue addArrayIntegerDefaultItem(Integer arrayIntegerDefaultItem) { if (this.arrayIntegerDefault == null) { - this.arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3)); + this.arrayIntegerDefault = new ArrayList<>(); } this.arrayIntegerDefault.add(arrayIntegerDefaultItem); return this; diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/Query.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/Query.java index 991e4cc32ee8..d9086f24c81a 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/Query.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/model/Query.java @@ -119,7 +119,7 @@ public Query outcomes(@javax.annotation.Nullable List outcomes) { public Query addOutcomesItem(OutcomesEnum outcomesItem) { if (this.outcomes == null) { - this.outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE)); + this.outcomes = new ArrayList<>(); } this.outcomes.add(outcomesItem); return this; diff --git a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java index d5216fd0896d..12cce66462ce 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -159,7 +159,7 @@ public DefaultValue arrayStringEnumRefDefault(@javax.annotation.Nullable List(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE)); + this.arrayStringEnumRefDefault = new ArrayList<>(); } this.arrayStringEnumRefDefault.add(arrayStringEnumRefDefaultItem); return this; @@ -186,7 +186,7 @@ public DefaultValue arrayStringEnumDefault(@javax.annotation.Nullable List(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE)); + this.arrayStringEnumDefault = new ArrayList<>(); } this.arrayStringEnumDefault.add(arrayStringEnumDefaultItem); return this; @@ -213,7 +213,7 @@ public DefaultValue arrayStringDefault(@javax.annotation.Nullable List a public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) { if (this.arrayStringDefault == null) { - this.arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped")); + this.arrayStringDefault = new ArrayList<>(); } this.arrayStringDefault.add(arrayStringDefaultItem); return this; @@ -240,7 +240,7 @@ public DefaultValue arrayIntegerDefault(@javax.annotation.Nullable List public DefaultValue addArrayIntegerDefaultItem(Integer arrayIntegerDefaultItem) { if (this.arrayIntegerDefault == null) { - this.arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3)); + this.arrayIntegerDefault = new ArrayList<>(); } this.arrayIntegerDefault.add(arrayIntegerDefaultItem); return this; diff --git a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Query.java b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Query.java index de9ee1bdd6ec..c627580368e3 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Query.java +++ b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Query.java @@ -146,7 +146,7 @@ public Query outcomes(@javax.annotation.Nullable List outcomes) { public Query addOutcomesItem(OutcomesEnum outcomesItem) { if (this.outcomes == null) { - this.outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE)); + this.outcomes = new ArrayList<>(); } this.outcomes.add(outcomesItem); return this; diff --git a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/DefaultValue.java index a93354d7c6a9..7f048f2cec23 100644 --- a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -127,7 +127,7 @@ public DefaultValue arrayStringEnumRefDefault(@jakarta.annotation.Nullable List< public DefaultValue addArrayStringEnumRefDefaultItem(StringEnumRef arrayStringEnumRefDefaultItem) { if (this.arrayStringEnumRefDefault == null) { - this.arrayStringEnumRefDefault = new ArrayList<>(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE)); + this.arrayStringEnumRefDefault = new ArrayList<>(); } this.arrayStringEnumRefDefault.add(arrayStringEnumRefDefaultItem); return this; @@ -160,7 +160,7 @@ public DefaultValue arrayStringEnumDefault(@jakarta.annotation.Nullable List(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE)); + this.arrayStringEnumDefault = new ArrayList<>(); } this.arrayStringEnumDefault.add(arrayStringEnumDefaultItem); return this; @@ -193,7 +193,7 @@ public DefaultValue arrayStringDefault(@jakarta.annotation.Nullable List public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) { if (this.arrayStringDefault == null) { - this.arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped")); + this.arrayStringDefault = new ArrayList<>(); } this.arrayStringDefault.add(arrayStringDefaultItem); return this; @@ -226,7 +226,7 @@ public DefaultValue arrayIntegerDefault(@jakarta.annotation.Nullable List(Arrays.asList(1, 3)); + this.arrayIntegerDefault = new ArrayList<>(); } this.arrayIntegerDefault.add(arrayIntegerDefaultItem); return this; diff --git a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/Query.java b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/Query.java index 732573b790f8..0334ff17f916 100644 --- a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/Query.java +++ b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/Query.java @@ -117,7 +117,7 @@ public Query outcomes(@jakarta.annotation.Nullable List outcomes) public Query addOutcomesItem(OutcomesEnum outcomesItem) { if (this.outcomes == null) { - this.outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE)); + this.outcomes = new ArrayList<>(); } this.outcomes.add(outcomesItem); return this; diff --git a/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/DefaultValue.java index fa2912a7f0a6..489ffc525c36 100644 --- a/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -126,7 +126,7 @@ public DefaultValue arrayStringEnumRefDefault(@javax.annotation.Nullable List(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE)); + this.arrayStringEnumRefDefault = new ArrayList<>(); } this.arrayStringEnumRefDefault.add(arrayStringEnumRefDefaultItem); return this; @@ -159,7 +159,7 @@ public DefaultValue arrayStringEnumDefault(@javax.annotation.Nullable List(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE)); + this.arrayStringEnumDefault = new ArrayList<>(); } this.arrayStringEnumDefault.add(arrayStringEnumDefaultItem); return this; @@ -192,7 +192,7 @@ public DefaultValue arrayStringDefault(@javax.annotation.Nullable List a public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) { if (this.arrayStringDefault == null) { - this.arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped")); + this.arrayStringDefault = new ArrayList<>(); } this.arrayStringDefault.add(arrayStringDefaultItem); return this; @@ -225,7 +225,7 @@ public DefaultValue arrayIntegerDefault(@javax.annotation.Nullable List public DefaultValue addArrayIntegerDefaultItem(Integer arrayIntegerDefaultItem) { if (this.arrayIntegerDefault == null) { - this.arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3)); + this.arrayIntegerDefault = new ArrayList<>(); } this.arrayIntegerDefault.add(arrayIntegerDefaultItem); return this; diff --git a/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/Query.java b/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/Query.java index db7e48cefff4..e056ccbb8aad 100644 --- a/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/Query.java +++ b/samples/client/echo_api/java/resteasy/src/main/java/org/openapitools/client/model/Query.java @@ -116,7 +116,7 @@ public Query outcomes(@javax.annotation.Nullable List outcomes) { public Query addOutcomesItem(OutcomesEnum outcomesItem) { if (this.outcomes == null) { - this.outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE)); + this.outcomes = new ArrayList<>(); } this.outcomes.add(outcomesItem); return this; diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/DefaultValue.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/DefaultValue.java index d1da7740db83..23946d358083 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/DefaultValue.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/DefaultValue.java @@ -127,7 +127,7 @@ public DefaultValue arrayStringEnumRefDefault(@javax.annotation.Nullable List(Arrays.asList(StringEnumRef.SUCCESS, StringEnumRef.FAILURE)); + this.arrayStringEnumRefDefault = new ArrayList<>(); } this.arrayStringEnumRefDefault.add(arrayStringEnumRefDefaultItem); return this; @@ -160,7 +160,7 @@ public DefaultValue arrayStringEnumDefault(@javax.annotation.Nullable List(Arrays.asList(ArrayStringEnumDefaultEnum.SUCCESS, ArrayStringEnumDefaultEnum.FAILURE)); + this.arrayStringEnumDefault = new ArrayList<>(); } this.arrayStringEnumDefault.add(arrayStringEnumDefaultItem); return this; @@ -193,7 +193,7 @@ public DefaultValue arrayStringDefault(@javax.annotation.Nullable List a public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) { if (this.arrayStringDefault == null) { - this.arrayStringDefault = new ArrayList<>(Arrays.asList("failure", "skipped")); + this.arrayStringDefault = new ArrayList<>(); } this.arrayStringDefault.add(arrayStringDefaultItem); return this; @@ -226,7 +226,7 @@ public DefaultValue arrayIntegerDefault(@javax.annotation.Nullable List public DefaultValue addArrayIntegerDefaultItem(Integer arrayIntegerDefaultItem) { if (this.arrayIntegerDefault == null) { - this.arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3)); + this.arrayIntegerDefault = new ArrayList<>(); } this.arrayIntegerDefault.add(arrayIntegerDefaultItem); return this; diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/Query.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/Query.java index 80f56c024468..c54f9bec172d 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/Query.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/model/Query.java @@ -117,7 +117,7 @@ public Query outcomes(@javax.annotation.Nullable List outcomes) { public Query addOutcomesItem(OutcomesEnum outcomesItem) { if (this.outcomes == null) { - this.outcomes = new ArrayList<>(Arrays.asList(OutcomesEnum.SUCCESS, OutcomesEnum.FAILURE)); + this.outcomes = new ArrayList<>(); } this.outcomes.add(outcomesItem); return this; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NestedArrayWithDefaultValues.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NestedArrayWithDefaultValues.java index a2eb060cb495..48814b34092d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NestedArrayWithDefaultValues.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NestedArrayWithDefaultValues.java @@ -56,7 +56,12 @@ public class NestedArrayWithDefaultValues { public static final String SERIALIZED_NAME_NESTED_ARRAY = "nestedArray"; @SerializedName(SERIALIZED_NAME_NESTED_ARRAY) @javax.annotation.Nullable - private List> nestedArray; + private List> nestedArray = new ArrayList<>(Arrays.asList( + new ArrayList<>(Arrays.asList("h1", "Header 1")), + new ArrayList<>(Arrays.asList("h2", "Header 2")), + new ArrayList<>(Arrays.asList("h3", "Header 3")), + new ArrayList<>(Arrays.asList("h4", "Header 4")) + )); public NestedArrayWithDefaultValues() { } diff --git a/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java b/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java index 6aa2554e4b9b..e16517f01afe 100644 --- a/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java +++ b/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java @@ -133,7 +133,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(List nullableAr public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java b/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java index 9e1ca410807f..de44068588b8 100644 --- a/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java +++ b/samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java @@ -134,7 +134,7 @@ public TypeHolderDefaultDto arrayItem(List arrayItem) { public TypeHolderDefaultDto addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java index 5d27a402d91e..c8c322457882 100644 --- a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java +++ b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java @@ -132,7 +132,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(List nullableAr public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java index 68efb18ba702..327544428893 100644 --- a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java +++ b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java @@ -133,7 +133,7 @@ public TypeHolderDefaultDto arrayItem(List arrayItem) { public TypeHolderDefaultDto addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 604eb01af6e8..f01445b4a0b7 100644 --- a/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -139,7 +139,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java index 49aa2c2c320f..b0eced42d1e8 100644 --- a/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -143,7 +143,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java index d9cb7817b39e..7404f363cdf3 100644 --- a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -138,7 +138,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java index e4e061a72e8f..d10fcce1fe39 100644 --- a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -142,7 +142,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java index d9cb7817b39e..7404f363cdf3 100644 --- a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -138,7 +138,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java index e4e061a72e8f..d10fcce1fe39 100644 --- a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -142,7 +142,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java index f2a0293de163..a3470ed6c646 100644 --- a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java +++ b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java @@ -132,7 +132,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(@Nullable List public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null) { - this.nullableArrayWithDefault = new ArrayList<>(Arrays.asList("foo", "bar")); + this.nullableArrayWithDefault = new ArrayList<>(); } this.nullableArrayWithDefault.add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java index 298d26b97d80..508c07b98798 100644 --- a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java +++ b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java @@ -134,7 +134,7 @@ public TypeHolderDefaultDto arrayItem(List arrayItem) { public TypeHolderDefaultDto addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 95735ab0a3ab..e9d1a0634c6b 100644 --- a/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -140,7 +140,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/TypeHolderDefault.java index 7155f8993692..9f11c8965bee 100644 --- a/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -144,7 +144,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java index 5d27a402d91e..c8c322457882 100644 --- a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java +++ b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java @@ -132,7 +132,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(List nullableAr public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java index 68efb18ba702..327544428893 100644 --- a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java +++ b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java @@ -133,7 +133,7 @@ public TypeHolderDefaultDto arrayItem(List arrayItem) { public TypeHolderDefaultDto addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 1f95625c0f4d..772186195867 100644 --- a/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -135,7 +135,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/TypeHolderDefault.java index f890d89de5e7..0f880f9dea0c 100644 --- a/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -137,7 +137,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/spring-boot-defaultInterface-unhandledExcp/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 42d16df5b618..d9f813d3d5c6 100644 --- a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -141,7 +141,7 @@ public ContainerDefaultValue nullableArrayWithDefault(@Nullable List nul public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null) { - this.nullableArrayWithDefault = new ArrayList<>(Arrays.asList("foo", "bar")); + this.nullableArrayWithDefault = new ArrayList<>(); } this.nullableArrayWithDefault.add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/TypeHolderDefault.java index f5bed560f58e..afa2b19c79a0 100644 --- a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -147,7 +147,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 4437c27e7515..32e5fead03f7 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -153,7 +153,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java index 16870d1ba740..02761b2cc368 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 728935588c15..7f8cb7ecfe2b 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java index 575629bd429c..1d9b5a3a59c6 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java b/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java index 3dd8fc9bbfc5..224ca6695157 100644 --- a/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java +++ b/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java @@ -145,7 +145,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(List nullableAr public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java b/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java index a5f835a03345..7b627e7a2b44 100644 --- a/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java +++ b/samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java @@ -150,7 +150,7 @@ public TypeHolderDefaultDto arrayItem(List arrayItem) { public TypeHolderDefaultDto addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java index 92c5cd8bf463..5ae258254493 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java index 08271fd96d26..4cbea99016f8 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/ContainerDefaultValue.java index e82391112784..f1b09771a9ea 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/TypeHolderDefault.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/TypeHolderDefault.java index 181aea003476..28d8fbb4a60b 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/ContainerDefaultValue.java b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/ContainerDefaultValue.java index b0b030c3da11..5c0b89e04512 100644 --- a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/ContainerDefaultValue.java +++ b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/ContainerDefaultValue.java @@ -143,7 +143,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List nullableArray public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/TypeHolderDefault.java b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/TypeHolderDefault.java index c0e3ff7963eb..98ea4e4e74c6 100644 --- a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/TypeHolderDefault.java +++ b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/TypeHolderDefault.java @@ -148,7 +148,7 @@ public TypeHolderDefault arrayItem(List arrayItem) { public TypeHolderDefault addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this; diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java index 4bde53e8fc80..840fd6853399 100644 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java +++ b/samples/server/petstore/springboot/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java @@ -145,7 +145,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(List nullableAr public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) { if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) { - this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar"))); + this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>()); } this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem); return this; diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java index b70e6b0fe412..f8b75b9d3bab 100644 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java +++ b/samples/server/petstore/springboot/src/main/java/org/openapitools/model/TypeHolderDefaultDto.java @@ -150,7 +150,7 @@ public TypeHolderDefaultDto arrayItem(List arrayItem) { public TypeHolderDefaultDto addArrayItemItem(Integer arrayItemItem) { if (this.arrayItem == null) { - this.arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + this.arrayItem = new ArrayList<>(); } this.arrayItem.add(arrayItemItem); return this;