[JAXRS-CXF] [issue #4386] add builder-style methods to model classes (#4468)

* [JAXRS-CXF] [issue #4386] add builder-style methods to model classes

before this change, model classes had only a default constructor and
setter methods, resulting in code like this:

    myModel = MyModel();
    myModel.setFirstField(firstField);
    myModel.setSecondField(secondField);
    return myModel;

this change adds builder style methods, such that the above code can be
written more compactly:

    return MyModel().firstField(firstField).secondField(secondField);

this is consistent with other JAVA generators in swagger-codegen.

* update jaxrs-cxf sample code
This commit is contained in:
Matan Rubin 2017-01-31 17:07:12 +02:00 committed by wing328
parent ee857d1be3
commit 8042f5ca3e
7 changed files with 222 additions and 0 deletions

View File

@ -52,9 +52,32 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
{{^isReadOnly}}
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
return this;
}
{{#isListContainer}}
public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
this.{{name}}.add({{name}}Item);
return this;
}
{{/isListContainer}}
{{#isMapContainer}}
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
this.{{name}}.put(key, {{name}}Item);
return this;
}
{{/isMapContainer}}
{{/isReadOnly}}
{{/vars}}
@Override

View File

@ -26,9 +26,16 @@ public class Category {
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Category id(Long id) {
this.id = id;
return this;
}
/**
* Get name
* @return name
@ -36,10 +43,17 @@ public class Category {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Category name(String name) {
this.name = name;
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@ -28,9 +28,16 @@ public class ModelApiResponse {
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public ModelApiResponse code(Integer code) {
this.code = code;
return this;
}
/**
* Get type
* @return type
@ -38,9 +45,16 @@ public class ModelApiResponse {
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public ModelApiResponse type(String type) {
this.type = type;
return this;
}
/**
* Get message
* @return message
@ -48,10 +62,17 @@ public class ModelApiResponse {
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public ModelApiResponse message(String message) {
this.message = message;
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@ -67,9 +67,16 @@ public enum StatusEnum {
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Order id(Long id) {
this.id = id;
return this;
}
/**
* Get petId
* @return petId
@ -77,9 +84,16 @@ public enum StatusEnum {
public Long getPetId() {
return petId;
}
public void setPetId(Long petId) {
this.petId = petId;
}
public Order petId(Long petId) {
this.petId = petId;
return this;
}
/**
* Get quantity
* @return quantity
@ -87,9 +101,16 @@ public enum StatusEnum {
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public Order quantity(Integer quantity) {
this.quantity = quantity;
return this;
}
/**
* Get shipDate
* @return shipDate
@ -97,9 +118,16 @@ public enum StatusEnum {
public javax.xml.datatype.XMLGregorianCalendar getShipDate() {
return shipDate;
}
public void setShipDate(javax.xml.datatype.XMLGregorianCalendar shipDate) {
this.shipDate = shipDate;
}
public Order shipDate(javax.xml.datatype.XMLGregorianCalendar shipDate) {
this.shipDate = shipDate;
return this;
}
/**
* Order Status
* @return status
@ -107,9 +135,16 @@ public enum StatusEnum {
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
public Order status(StatusEnum status) {
this.status = status;
return this;
}
/**
* Get complete
* @return complete
@ -117,10 +152,17 @@ public enum StatusEnum {
public Boolean getComplete() {
return complete;
}
public void setComplete(Boolean complete) {
this.complete = complete;
}
public Order complete(Boolean complete) {
this.complete = complete;
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@ -71,9 +71,16 @@ public enum StatusEnum {
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Pet id(Long id) {
this.id = id;
return this;
}
/**
* Get category
* @return category
@ -81,9 +88,16 @@ public enum StatusEnum {
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public Pet category(Category category) {
this.category = category;
return this;
}
/**
* Get name
* @return name
@ -91,9 +105,16 @@ public enum StatusEnum {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Pet name(String name) {
this.name = name;
return this;
}
/**
* Get photoUrls
* @return photoUrls
@ -101,9 +122,21 @@ public enum StatusEnum {
public List<String> getPhotoUrls() {
return photoUrls;
}
public void setPhotoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
}
public Pet photoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
}
public Pet addPhotoUrlsItem(String photoUrlsItem) {
this.photoUrls.add(photoUrlsItem);
return this;
}
/**
* Get tags
* @return tags
@ -111,9 +144,21 @@ public enum StatusEnum {
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
public Pet tags(List<Tag> tags) {
this.tags = tags;
return this;
}
public Pet addTagsItem(Tag tagsItem) {
this.tags.add(tagsItem);
return this;
}
/**
* pet status in the store
* @return status
@ -121,10 +166,17 @@ public enum StatusEnum {
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
public Pet status(StatusEnum status) {
this.status = status;
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@ -26,9 +26,16 @@ public class Tag {
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Tag id(Long id) {
this.id = id;
return this;
}
/**
* Get name
* @return name
@ -36,10 +43,17 @@ public class Tag {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Tag name(String name) {
this.name = name;
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@ -38,9 +38,16 @@ public class User {
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User id(Long id) {
this.id = id;
return this;
}
/**
* Get username
* @return username
@ -48,9 +55,16 @@ public class User {
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public User username(String username) {
this.username = username;
return this;
}
/**
* Get firstName
* @return firstName
@ -58,9 +72,16 @@ public class User {
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public User firstName(String firstName) {
this.firstName = firstName;
return this;
}
/**
* Get lastName
* @return lastName
@ -68,9 +89,16 @@ public class User {
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public User lastName(String lastName) {
this.lastName = lastName;
return this;
}
/**
* Get email
* @return email
@ -78,9 +106,16 @@ public class User {
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public User email(String email) {
this.email = email;
return this;
}
/**
* Get password
* @return password
@ -88,9 +123,16 @@ public class User {
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public User password(String password) {
this.password = password;
return this;
}
/**
* Get phone
* @return phone
@ -98,9 +140,16 @@ public class User {
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public User phone(String phone) {
this.phone = phone;
return this;
}
/**
* User Status
* @return userStatus
@ -108,10 +157,17 @@ public class User {
public Integer getUserStatus() {
return userStatus;
}
public void setUserStatus(Integer userStatus) {
this.userStatus = userStatus;
}
public User userStatus(Integer userStatus) {
this.userStatus = userStatus;
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();