-
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 #1790 from swagger-api/issue-1789
updated templates for pojos, enums
- Loading branch information
Showing
16 changed files
with
287 additions
and
187 deletions.
There are no files selected for viewing
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
6 changes: 1 addition & 5 deletions
6
modules/swagger-codegen/src/main/resources/Java/model.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
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
42 changes: 42 additions & 0 deletions
42
modules/swagger-codegen/src/main/resources/JavaInflector/StringUtil.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,42 @@ | ||
package {{invokerPackage}}; | ||
|
||
{{>generatedAnnotation}} | ||
public class StringUtil { | ||
/** | ||
* Check if the given array contains the given value (with case-insensitive comparison). | ||
* | ||
* @param array The array | ||
* @param value The value to search | ||
* @return true if the array contains the value | ||
*/ | ||
public static boolean containsIgnoreCase(String[] array, String value) { | ||
for (String str : array) { | ||
if (value == null && str == null) return true; | ||
if (value != null && value.equalsIgnoreCase(str)) return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Join an array of strings with the given separator. | ||
* <p> | ||
* Note: This might be replaced by utility method from commons-lang or guava someday | ||
* if one of those libraries is added as dependency. | ||
* </p> | ||
* | ||
* @param array The array of strings | ||
* @param separator The separator | ||
* @return the resulting string | ||
*/ | ||
public static String join(String[] array, String separator) { | ||
int len = array.length; | ||
if (len == 0) return ""; | ||
StringBuilder out = new StringBuilder(); | ||
out.append(array[0]); | ||
for (int i = 1; i < len; i++) { | ||
out.append(separator).append(array[i]); | ||
} | ||
return out.toString(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
modules/swagger-codegen/src/main/resources/JavaInflector/enumClass.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,17 @@ | ||
|
||
public enum {{{datatypeWithEnum}}} { | ||
{{#allowableValues}}{{#enumVars}}{{{name}}}("{{{value}}}"){{^-last}}, | ||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
|
||
private String value; | ||
|
||
{{{datatypeWithEnum}}}(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
@JsonValue | ||
public String toString() { | ||
return value; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
modules/swagger-codegen/src/main/resources/JavaInflector/enumOuterClass.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,3 @@ | ||
public enum {{classname}} { | ||
{{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{/allowableValues}} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
modules/swagger-codegen/src/main/resources/JavaInflector/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,68 @@ | ||
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}} | ||
{{>generatedAnnotation}} | ||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { | ||
{{#vars}}{{#isEnum}} | ||
|
||
{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}} | ||
|
||
{{>enumClass}}{{/items}}{{/items.isEnum}} | ||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} | ||
|
||
{{#vars}} | ||
/**{{#description}} | ||
* {{{description}}}{{/description}}{{#minimum}} | ||
* minimum: {{minimum}}{{/minimum}}{{#maximum}} | ||
* maximum: {{maximum}}{{/maximum}} | ||
**/ | ||
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}} | ||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") | ||
@JsonProperty("{{baseName}}") | ||
public {{{datatypeWithEnum}}} {{getter}}() { | ||
return {{name}}; | ||
} | ||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { | ||
this.{{name}} = {{name}}; | ||
} | ||
|
||
{{/vars}} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
{{classname}} {{classVarName}} = ({{classname}}) o;{{#hasVars}} | ||
return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#hasMore}} && | ||
{{/hasMore}}{{^hasMore}};{{/hasMore}}{{/vars}}{{/hasVars}}{{^hasVars}} | ||
return true;{{/hasVars}} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}); | ||
} | ||
|
||
@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 "); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/StringUtil.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,42 @@ | ||
package {{invokerPackage}}; | ||
|
||
{{>generatedAnnotation}} | ||
public class StringUtil { | ||
/** | ||
* Check if the given array contains the given value (with case-insensitive comparison). | ||
* | ||
* @param array The array | ||
* @param value The value to search | ||
* @return true if the array contains the value | ||
*/ | ||
public static boolean containsIgnoreCase(String[] array, String value) { | ||
for (String str : array) { | ||
if (value == null && str == null) return true; | ||
if (value != null && value.equalsIgnoreCase(str)) return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Join an array of strings with the given separator. | ||
* <p> | ||
* Note: This might be replaced by utility method from commons-lang or guava someday | ||
* if one of those libraries is added as dependency. | ||
* </p> | ||
* | ||
* @param array The array of strings | ||
* @param separator The separator | ||
* @return the resulting string | ||
*/ | ||
public static String join(String[] array, String separator) { | ||
int len = array.length; | ||
if (len == 0) return ""; | ||
StringBuilder out = new StringBuilder(); | ||
out.append(array[0]); | ||
for (int i = 1; i < len; i++) { | ||
out.append(separator).append(array[i]); | ||
} | ||
return out.toString(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/enumClass.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,17 @@ | ||
|
||
public enum {{{datatypeWithEnum}}} { | ||
{{#allowableValues}}{{#enumVars}}{{{name}}}("{{{value}}}"){{^-last}}, | ||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
|
||
private String value; | ||
|
||
{{{datatypeWithEnum}}}(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
@JsonValue | ||
public String toString() { | ||
return value; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/enumOuterClass.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,3 @@ | ||
public enum {{classname}} { | ||
{{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{/allowableValues}} | ||
} |
Oops, something went wrong.