forked from loafle/openapi-generator-original
* Add configuration to split input and output bean validations. When useBeanValidation is used, the variable are created in the application.conf file and can be tweaked by environment. For example, dev and stage can have true to both but only have input in prod. * Refactor of mustache tags for more clarity * sample generation with refactor * Fix a couple of bugs with the fake-endpoint yaml but there is still 2 cases where it doesn't work.
138 lines
3.7 KiB
Plaintext
138 lines
3.7 KiB
Plaintext
import java.util.Objects;
|
|
{{#useBeanValidation}}
|
|
import javax.validation.constraints.*;
|
|
{{/useBeanValidation}}
|
|
/**
|
|
* {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
|
|
*/
|
|
{{>generatedAnnotation}}
|
|
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
|
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
|
|
{{#vars}}
|
|
{{#isEnum}}
|
|
{{^isContainer}}
|
|
{{>enumClass}}
|
|
{{/isContainer}}
|
|
{{/isEnum}}
|
|
{{#items.isEnum}}
|
|
{{#items}}
|
|
{{^isContainer}}
|
|
{{>enumClass}}
|
|
{{/isContainer}}
|
|
{{/items}}
|
|
{{/items.isEnum}}
|
|
{{#jackson}}
|
|
@JsonProperty("{{baseName}}")
|
|
{{/jackson}}
|
|
{{#gson}}
|
|
@SerializedName("{{baseName}}")
|
|
{{/gson}}
|
|
{{#isContainer}}
|
|
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
|
|
{{/isContainer}}
|
|
{{^isContainer}}
|
|
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
|
|
{{/isContainer}}
|
|
|
|
{{/vars}}
|
|
{{#vars}}
|
|
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
|
this.{{name}} = {{name}};
|
|
return this;
|
|
}
|
|
{{#isListContainer}}
|
|
|
|
public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
|
{{^required}}
|
|
if ({{name}} == null) {
|
|
{{name}} = {{{defaultValue}}};
|
|
}
|
|
{{/required}}
|
|
{{name}}.add({{name}}Item);
|
|
return this;
|
|
}
|
|
{{/isListContainer}}
|
|
{{#isMapContainer}}
|
|
|
|
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
|
|
{{^required}}
|
|
if (this.{{name}} == null) {
|
|
this.{{name}} = {{{defaultValue}}};
|
|
}
|
|
{{/required}}
|
|
this.{{name}}.put(key, {{name}}Item);
|
|
return this;
|
|
}
|
|
{{/isMapContainer}}
|
|
|
|
/**
|
|
{{#description}}
|
|
* {{{description}}}
|
|
{{/description}}
|
|
{{^description}}
|
|
* Get {{name}}
|
|
{{/description}}
|
|
{{#minimum}}
|
|
* minimum: {{minimum}}
|
|
{{/minimum}}
|
|
{{#maximum}}
|
|
* maximum: {{maximum}}
|
|
{{/maximum}}
|
|
* @return {{name}}
|
|
**/
|
|
{{#vendorExtensions.extraAnnotation}}
|
|
{{{vendorExtensions.extraAnnotation}}}
|
|
{{/vendorExtensions.extraAnnotation}}
|
|
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() {
|
|
return {{name}};
|
|
}
|
|
|
|
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
|
this.{{name}} = {{name}};
|
|
}
|
|
|
|
{{/vars}}
|
|
|
|
@Override
|
|
public boolean equals(java.lang.Object o) {
|
|
if (this == o) {
|
|
return true;
|
|
}
|
|
if (o == null || getClass() != o.getClass()) {
|
|
return false;
|
|
}{{#hasVars}}
|
|
{{classname}} {{classVarName}} = ({{classname}}) o;
|
|
return {{#vars}}Objects.equals({{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}});
|
|
}
|
|
|
|
@SuppressWarnings("StringBufferReplaceableByString")
|
|
@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(java.lang.Object o) {
|
|
if (o == null) {
|
|
return "null";
|
|
}
|
|
return o.toString().replace("\n", "\n ");
|
|
}
|
|
}
|