-
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.
improve enum support in java okhttp-gson client
- Loading branch information
Showing
21 changed files
with
513 additions
and
253 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
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
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
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
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
Oops, something went wrong.