[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

@@ -19,11 +19,11 @@ public class NullableClass extends HashMap<String, Object> {
private String stringProp;
private LocalDate dateProp;
private OffsetDateTime datetimeProp;
private List<Object> arrayNullableProp = new ArrayList<>();
private List<Object> arrayAndItemsNullableProp = new ArrayList<>();
private List<Object> arrayNullableProp = null;
private List<Object> arrayAndItemsNullableProp = null;
private List<Object> arrayItemsNullable = new ArrayList<>();
private Map<String, Object> objectNullableProp = new HashMap<>();
private Map<String, Object> objectAndItemsNullableProp = new HashMap<>();
private Map<String, Object> objectNullableProp = null;
private Map<String, Object> objectAndItemsNullableProp = null;
private Map<String, Object> objectItemsNullable = new HashMap<>();
/**

View File

@@ -222,7 +222,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass addArrayNullablePropItem(Object arrayNullablePropItem) {
if (this.arrayNullableProp == null) {
this.arrayNullableProp = new ArrayList<>();
this.arrayNullableProp = null;
}
this.arrayNullableProp.add(arrayNullablePropItem);
return this;
@@ -250,7 +250,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass addArrayAndItemsNullablePropItem(Object arrayAndItemsNullablePropItem) {
if (this.arrayAndItemsNullableProp == null) {
this.arrayAndItemsNullableProp = new ArrayList<>();
this.arrayAndItemsNullableProp = null;
}
this.arrayAndItemsNullableProp.add(arrayAndItemsNullablePropItem);
return this;
@@ -306,7 +306,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass putObjectNullablePropItem(String key, Object objectNullablePropItem) {
if (this.objectNullableProp == null) {
this.objectNullableProp = new HashMap<>();
this.objectNullableProp = null;
}
this.objectNullableProp.put(key, objectNullablePropItem);
return this;
@@ -334,7 +334,7 @@ public class NullableClass extends HashMap<String, Object> {
public NullableClass putObjectAndItemsNullablePropItem(String key, Object objectAndItemsNullablePropItem) {
if (this.objectAndItemsNullableProp == null) {
this.objectAndItemsNullableProp = new HashMap<>();
this.objectAndItemsNullableProp = null;
}
this.objectAndItemsNullableProp.put(key, objectAndItemsNullablePropItem);
return this;

View File

@@ -62,7 +62,7 @@ public class ObjectWithUniqueItems {
public ObjectWithUniqueItems addNullSetItem(String nullSetItem) {
if (this.nullSet == null || !this.nullSet.isPresent()) {
this.nullSet = JsonNullable.of(new LinkedHashSet<>());
this.nullSet = JsonNullable.of(null);
}
this.nullSet.get().add(nullSetItem);
return this;
@@ -117,7 +117,7 @@ public class ObjectWithUniqueItems {
public ObjectWithUniqueItems addNullListItem(String nullListItem) {
if (this.nullList == null || !this.nullList.isPresent()) {
this.nullList = JsonNullable.of(new ArrayList<>());
this.nullList = JsonNullable.of(null);
}
this.nullList.get().add(nullListItem);
return this;