-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from xhh/java-enum
Improve enum support in java okhttp-gson client
- Loading branch information
Showing
21 changed files
with
678 additions
and
171 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/enumClass.mustache
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/modelEnum.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* {{^description}}Gets or Sets {{name}}{{/description}}{{#description}}{{description}}{{/description}} | ||
*/ | ||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { | ||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}) | ||
{{{name}}}({{{value}}}){{^-last}}, | ||
|
||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
|
||
private {{dataType}} value; | ||
|
||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{dataType}} value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(value); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...les/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/modelInnerEnum.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} | ||
*/ | ||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { | ||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}) | ||
{{{name}}}({{{value}}}){{^-last}}, | ||
|
||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
|
||
private {{datatype}} value; | ||
|
||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(value); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* {{#description}}{{description}}{{/description}}{{^description}}{{classname}}{{/description}} | ||
*/{{#description}} | ||
@ApiModel(description = "{{{description}}}"){{/description}} | ||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { | ||
{{#vars}}{{#isEnum}} | ||
|
||
{{>libraries/okhttp-gson/modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}} | ||
|
||
{{>libraries/okhttp-gson/modelInnerEnum}}{{/items}}{{/items.isEnum}} | ||
@SerializedName("{{baseName}}") | ||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}}; | ||
{{/vars}} | ||
|
||
{{#vars}} | ||
/**{{#description}} | ||
* {{{description}}}{{/description}}{{#minimum}} | ||
* minimum: {{minimum}}{{/minimum}}{{#maximum}} | ||
* maximum: {{maximum}}{{/maximum}} | ||
**/ | ||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") | ||
public {{{datatypeWithEnum}}} {{getter}}() { | ||
return {{name}}; | ||
}{{^isReadOnly}} | ||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { | ||
this.{{name}} = {{name}}; | ||
}{{/isReadOnly}} | ||
|
||
{{/vars}} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
}{{#hasVars}} | ||
{{classname}} {{classVarName}} = ({{classname}}) o; | ||
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} && | ||
{{/hasMore}}{{/vars}}{{#parent}} && | ||
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}} | ||
return true;{{/hasVars}} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("class {{classname}} {\n"); | ||
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}} | ||
{{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n"); | ||
{{/vars}}sb.append("}"); | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Convert the given object to string with each line indented by 4 spaces | ||
* (except the first line). | ||
*/ | ||
private String toIndentedString(Object o) { | ||
if (o == null) { | ||
return "null"; | ||
} | ||
return o.toString().replace("\n", "\n "); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Animal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.swagger.client.model; | ||
|
||
import java.util.Objects; | ||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
|
||
/** | ||
* Animal | ||
*/ | ||
public class Animal { | ||
|
||
@SerializedName("className") | ||
private String className = null; | ||
|
||
|
||
|
||
/** | ||
**/ | ||
@ApiModelProperty(required = true, value = "") | ||
public String getClassName() { | ||
return className; | ||
} | ||
public void setClassName(String className) { | ||
this.className = className; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Animal animal = (Animal) o; | ||
return Objects.equals(this.className, animal.className); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(className); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("class Animal {\n"); | ||
|
||
sb.append(" className: ").append(toIndentedString(className)).append("\n"); | ||
sb.append("}"); | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Convert the given object to string with each line indented by 4 spaces | ||
* (except the first line). | ||
*/ | ||
private String toIndentedString(Object o) { | ||
if (o == null) { | ||
return "null"; | ||
} | ||
return o.toString().replace("\n", "\n "); | ||
} | ||
} | ||
|
88 changes: 88 additions & 0 deletions
88
samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Cat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.swagger.client.model; | ||
|
||
import java.util.Objects; | ||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import io.swagger.client.model.Animal; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
|
||
/** | ||
* Cat | ||
*/ | ||
public class Cat extends Animal { | ||
|
||
@SerializedName("className") | ||
private String className = null; | ||
|
||
@SerializedName("declawed") | ||
private Boolean declawed = null; | ||
|
||
|
||
|
||
/** | ||
**/ | ||
@ApiModelProperty(required = true, value = "") | ||
public String getClassName() { | ||
return className; | ||
} | ||
public void setClassName(String className) { | ||
this.className = className; | ||
} | ||
|
||
|
||
/** | ||
**/ | ||
@ApiModelProperty(value = "") | ||
public Boolean getDeclawed() { | ||
return declawed; | ||
} | ||
public void setDeclawed(Boolean declawed) { | ||
this.declawed = declawed; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Cat cat = (Cat) o; | ||
return Objects.equals(this.className, cat.className) && | ||
Objects.equals(this.declawed, cat.declawed) && | ||
super.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(className, declawed, super.hashCode()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("class Cat {\n"); | ||
sb.append(" ").append(toIndentedString(super.toString())).append("\n"); | ||
sb.append(" className: ").append(toIndentedString(className)).append("\n"); | ||
sb.append(" declawed: ").append(toIndentedString(declawed)).append("\n"); | ||
sb.append("}"); | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Convert the given object to string with each line indented by 4 spaces | ||
* (except the first line). | ||
*/ | ||
private String toIndentedString(Object o) { | ||
if (o == null) { | ||
return "null"; | ||
} | ||
return o.toString().replace("\n", "\n "); | ||
} | ||
} | ||
|
Oops, something went wrong.