forked from loafle/openapi-generator-original
Merge pull request #3235 from cbornet/common_java_models
Mutualize jackson and gson models in java clients
This commit is contained in:
commit
48bdae8fe7
@ -210,6 +210,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
importMapping.put("ApiModel", "io.swagger.annotations.ApiModel");
|
importMapping.put("ApiModel", "io.swagger.annotations.ApiModel");
|
||||||
importMapping.put("JsonProperty", "com.fasterxml.jackson.annotation.JsonProperty");
|
importMapping.put("JsonProperty", "com.fasterxml.jackson.annotation.JsonProperty");
|
||||||
importMapping.put("JsonValue", "com.fasterxml.jackson.annotation.JsonValue");
|
importMapping.put("JsonValue", "com.fasterxml.jackson.annotation.JsonValue");
|
||||||
|
importMapping.put("SerializedName", "com.google.gson.annotations.SerializedName");
|
||||||
importMapping.put("Objects", "java.util.Objects");
|
importMapping.put("Objects", "java.util.Objects");
|
||||||
importMapping.put("StringUtil", invokerPackage + ".StringUtil");
|
importMapping.put("StringUtil", invokerPackage + ".StringUtil");
|
||||||
|
|
||||||
|
@ -115,6 +115,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
|||||||
|
|
||||||
if ("feign".equals(getLibrary())) {
|
if ("feign".equals(getLibrary())) {
|
||||||
supportingFiles.add(new SupportingFile("FormAwareEncoder.mustache", invokerFolder, "FormAwareEncoder.java"));
|
supportingFiles.add(new SupportingFile("FormAwareEncoder.mustache", invokerFolder, "FormAwareEncoder.java"));
|
||||||
|
additionalProperties.put("jackson", "true");
|
||||||
} else if ("okhttp-gson".equals(getLibrary())) {
|
} else if ("okhttp-gson".equals(getLibrary())) {
|
||||||
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
|
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
|
||||||
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
|
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
|
||||||
@ -122,11 +123,16 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
|||||||
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
||||||
supportingFiles.add(new SupportingFile("ProgressRequestBody.mustache", invokerFolder, "ProgressRequestBody.java"));
|
supportingFiles.add(new SupportingFile("ProgressRequestBody.mustache", invokerFolder, "ProgressRequestBody.java"));
|
||||||
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
||||||
|
additionalProperties.put("gson", "true");
|
||||||
} else if (usesAnyRetrofitLibrary()) {
|
} else if (usesAnyRetrofitLibrary()) {
|
||||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||||
supportingFiles.add(new SupportingFile("CollectionFormats.mustache", invokerFolder, "CollectionFormats.java"));
|
supportingFiles.add(new SupportingFile("CollectionFormats.mustache", invokerFolder, "CollectionFormats.java"));
|
||||||
|
additionalProperties.put("gson", "true");
|
||||||
} else if("jersey2".equals(getLibrary())) {
|
} else if("jersey2".equals(getLibrary())) {
|
||||||
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
||||||
|
additionalProperties.put("jackson", "true");
|
||||||
|
} else if(StringUtils.isEmpty(getLibrary())) {
|
||||||
|
additionalProperties.put("jackson", "true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,12 +177,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
|||||||
if(!BooleanUtils.toBoolean(model.isEnum)) {
|
if(!BooleanUtils.toBoolean(model.isEnum)) {
|
||||||
final String lib = getLibrary();
|
final String lib = getLibrary();
|
||||||
//Needed imports for Jackson based libraries
|
//Needed imports for Jackson based libraries
|
||||||
if(StringUtils.isEmpty(lib) || "feign".equals(lib) || "jersey2".equals(lib)) {
|
if(additionalProperties.containsKey("jackson")) {
|
||||||
model.imports.add("JsonProperty");
|
model.imports.add("JsonProperty");
|
||||||
|
|
||||||
if(BooleanUtils.toBoolean(model.hasEnums)) {
|
|
||||||
model.imports.add("JsonValue");
|
|
||||||
}
|
}
|
||||||
|
if(additionalProperties.containsKey("gson")) {
|
||||||
|
model.imports.add("SerializedName");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,9 +189,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
||||||
objs = super.postProcessModelsEnum(objs);
|
objs = super.postProcessModelsEnum(objs);
|
||||||
String lib = getLibrary();
|
//Needed import for Gson based libraries
|
||||||
//Needed imports for Jackson based libraries
|
if (additionalProperties.containsKey("gson")) {
|
||||||
if (StringUtils.isEmpty(lib) || "feign".equals(lib) || "jersey2".equals(lib)) {
|
|
||||||
List<Map<String, String>> imports = (List<Map<String, String>>)objs.get("imports");
|
List<Map<String, String>> imports = (List<Map<String, String>>)objs.get("imports");
|
||||||
List<Object> models = (List<Object>) objs.get("models");
|
List<Object> models = (List<Object>) objs.get("models");
|
||||||
for (Object _mo : models) {
|
for (Object _mo : models) {
|
||||||
@ -194,9 +198,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
|||||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||||
// for enum model
|
// for enum model
|
||||||
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
|
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
|
||||||
cm.imports.add(importMapping.get("JsonValue"));
|
cm.imports.add(importMapping.get("SerializedName"));
|
||||||
Map<String, String> item = new HashMap<String, String>();
|
Map<String, String> item = new HashMap<String, String>();
|
||||||
item.put("import", importMapping.get("JsonValue"));
|
item.put("import", importMapping.get("SerializedName"));
|
||||||
imports.add(item);
|
imports.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
|
||||||
*/
|
|
||||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
|
||||||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
|
||||||
{{{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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
# {{classname}}
|
|
||||||
|
|
||||||
## Enum
|
|
||||||
|
|
||||||
{{#allowableValues}}{{#enumVars}}
|
|
||||||
* `{{name}}` (value: `{{{value}}}`)
|
|
||||||
{{/enumVars}}{{/allowableValues}}
|
|
@ -1,16 +0,0 @@
|
|||||||
{{>licenseInfo}}
|
|
||||||
|
|
||||||
package {{package}};
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
{{#imports}}import {{import}};
|
|
||||||
{{/imports}}
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
|
|
||||||
{{#models}}
|
|
||||||
{{#model}}
|
|
||||||
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>pojo}}{{/isEnum}}
|
|
||||||
{{/model}}
|
|
||||||
{{/models}}
|
|
@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
* {{^description}}Gets or Sets {{name}}{{/description}}{{#description}}{{description}}{{/description}}
|
|
||||||
*/
|
|
||||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
|
||||||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
|
||||||
{{{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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
|
||||||
*/
|
|
||||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
|
||||||
{{#allowableValues}}{{#enumVars}}@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
|
||||||
{{{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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
{{#models}}{{#model}}
|
|
||||||
{{#isEnum}}{{>libraries/okhttp-gson/enum_outer_doc}}{{/isEnum}}{{^isEnum}}{{>pojo_doc}}{{/isEnum}}
|
|
||||||
{{/model}}{{/models}}
|
|
@ -1,95 +0,0 @@
|
|||||||
/**
|
|
||||||
* {{#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/common/modelInnerEnum}}
|
|
||||||
{{/isEnum}}
|
|
||||||
{{#items.isEnum}}
|
|
||||||
{{#items}}
|
|
||||||
{{>libraries/common/modelInnerEnum}}
|
|
||||||
{{/items}}
|
|
||||||
{{/items.isEnum}}
|
|
||||||
@SerializedName("{{baseName}}")
|
|
||||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
|
|
||||||
{{/vars}}
|
|
||||||
|
|
||||||
{{#vars}}
|
|
||||||
/**
|
|
||||||
{{#description}}
|
|
||||||
* {{{description}}}
|
|
||||||
{{/description}}
|
|
||||||
{{^description}}
|
|
||||||
* Get {{name}}
|
|
||||||
{{/description}}
|
|
||||||
{{#minimum}}
|
|
||||||
* minimum: {{minimum}}
|
|
||||||
{{/minimum}}
|
|
||||||
{{#maximum}}
|
|
||||||
* maximum: {{maximum}}
|
|
||||||
{{/maximum}}
|
|
||||||
* @return {{name}}
|
|
||||||
**/
|
|
||||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
|
||||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
|
||||||
return {{name}};
|
|
||||||
}
|
|
||||||
|
|
||||||
{{^isReadOnly}}
|
|
||||||
/**
|
|
||||||
* Set {{name}}
|
|
||||||
*
|
|
||||||
* @param {{name}} {{name}}
|
|
||||||
*/
|
|
||||||
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).
|
|
||||||
*
|
|
||||||
* @param o Object to be converted to indented string
|
|
||||||
*/
|
|
||||||
private String toIndentedString(Object o) {
|
|
||||||
if (o == null) {
|
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
return o.toString().replace("\n", "\n ");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
package {{package}};
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
{{#imports}}import {{import}};
|
|
||||||
{{/imports}}
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
|
|
||||||
{{#models}}
|
|
||||||
|
|
||||||
{{#model}}{{#description}}
|
|
||||||
/**
|
|
||||||
* {{description}}
|
|
||||||
**/{{/description}}
|
|
||||||
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
|
|
||||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
|
||||||
{{#vars}}{{#isEnum}}
|
|
||||||
|
|
||||||
{{>libraries/common/modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
|
||||||
|
|
||||||
{{>libraries/common/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;
|
|
||||||
}
|
|
||||||
{{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 ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{/model}}
|
|
||||||
{{/models}}
|
|
@ -1,84 +0,0 @@
|
|||||||
package {{package}};
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
{{#imports}}import {{import}};
|
|
||||||
{{/imports}}
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
|
|
||||||
{{#models}}
|
|
||||||
|
|
||||||
{{#model}}{{#description}}
|
|
||||||
/**
|
|
||||||
* {{description}}
|
|
||||||
**/{{/description}}
|
|
||||||
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
|
|
||||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
|
||||||
{{#vars}}{{#isEnum}}
|
|
||||||
|
|
||||||
{{>libraries/common/modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
|
||||||
|
|
||||||
{{>libraries/common/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;
|
|
||||||
}
|
|
||||||
{{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 ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{/model}}
|
|
||||||
{{/models}}
|
|
@ -1,8 +1,10 @@
|
|||||||
|
{{>licenseInfo}}
|
||||||
|
|
||||||
package {{package}};
|
package {{package}};
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
{{#imports}}import {{import}};
|
{{#imports}}
|
||||||
|
import {{import}};
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
|
|
||||||
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
|
{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
|
||||||
|
@ -2,8 +2,17 @@
|
|||||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||||
*/
|
*/
|
||||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||||
{{#allowableValues}}{{#enumVars}}{{{name}}}({{{value}}}){{^-last}},
|
{{#gson}}
|
||||||
|
{{#allowableValues}}{{#enumVars}}
|
||||||
|
@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||||
|
{{{name}}}({{{value}}}){{^-last}},
|
||||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||||
|
{{/gson}}
|
||||||
|
{{^gson}}
|
||||||
|
{{#allowableValues}}{{#enumVars}}
|
||||||
|
{{{name}}}({{{value}}}){{^-last}},
|
||||||
|
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||||
|
{{/gson}}
|
||||||
|
|
||||||
private {{dataType}} value;
|
private {{dataType}} value;
|
||||||
|
|
||||||
@ -12,7 +21,6 @@ public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@JsonValue
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.valueOf(value);
|
return String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,32 @@
|
|||||||
/**
|
/**
|
||||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||||
*/
|
*/
|
||||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||||
{{#allowableValues}}{{#enumVars}}{{{name}}}({{{value}}}){{^-last}},
|
{{#gson}}
|
||||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
{{#allowableValues}}
|
||||||
|
{{#enumVars}}
|
||||||
|
@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||||
|
{{{name}}}({{{value}}}){{^-last}},
|
||||||
|
{{/-last}}{{#-last}};{{/-last}}
|
||||||
|
{{/enumVars}}
|
||||||
|
{{/allowableValues}}
|
||||||
|
{{/gson}}
|
||||||
|
{{^gson}}
|
||||||
|
{{#allowableValues}}
|
||||||
|
{{#enumVars}}
|
||||||
|
{{{name}}}({{{value}}}){{^-last}},
|
||||||
|
{{/-last}}{{#-last}};{{/-last}}
|
||||||
|
{{/enumVars}}
|
||||||
|
{{/allowableValues}}
|
||||||
|
{{/gson}}
|
||||||
|
|
||||||
private {{datatype}} value;
|
private {{{datatype}}} value;
|
||||||
|
|
||||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
|
{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{datatype}}} value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@JsonValue
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.valueOf(value);
|
return String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
@ -4,33 +4,60 @@
|
|||||||
@ApiModel(description = "{{{description}}}"){{/description}}
|
@ApiModel(description = "{{{description}}}"){{/description}}
|
||||||
{{>generatedAnnotation}}
|
{{>generatedAnnotation}}
|
||||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
||||||
{{#vars}}{{#isEnum}}
|
{{#vars}}
|
||||||
|
{{#isEnum}}
|
||||||
|
{{>modelInnerEnum}}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{#items.isEnum}}
|
||||||
|
{{#items}}
|
||||||
|
{{>modelInnerEnum}}
|
||||||
|
{{/items}}
|
||||||
|
{{/items.isEnum}}
|
||||||
|
{{#jackson}}
|
||||||
|
@JsonProperty("{{baseName}}")
|
||||||
|
{{/jackson}}
|
||||||
|
{{#gson}}
|
||||||
|
@SerializedName("{{baseName}}")
|
||||||
|
{{/gson}}
|
||||||
|
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
|
||||||
|
|
||||||
{{>modelInnerEnum}}{{/isEnum}}{{#items.isEnum}}{{#items}}
|
{{/vars}}
|
||||||
|
{{#vars}}
|
||||||
{{>modelInnerEnum}}{{/items}}{{/items.isEnum}}
|
{{^isReadOnly}}
|
||||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}}
|
|
||||||
|
|
||||||
{{#vars}}{{^isReadOnly}}
|
|
||||||
/**{{#description}}
|
|
||||||
* {{{description}}}{{/description}}{{#minimum}}
|
|
||||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
|
||||||
* maximum: {{maximum}}{{/maximum}}
|
|
||||||
**/
|
|
||||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||||
this.{{name}} = {{name}};
|
this.{{name}} = {{name}};
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
{{/isReadOnly}}{{#vendorExtensions.extraAnnotation}}
|
|
||||||
{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
{{/isReadOnly}}
|
||||||
|
/**
|
||||||
|
{{#description}}
|
||||||
|
* {{{description}}}
|
||||||
|
{{/description}}
|
||||||
|
{{^description}}
|
||||||
|
* Get {{name}}
|
||||||
|
{{/description}}
|
||||||
|
{{#minimum}}
|
||||||
|
* minimum: {{minimum}}
|
||||||
|
{{/minimum}}
|
||||||
|
{{#maximum}}
|
||||||
|
* maximum: {{maximum}}
|
||||||
|
{{/maximum}}
|
||||||
|
* @return {{name}}
|
||||||
|
**/
|
||||||
|
{{#vendorExtensions.extraAnnotation}}
|
||||||
|
{{vendorExtensions.extraAnnotation}}
|
||||||
|
{{/vendorExtensions.extraAnnotation}}
|
||||||
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||||
@JsonProperty("{{baseName}}")
|
|
||||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||||
return {{name}};
|
return {{name}};
|
||||||
}{{^isReadOnly}}
|
}
|
||||||
|
{{^isReadOnly}}
|
||||||
|
|
||||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||||
this.{{name}} = {{name}};
|
this.{{name}} = {{name}};
|
||||||
}{{/isReadOnly}}
|
}
|
||||||
|
{{/isReadOnly}}
|
||||||
|
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user