[Java] better default value handling (#14130)

* add test for array default value

* update null return

* minor fixes

* move default value tests to echo api spec

* add new files

* remove unused files

* fix enum array default, add tests

* better array init

* Update modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java

Co-authored-by: Leonard Brünings <lord_damokles@gmx.net>

* Update modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java

Co-authored-by: Leonard Brünings <lord_damokles@gmx.net>

* revert the fix

* improve default value handling

* update native samples, add tests

* update samples

* fix tests

* use conditional test for timezone

* add tests to apache http client echo api

* add option to default container to null

* fix map default value

* minor refactoring

* update samples

* fix javadoc

* fix pom.xml

* add tests in java native echo client

* add java apache client echo tests

* fix test

* fix test

---------

Co-authored-by: Leonard Brünings <lord_damokles@gmx.net>
This commit is contained in:
William Cheng
2023-01-30 20:19:00 +08:00
committed by GitHub
parent b3527348f3
commit fd45b74128
290 changed files with 3687 additions and 650 deletions

View File

@@ -38,10 +38,10 @@ import java.util.StringJoiner;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class AdditionalPropertiesClass {
public static final String JSON_PROPERTY_MAP_PROPERTY = "map_property";
private Map<String, String> mapProperty = null;
private Map<String, String> mapProperty = new HashMap<>();
public static final String JSON_PROPERTY_MAP_OF_MAP_PROPERTY = "map_of_map_property";
private Map<String, Map<String, String>> mapOfMapProperty = null;
private Map<String, Map<String, String>> mapOfMapProperty = new HashMap<>();
public AdditionalPropertiesClass() {
}

View File

@@ -38,7 +38,7 @@ import java.util.StringJoiner;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ArrayOfArrayOfNumberOnly {
public static final String JSON_PROPERTY_ARRAY_ARRAY_NUMBER = "ArrayArrayNumber";
private List<List<BigDecimal>> arrayArrayNumber = null;
private List<List<BigDecimal>> arrayArrayNumber = new ArrayList<>();
public ArrayOfArrayOfNumberOnly() {
}

View File

@@ -38,7 +38,7 @@ import java.util.StringJoiner;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ArrayOfNumberOnly {
public static final String JSON_PROPERTY_ARRAY_NUMBER = "ArrayNumber";
private List<BigDecimal> arrayNumber = null;
private List<BigDecimal> arrayNumber = new ArrayList<>();
public ArrayOfNumberOnly() {
}

View File

@@ -40,13 +40,13 @@ import java.util.StringJoiner;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ArrayTest {
public static final String JSON_PROPERTY_ARRAY_OF_STRING = "array_of_string";
private List<String> arrayOfString = null;
private List<String> arrayOfString = new ArrayList<>();
public static final String JSON_PROPERTY_ARRAY_ARRAY_OF_INTEGER = "array_array_of_integer";
private List<List<Long>> arrayArrayOfInteger = null;
private List<List<Long>> arrayArrayOfInteger = new ArrayList<>();
public static final String JSON_PROPERTY_ARRAY_ARRAY_OF_MODEL = "array_array_of_model";
private List<List<ReadOnlyFirst>> arrayArrayOfModel = null;
private List<List<ReadOnlyFirst>> arrayArrayOfModel = new ArrayList<>();
public ArrayTest() {
}

View File

@@ -111,7 +111,7 @@ public class EnumArrays {
}
public static final String JSON_PROPERTY_ARRAY_ENUM = "array_enum";
private List<ArrayEnumEnum> arrayEnum = null;
private List<ArrayEnumEnum> arrayEnum = new ArrayList<>();
public EnumArrays() {
}

View File

@@ -42,7 +42,7 @@ public class FileSchemaTestClass {
private ModelFile _file;
public static final String JSON_PROPERTY_FILES = "files";
private List<ModelFile> files = null;
private List<ModelFile> files = new ArrayList<>();
public FileSchemaTestClass() {
}

View File

@@ -40,7 +40,7 @@ import java.util.StringJoiner;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class MapTest {
public static final String JSON_PROPERTY_MAP_MAP_OF_STRING = "map_map_of_string";
private Map<String, Map<String, String>> mapMapOfString = null;
private Map<String, Map<String, String>> mapMapOfString = new HashMap<>();
/**
* Gets or Sets inner
@@ -78,13 +78,13 @@ public class MapTest {
}
public static final String JSON_PROPERTY_MAP_OF_ENUM_STRING = "map_of_enum_string";
private Map<String, InnerEnum> mapOfEnumString = null;
private Map<String, InnerEnum> mapOfEnumString = new HashMap<>();
public static final String JSON_PROPERTY_DIRECT_MAP = "direct_map";
private Map<String, Boolean> directMap = null;
private Map<String, Boolean> directMap = new HashMap<>();
public static final String JSON_PROPERTY_INDIRECT_MAP = "indirect_map";
private Map<String, Boolean> indirectMap = null;
private Map<String, Boolean> indirectMap = new HashMap<>();
public MapTest() {
}

View File

@@ -48,7 +48,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
private OffsetDateTime dateTime;
public static final String JSON_PROPERTY_MAP = "map";
private Map<String, Animal> map = null;
private Map<String, Animal> map = new HashMap<>();
public MixedPropertiesAndAdditionalPropertiesClass() {
}

View File

@@ -81,7 +81,7 @@ public class NullableClass extends HashMap<String, Object> {
private JsonNullable<List<Object>> arrayAndItemsNullableProp = JsonNullable.<List<Object>>undefined();
public static final String JSON_PROPERTY_ARRAY_ITEMS_NULLABLE = "array_items_nullable";
private List<Object> arrayItemsNullable = null;
private List<Object> arrayItemsNullable = new ArrayList<>();
public static final String JSON_PROPERTY_OBJECT_NULLABLE_PROP = "object_nullable_prop";
private JsonNullable<Map<String, Object>> objectNullableProp = JsonNullable.<Map<String, Object>>undefined();
@@ -90,7 +90,7 @@ public class NullableClass extends HashMap<String, Object> {
private JsonNullable<Map<String, Object>> objectAndItemsNullableProp = JsonNullable.<Map<String, Object>>undefined();
public static final String JSON_PROPERTY_OBJECT_ITEMS_NULLABLE = "object_items_nullable";
private Map<String, Object> objectItemsNullable = null;
private Map<String, Object> objectItemsNullable = new HashMap<>();
public NullableClass() {
@@ -308,7 +308,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass addArrayNullablePropItem(Object arrayNullablePropItem) {
if (this.arrayNullableProp == null || !this.arrayNullableProp.isPresent()) {
this.arrayNullableProp = JsonNullable.<List<Object>>of(new ArrayList<>());
this.arrayNullableProp = JsonNullable.<List<Object>>of(null);
}
try {
this.arrayNullableProp.get().add(arrayNullablePropItem);
@@ -354,7 +354,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass addArrayAndItemsNullablePropItem(Object arrayAndItemsNullablePropItem) {
if (this.arrayAndItemsNullableProp == null || !this.arrayAndItemsNullableProp.isPresent()) {
this.arrayAndItemsNullableProp = JsonNullable.<List<Object>>of(new ArrayList<>());
this.arrayAndItemsNullableProp = JsonNullable.<List<Object>>of(null);
}
try {
this.arrayAndItemsNullableProp.get().add(arrayAndItemsNullablePropItem);
@@ -434,7 +434,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass putObjectNullablePropItem(String key, Object objectNullablePropItem) {
if (this.objectNullableProp == null || !this.objectNullableProp.isPresent()) {
this.objectNullableProp = JsonNullable.<Map<String, Object>>of(new HashMap<>());
this.objectNullableProp = JsonNullable.<Map<String, Object>>of(null);
}
try {
this.objectNullableProp.get().put(key, objectNullablePropItem);
@@ -480,7 +480,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass putObjectAndItemsNullablePropItem(String key, Object objectAndItemsNullablePropItem) {
if (this.objectAndItemsNullableProp == null || !this.objectAndItemsNullableProp.isPresent()) {
this.objectAndItemsNullableProp = JsonNullable.<Map<String, Object>>of(new HashMap<>());
this.objectAndItemsNullableProp = JsonNullable.<Map<String, Object>>of(null);
}
try {
this.objectAndItemsNullableProp.get().put(key, objectAndItemsNullablePropItem);

View File

@@ -51,7 +51,7 @@ public class ObjectWithDeprecatedFields {
private DeprecatedObject deprecatedRef;
public static final String JSON_PROPERTY_BARS = "bars";
private List<String> bars = null;
private List<String> bars = new ArrayList<>();
public ObjectWithDeprecatedFields() {
}

View File

@@ -59,7 +59,7 @@ public class Pet {
private Set<String> photoUrls = new LinkedHashSet<>();
public static final String JSON_PROPERTY_TAGS = "tags";
private List<Tag> tags = null;
private List<Tag> tags = new ArrayList<>();
/**
* pet status in the store