Merge pull request #3244 from wing328/java_fix_2d_array_enum

[Java] better default value for variable declaration (with inner enum type)
This commit is contained in:
wing328 2016-06-29 19:39:01 +08:00 committed by GitHub
commit acc28495e8
5 changed files with 23 additions and 55 deletions

View File

@ -1595,14 +1595,10 @@ public class DefaultCodegen {
// inner item is Enum
if (isPropertyInnerMostEnum(property)) {
property.isEnum = true;
// update datatypeWithEnum for array
// update datatypeWithEnum and default value for array
// e.g. List<string> => List<StatusEnum>
updateDataTypeWithEnumForArray(property);
// TOOD need to revise the default value for enum
if (property.defaultValue != null) {
property.defaultValue = property.defaultValue.replace(property.items.baseType, property.items.datatypeWithEnum);
}
}
}
}
@ -1626,15 +1622,9 @@ public class DefaultCodegen {
// inner item is Enum
if (isPropertyInnerMostEnum(property)) {
property.isEnum = true;
// update datatypeWithEnum for map
// update datatypeWithEnum and default value for map
// e.g. Dictionary<string, string> => Dictionary<string, StatusEnum>
updateDataTypeWithEnumForMap(property);
// TOOD need to revise the default value for enum
// set default value
if (property.defaultValue != null) {
property.defaultValue = property.defaultValue.replace(property.items.baseType, property.items.datatypeWithEnum);
}
}
}
@ -1667,7 +1657,11 @@ public class DefaultCodegen {
}
// set both datatype and datetypeWithEnum as only the inner type is enum
property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, toEnumName(baseItem));
//property.datatype = property.datatypeWithEnum;
// set default value for variable with inner enum
if (property.defaultValue != null) {
property.defaultValue = property.defaultValue.replace(property.items.baseType, toEnumName(property.items));
}
}
/**
@ -1682,7 +1676,11 @@ public class DefaultCodegen {
}
// set both datatype and datetypeWithEnum as only the inner type is enum
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem));
//property.datatype = property.datatypeWithEnum;
// set default value for variable with inner enum
if (property.defaultValue != null) {
property.defaultValue = property.defaultValue.replace(", " + property.items.baseType, ", " + toEnumName(property.items));
}
}
protected void setNonArrayMapProperty(CodegenProperty property, String type) {

View File

@ -1064,15 +1064,16 @@ definitions:
type: object
additionalProperties:
type: string
map_map_of_enum:
type: object
additionalProperties:
type: object
additionalProperties:
type: string
enum:
- UPPER
- lower
# comment out the following (map of map of enum) as many language not yet support this
#map_map_of_enum:
# type: object
# additionalProperties:
# type: object
# additionalProperties:
# type: string
# enum:
# - UPPER
# - lower
map_of_enum_string:
type: object
additionalProperties:

View File

@ -5,16 +5,9 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**mapMapOfString** | [**Map&lt;String, Map&lt;String, String&gt;&gt;**](Map.md) | | [optional]
**mapMapOfEnum** | [**Map&lt;String, Map&lt;String, InnerEnum&gt;&gt;**](#Map&lt;String, Map&lt;String, InnerEnum&gt;&gt;) | | [optional]
**mapOfEnumString** | [**Map&lt;String, InnerEnum&gt;**](#Map&lt;String, InnerEnum&gt;) | | [optional]
<a name="Map<String, Map<String, InnerEnum>>"></a>
## Enum: Map&lt;String, Map&lt;String, InnerEnum&gt;&gt;
Name | Value
---- | -----
<a name="Map<String, InnerEnum>"></a>
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value

View File

@ -1 +0,0 @@
Hello world!

View File

@ -42,9 +42,6 @@ public class MapTest {
@SerializedName("map_map_of_string")
private Map<String, Map<String, String>> mapMapOfString = new HashMap<String, Map<String, String>>();
@SerializedName("map_map_of_enum")
private Map<String, Map<String, InnerEnum>> mapMapOfEnum = new HashMap<String, Map<String, InnerEnum>>();
/**
* Gets or Sets inner
*/
@ -88,24 +85,6 @@ public class MapTest {
this.mapMapOfString = mapMapOfString;
}
public MapTest mapMapOfEnum(Map<String, Map<String, InnerEnum>> mapMapOfEnum) {
this.mapMapOfEnum = mapMapOfEnum;
return this;
}
/**
* Get mapMapOfEnum
* @return mapMapOfEnum
**/
@ApiModelProperty(example = "null", value = "")
public Map<String, Map<String, InnerEnum>> getMapMapOfEnum() {
return mapMapOfEnum;
}
public void setMapMapOfEnum(Map<String, Map<String, InnerEnum>> mapMapOfEnum) {
this.mapMapOfEnum = mapMapOfEnum;
}
public MapTest mapOfEnumString(Map<String, InnerEnum> mapOfEnumString) {
this.mapOfEnumString = mapOfEnumString;
return this;
@ -135,13 +114,12 @@ public class MapTest {
}
MapTest mapTest = (MapTest) o;
return Objects.equals(this.mapMapOfString, mapTest.mapMapOfString) &&
Objects.equals(this.mapMapOfEnum, mapTest.mapMapOfEnum) &&
Objects.equals(this.mapOfEnumString, mapTest.mapOfEnumString);
}
@Override
public int hashCode() {
return Objects.hash(mapMapOfString, mapMapOfEnum, mapOfEnumString);
return Objects.hash(mapMapOfString, mapOfEnumString);
}
@Override
@ -150,7 +128,6 @@ public class MapTest {
sb.append("class MapTest {\n");
sb.append(" mapMapOfString: ").append(toIndentedString(mapMapOfString)).append("\n");
sb.append(" mapMapOfEnum: ").append(toIndentedString(mapMapOfEnum)).append("\n");
sb.append(" mapOfEnumString: ").append(toIndentedString(mapOfEnumString)).append("\n");
sb.append("}");
return sb.toString();