Skip to content

Commit 82d23be

Browse files
xhhwing328
authored andcommitted
improve enum support in java okhttp-gson client
1 parent 39267a2 commit 82d23be

File tree

21 files changed

+513
-253
lines changed

21 files changed

+513
-253
lines changed

modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/enumClass.mustache

Lines changed: 0 additions & 17 deletions
This file was deleted.

modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/model.mustache

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,78 +8,7 @@ import com.google.gson.annotations.SerializedName;
88

99
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
1010
{{#models}}
11-
12-
{{#model}}{{#description}}
13-
/**
14-
* {{description}}
15-
**/{{/description}}
16-
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
17-
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
18-
{{#vars}}{{#isEnum}}
19-
20-
{{>libraries/okhttp-gson/enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
21-
22-
{{>libraries/okhttp-gson/enumClass}}{{/items}}{{/items.isEnum}}
23-
@SerializedName("{{baseName}}")
24-
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
25-
{{/vars}}
26-
27-
{{#vars}}
28-
/**{{#description}}
29-
* {{{description}}}{{/description}}{{#minimum}}
30-
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
31-
* maximum: {{maximum}}{{/maximum}}
32-
**/
33-
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
34-
public {{{datatypeWithEnum}}} {{getter}}() {
35-
return {{name}};
36-
}{{^isReadOnly}}
37-
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
38-
this.{{name}} = {{name}};
39-
}{{/isReadOnly}}
40-
41-
{{/vars}}
42-
43-
@Override
44-
public boolean equals(Object o) {
45-
if (this == o) {
46-
return true;
47-
}
48-
if (o == null || getClass() != o.getClass()) {
49-
return false;
50-
}{{#hasVars}}
51-
{{classname}} {{classVarName}} = ({{classname}}) o;
52-
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
53-
{{/hasMore}}{{/vars}}{{#parent}} &&
54-
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
55-
return true;{{/hasVars}}
56-
}
57-
58-
@Override
59-
public int hashCode() {
60-
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
61-
}
62-
63-
@Override
64-
public String toString() {
65-
StringBuilder sb = new StringBuilder();
66-
sb.append("class {{classname}} {\n");
67-
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
68-
{{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n");
69-
{{/vars}}sb.append("}");
70-
return sb.toString();
71-
}
72-
73-
/**
74-
* Convert the given object to string with each line indented by 4 spaces
75-
* (except the first line).
76-
*/
77-
private String toIndentedString(Object o) {
78-
if (o == null) {
79-
return "null";
80-
}
81-
return o.toString().replace("\n", "\n ");
82-
}
83-
}
11+
{{#model}}
12+
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>pojo}}{{/isEnum}}
8413
{{/model}}
8514
{{/models}}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* {{^description}}Gets or Sets {{name}}{{/description}}{{#description}}{{description}}{{/description}}
3+
*/
4+
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
5+
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}})
6+
{{{name}}}({{{value}}}){{^-last}},
7+
8+
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
9+
10+
private {{dataType}} value;
11+
12+
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{dataType}} value) {
13+
this.value = value;
14+
}
15+
16+
@Override
17+
public String toString() {
18+
return String.valueOf(value);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
3+
*/
4+
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
5+
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}})
6+
{{{name}}}({{{value}}}){{^-last}},
7+
8+
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
9+
10+
private {{datatype}} value;
11+
12+
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
13+
this.value = value;
14+
}
15+
16+
@Override
17+
public String toString() {
18+
return String.valueOf(value);
19+
}
20+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* {{#description}}{{description}}{{/description}}{{^description}}{{classname}}{{/description}}
3+
*/{{#description}}
4+
@ApiModel(description = "{{{description}}}"){{/description}}
5+
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
6+
{{#vars}}{{#isEnum}}
7+
8+
{{>libraries/okhttp-gson/modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
9+
10+
{{>libraries/okhttp-gson/modelInnerEnum}}{{/items}}{{/items.isEnum}}
11+
@SerializedName("{{baseName}}")
12+
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
13+
{{/vars}}
14+
15+
{{#vars}}
16+
/**{{#description}}
17+
* {{{description}}}{{/description}}{{#minimum}}
18+
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
19+
* maximum: {{maximum}}{{/maximum}}
20+
**/
21+
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
22+
public {{{datatypeWithEnum}}} {{getter}}() {
23+
return {{name}};
24+
}{{^isReadOnly}}
25+
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
26+
this.{{name}} = {{name}};
27+
}{{/isReadOnly}}
28+
29+
{{/vars}}
30+
31+
@Override
32+
public boolean equals(Object o) {
33+
if (this == o) {
34+
return true;
35+
}
36+
if (o == null || getClass() != o.getClass()) {
37+
return false;
38+
}{{#hasVars}}
39+
{{classname}} {{classVarName}} = ({{classname}}) o;
40+
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
41+
{{/hasMore}}{{/vars}}{{#parent}} &&
42+
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
43+
return true;{{/hasVars}}
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
49+
}
50+
51+
@Override
52+
public String toString() {
53+
StringBuilder sb = new StringBuilder();
54+
sb.append("class {{classname}} {\n");
55+
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
56+
{{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n");
57+
{{/vars}}sb.append("}");
58+
return sb.toString();
59+
}
60+
61+
/**
62+
* Convert the given object to string with each line indented by 4 spaces
63+
* (except the first line).
64+
*/
65+
private String toIndentedString(Object o) {
66+
if (o == null) {
67+
return "null";
68+
}
69+
return o.toString().replace("\n", "\n ");
70+
}
71+
}

samples/client/petstore/java/okhttp-gson/git_push.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ git_repo_id=$2
88
release_note=$3
99

1010
if [ "$git_user_id" = "" ]; then
11-
git_user_id="YOUR_GIT_USR_ID"
11+
git_user_id=""
1212
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
1313
fi
1414

1515
if [ "$git_repo_id" = "" ]; then
16-
git_repo_id="YOUR_GIT_REPO_ID"
16+
git_repo_id=""
1717
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
1818
fi
1919

2020
if [ "$release_note" = "" ]; then
21-
release_note="Minor update"
21+
release_note=""
2222
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
2323
fi
2424

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
import com.google.gson.annotations.SerializedName;
88

99

10-
11-
12-
10+
/**
11+
* Animal
12+
*/
1313
public class Animal {
1414

1515
@SerializedName("className")
1616
private String className = null;
17+
1718

19+
1820
/**
1921
**/
2022
@ApiModelProperty(required = true, value = "")
@@ -25,6 +27,7 @@ public void setClassName(String className) {
2527
this.className = className;
2628
}
2729

30+
2831

2932
@Override
3033
public boolean equals(Object o) {
@@ -64,3 +67,4 @@ private String toIndentedString(Object o) {
6467
return o.toString().replace("\n", "\n ");
6568
}
6669
}
70+

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
import com.google.gson.annotations.SerializedName;
99

1010

11-
12-
13-
11+
/**
12+
* Cat
13+
*/
1414
public class Cat extends Animal {
1515

1616
@SerializedName("className")
1717
private String className = null;
18-
18+
1919
@SerializedName("declawed")
2020
private Boolean declawed = null;
21+
2122

23+
2224
/**
2325
**/
2426
@ApiModelProperty(required = true, value = "")
@@ -29,6 +31,7 @@ public void setClassName(String className) {
2931
this.className = className;
3032
}
3133

34+
3235
/**
3336
**/
3437
@ApiModelProperty(value = "")
@@ -39,6 +42,7 @@ public void setDeclawed(Boolean declawed) {
3942
this.declawed = declawed;
4043
}
4144

45+
4246

4347
@Override
4448
public boolean equals(Object o) {
@@ -81,3 +85,4 @@ private String toIndentedString(Object o) {
8185
return o.toString().replace("\n", "\n ");
8286
}
8387
}
88+

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.google.gson.annotations.SerializedName;
88

99

10-
11-
12-
10+
/**
11+
* Category
12+
*/
1313
public class Category {
1414

1515
@SerializedName("id")
@@ -79,3 +79,4 @@ private String toIndentedString(Object o) {
7979
return o.toString().replace("\n", "\n ");
8080
}
8181
}
82+

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
import com.google.gson.annotations.SerializedName;
99

1010

11-
12-
13-
11+
/**
12+
* Dog
13+
*/
1414
public class Dog extends Animal {
1515

1616
@SerializedName("className")
1717
private String className = null;
18-
18+
1919
@SerializedName("breed")
2020
private String breed = null;
21+
2122

23+
2224
/**
2325
**/
2426
@ApiModelProperty(required = true, value = "")
@@ -29,6 +31,7 @@ public void setClassName(String className) {
2931
this.className = className;
3032
}
3133

34+
3235
/**
3336
**/
3437
@ApiModelProperty(value = "")
@@ -39,6 +42,7 @@ public void setBreed(String breed) {
3942
this.breed = breed;
4043
}
4144

45+
4246

4347
@Override
4448
public boolean equals(Object o) {
@@ -81,3 +85,4 @@ private String toIndentedString(Object o) {
8185
return o.toString().replace("\n", "\n ");
8286
}
8387
}
88+

0 commit comments

Comments
 (0)