Skip to content

Commit fd72409

Browse files
committed
better default value for enum variable declaration
1 parent c5724a4 commit fd72409

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
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) {

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class MapTest {
4343
private Map<String, Map<String, String>> mapMapOfString = new HashMap<String, Map<String, String>>();
4444

4545
@SerializedName("map_map_of_enum")
46-
private Map<String, Map<String, InnerEnum>> mapMapOfEnum = new HashMap<String, Map<String, InnerEnum>>();
46+
private Map<String, Map<String, InnerEnum>> mapMapOfEnum = new HashMap<String, InnerEnum<String, String>>();
4747

4848
/**
4949
* Gets or Sets inner

0 commit comments

Comments
 (0)