Skip to content

Commit acc2849

Browse files
authored
Merge pull request #3244 from wing328/java_fix_2d_array_enum
[Java] better default value for variable declaration (with inner enum type)
2 parents c5724a4 + aaf7b99 commit acc2849

File tree

5 files changed

+23
-55
lines changed

5 files changed

+23
-55
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,14 +1595,10 @@ protected void updatePropertyForArray(CodegenProperty property, CodegenProperty
15951595
// inner item is Enum
15961596
if (isPropertyInnerMostEnum(property)) {
15971597
property.isEnum = true;
1598-
// update datatypeWithEnum for array
1598+
// update datatypeWithEnum and default value for array
15991599
// e.g. List<string> => List<StatusEnum>
16001600
updateDataTypeWithEnumForArray(property);
16011601

1602-
// TOOD need to revise the default value for enum
1603-
if (property.defaultValue != null) {
1604-
property.defaultValue = property.defaultValue.replace(property.items.baseType, property.items.datatypeWithEnum);
1605-
}
16061602
}
16071603
}
16081604
}
@@ -1626,15 +1622,9 @@ protected void updatePropertyForMap(CodegenProperty property, CodegenProperty in
16261622
// inner item is Enum
16271623
if (isPropertyInnerMostEnum(property)) {
16281624
property.isEnum = true;
1629-
// update datatypeWithEnum for map
1625+
// update datatypeWithEnum and default value for map
16301626
// e.g. Dictionary<string, string> => Dictionary<string, StatusEnum>
16311627
updateDataTypeWithEnumForMap(property);
1632-
1633-
// TOOD need to revise the default value for enum
1634-
// set default value
1635-
if (property.defaultValue != null) {
1636-
property.defaultValue = property.defaultValue.replace(property.items.baseType, property.items.datatypeWithEnum);
1637-
}
16381628
}
16391629
}
16401630

@@ -1667,7 +1657,11 @@ protected void updateDataTypeWithEnumForArray(CodegenProperty property) {
16671657
}
16681658
// set both datatype and datetypeWithEnum as only the inner type is enum
16691659
property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, toEnumName(baseItem));
1670-
//property.datatype = property.datatypeWithEnum;
1660+
1661+
// set default value for variable with inner enum
1662+
if (property.defaultValue != null) {
1663+
property.defaultValue = property.defaultValue.replace(property.items.baseType, toEnumName(property.items));
1664+
}
16711665
}
16721666

16731667
/**
@@ -1682,7 +1676,11 @@ protected void updateDataTypeWithEnumForMap(CodegenProperty property) {
16821676
}
16831677
// set both datatype and datetypeWithEnum as only the inner type is enum
16841678
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem));
1685-
//property.datatype = property.datatypeWithEnum;
1679+
1680+
// set default value for variable with inner enum
1681+
if (property.defaultValue != null) {
1682+
property.defaultValue = property.defaultValue.replace(", " + property.items.baseType, ", " + toEnumName(property.items));
1683+
}
16861684
}
16871685

16881686
protected void setNonArrayMapProperty(CodegenProperty property, String type) {

modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,15 +1064,16 @@ definitions:
10641064
type: object
10651065
additionalProperties:
10661066
type: string
1067-
map_map_of_enum:
1068-
type: object
1069-
additionalProperties:
1070-
type: object
1071-
additionalProperties:
1072-
type: string
1073-
enum:
1074-
- UPPER
1075-
- lower
1067+
# comment out the following (map of map of enum) as many language not yet support this
1068+
#map_map_of_enum:
1069+
# type: object
1070+
# additionalProperties:
1071+
# type: object
1072+
# additionalProperties:
1073+
# type: string
1074+
# enum:
1075+
# - UPPER
1076+
# - lower
10761077
map_of_enum_string:
10771078
type: object
10781079
additionalProperties:

samples/client/petstore/java/okhttp-gson/docs/MapTest.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,9 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**mapMapOfString** | [**Map&lt;String, Map&lt;String, String&gt;&gt;**](Map.md) | | [optional]
8-
**mapMapOfEnum** | [**Map&lt;String, Map&lt;String, InnerEnum&gt;&gt;**](#Map&lt;String, Map&lt;String, InnerEnum&gt;&gt;) | | [optional]
98
**mapOfEnumString** | [**Map&lt;String, InnerEnum&gt;**](#Map&lt;String, InnerEnum&gt;) | | [optional]
109

1110

12-
<a name="Map<String, Map<String, InnerEnum>>"></a>
13-
## Enum: Map&lt;String, Map&lt;String, InnerEnum&gt;&gt;
14-
Name | Value
15-
---- | -----
16-
17-
1811
<a name="Map<String, InnerEnum>"></a>
1912
## Enum: Map&lt;String, InnerEnum&gt;
2013
Name | Value

samples/client/petstore/java/okhttp-gson/hello.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ public class MapTest {
4242
@SerializedName("map_map_of_string")
4343
private Map<String, Map<String, String>> mapMapOfString = new HashMap<String, Map<String, String>>();
4444

45-
@SerializedName("map_map_of_enum")
46-
private Map<String, Map<String, InnerEnum>> mapMapOfEnum = new HashMap<String, Map<String, InnerEnum>>();
47-
4845
/**
4946
* Gets or Sets inner
5047
*/
@@ -88,24 +85,6 @@ public void setMapMapOfString(Map<String, Map<String, String>> mapMapOfString) {
8885
this.mapMapOfString = mapMapOfString;
8986
}
9087

91-
public MapTest mapMapOfEnum(Map<String, Map<String, InnerEnum>> mapMapOfEnum) {
92-
this.mapMapOfEnum = mapMapOfEnum;
93-
return this;
94-
}
95-
96-
/**
97-
* Get mapMapOfEnum
98-
* @return mapMapOfEnum
99-
**/
100-
@ApiModelProperty(example = "null", value = "")
101-
public Map<String, Map<String, InnerEnum>> getMapMapOfEnum() {
102-
return mapMapOfEnum;
103-
}
104-
105-
public void setMapMapOfEnum(Map<String, Map<String, InnerEnum>> mapMapOfEnum) {
106-
this.mapMapOfEnum = mapMapOfEnum;
107-
}
108-
10988
public MapTest mapOfEnumString(Map<String, InnerEnum> mapOfEnumString) {
11089
this.mapOfEnumString = mapOfEnumString;
11190
return this;
@@ -135,13 +114,12 @@ public boolean equals(java.lang.Object o) {
135114
}
136115
MapTest mapTest = (MapTest) o;
137116
return Objects.equals(this.mapMapOfString, mapTest.mapMapOfString) &&
138-
Objects.equals(this.mapMapOfEnum, mapTest.mapMapOfEnum) &&
139117
Objects.equals(this.mapOfEnumString, mapTest.mapOfEnumString);
140118
}
141119

142120
@Override
143121
public int hashCode() {
144-
return Objects.hash(mapMapOfString, mapMapOfEnum, mapOfEnumString);
122+
return Objects.hash(mapMapOfString, mapOfEnumString);
145123
}
146124

147125
@Override
@@ -150,7 +128,6 @@ public String toString() {
150128
sb.append("class MapTest {\n");
151129

152130
sb.append(" mapMapOfString: ").append(toIndentedString(mapMapOfString)).append("\n");
153-
sb.append(" mapMapOfEnum: ").append(toIndentedString(mapMapOfEnum)).append("\n");
154131
sb.append(" mapOfEnumString: ").append(toIndentedString(mapOfEnumString)).append("\n");
155132
sb.append("}");
156133
return sb.toString();

0 commit comments

Comments
 (0)