From fd72409e3b70a9419031593996ea2acd9823a0de Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 29 Jun 2016 17:30:33 +0800 Subject: [PATCH 1/2] better default value for enum variable declaration --- .../io/swagger/codegen/DefaultCodegen.java | 26 +++++++++---------- .../petstore/java/okhttp-gson/hello.txt | 1 - .../java/io/swagger/client/model/MapTest.java | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) delete mode 100644 samples/client/petstore/java/okhttp-gson/hello.txt diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index da7b038fd9..d2bb3aed87 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -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 => List 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 => Dictionary 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) { diff --git a/samples/client/petstore/java/okhttp-gson/hello.txt b/samples/client/petstore/java/okhttp-gson/hello.txt deleted file mode 100644 index 6769dd60bd..0000000000 --- a/samples/client/petstore/java/okhttp-gson/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java index 64e08ad779..daf8e9ca9e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java @@ -43,7 +43,7 @@ public class MapTest { private Map> mapMapOfString = new HashMap>(); @SerializedName("map_map_of_enum") - private Map> mapMapOfEnum = new HashMap>(); + private Map> mapMapOfEnum = new HashMap>(); /** * Gets or Sets inner From aaf7b99220576d95dcb71b99db48a5e849e35ab7 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 29 Jun 2016 17:46:45 +0800 Subject: [PATCH 2/2] comment out test case for map of map of enum as many lang don't support --- ...ith-fake-endpoints-models-for-testing.yaml | 19 +++++++------- .../petstore/java/okhttp-gson/docs/MapTest.md | 7 ------ .../java/io/swagger/client/model/MapTest.java | 25 +------------------ 3 files changed, 11 insertions(+), 40 deletions(-) diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index 79d82c992f..5a0511e45a 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -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: diff --git a/samples/client/petstore/java/okhttp-gson/docs/MapTest.md b/samples/client/petstore/java/okhttp-gson/docs/MapTest.md index 67450f9a4f..c671e97ffb 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/MapTest.md +++ b/samples/client/petstore/java/okhttp-gson/docs/MapTest.md @@ -5,16 +5,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **mapMapOfString** | [**Map<String, Map<String, String>>**](Map.md) | | [optional] -**mapMapOfEnum** | [**Map<String, Map<String, InnerEnum>>**](#Map<String, Map<String, InnerEnum>>) | | [optional] **mapOfEnumString** | [**Map<String, InnerEnum>**](#Map<String, InnerEnum>) | | [optional] - -## Enum: Map<String, Map<String, InnerEnum>> -Name | Value ----- | ----- - - ## Enum: Map<String, InnerEnum> Name | Value diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java index daf8e9ca9e..61bdb6b2c6 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MapTest.java @@ -42,9 +42,6 @@ public class MapTest { @SerializedName("map_map_of_string") private Map> mapMapOfString = new HashMap>(); - @SerializedName("map_map_of_enum") - private Map> mapMapOfEnum = new HashMap>(); - /** * Gets or Sets inner */ @@ -88,24 +85,6 @@ public class MapTest { this.mapMapOfString = mapMapOfString; } - public MapTest mapMapOfEnum(Map> mapMapOfEnum) { - this.mapMapOfEnum = mapMapOfEnum; - return this; - } - - /** - * Get mapMapOfEnum - * @return mapMapOfEnum - **/ - @ApiModelProperty(example = "null", value = "") - public Map> getMapMapOfEnum() { - return mapMapOfEnum; - } - - public void setMapMapOfEnum(Map> mapMapOfEnum) { - this.mapMapOfEnum = mapMapOfEnum; - } - public MapTest mapOfEnumString(Map 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();