Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Do not generate setter method for readonly properties #2206

Merged
merged 2 commits into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
}{{^isReadOnly}}
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
}
}{{/isReadOnly}}

{{/vars}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
}{{^isReadOnly}}
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
}
}{{/isReadOnly}}

{{/vars}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
}{{^isReadOnly}}
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
}
}{{/isReadOnly}}

{{/vars}}

Expand Down
10 changes: 5 additions & 5 deletions modules/swagger-codegen/src/main/resources/Java/pojo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
{{>enumClass}}{{/items}}{{/items.isEnum}}
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}}

{{#vars}}
{{#vars}}{{^isReadOnly}}
/**{{#description}}
* {{{description}}}{{/description}}{{#minimum}}
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
Expand All @@ -18,16 +18,16 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
this.{{name}} = {{name}};
return this;
}

{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
{{/isReadOnly}}{{#vendorExtensions.extraAnnotation}}
{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
@JsonProperty("{{baseName}}")
public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
}{{^isReadOnly}}
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
}
}{{/isReadOnly}}

{{/vars}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-22T14:59:49.052+08:00")
public class Category {

private Long id = null;
Expand All @@ -22,7 +22,6 @@ public Category id(Long id) {
this.id = id;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("id")
Expand All @@ -40,7 +39,6 @@ public Category name(String name) {
this.name = name;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@



@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-22T14:59:49.052+08:00")
public class Order {

private Long id = null;
Expand Down Expand Up @@ -42,22 +42,11 @@ public String toString() {
private Boolean complete = null;


/**
**/
public Order id(Long id) {
this.id = id;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}


/**
Expand All @@ -66,7 +55,6 @@ public Order petId(Long petId) {
this.petId = petId;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("petId")
Expand All @@ -84,7 +72,6 @@ public Order quantity(Integer quantity) {
this.quantity = quantity;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("quantity")
Expand All @@ -102,7 +89,6 @@ public Order shipDate(Date shipDate) {
this.shipDate = shipDate;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("shipDate")
Expand All @@ -121,7 +107,6 @@ public Order status(StatusEnum status) {
this.status = status;
return this;
}


@ApiModelProperty(example = "null", value = "Order Status")
@JsonProperty("status")
Expand All @@ -139,7 +124,6 @@ public Order complete(Boolean complete) {
this.complete = complete;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("complete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-22T14:59:49.052+08:00")
public class Pet {

private Long id = null;
Expand Down Expand Up @@ -51,7 +51,6 @@ public Pet id(Long id) {
this.id = id;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("id")
Expand All @@ -69,7 +68,6 @@ public Pet category(Category category) {
this.category = category;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("category")
Expand All @@ -87,7 +85,6 @@ public Pet name(String name) {
this.name = name;
return this;
}


@ApiModelProperty(example = "doggie", required = true, value = "")
@JsonProperty("name")
Expand All @@ -105,7 +102,6 @@ public Pet photoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
}


@ApiModelProperty(example = "null", required = true, value = "")
@JsonProperty("photoUrls")
Expand All @@ -123,7 +119,6 @@ public Pet tags(List<Tag> tags) {
this.tags = tags;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("tags")
Expand All @@ -142,7 +137,6 @@ public Pet status(StatusEnum status) {
this.status = status;
return this;
}


@ApiModelProperty(example = "null", value = "pet status in the store")
@JsonProperty("status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-22T14:59:49.052+08:00")
public class Tag {

private Long id = null;
Expand All @@ -22,7 +22,6 @@ public Tag id(Long id) {
this.id = id;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("id")
Expand All @@ -40,7 +39,6 @@ public Tag name(String name) {
this.name = name;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-22T14:59:49.052+08:00")
public class User {

private Long id = null;
Expand All @@ -28,7 +28,6 @@ public User id(Long id) {
this.id = id;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("id")
Expand All @@ -46,7 +45,6 @@ public User username(String username) {
this.username = username;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("username")
Expand All @@ -64,7 +62,6 @@ public User firstName(String firstName) {
this.firstName = firstName;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("firstName")
Expand All @@ -82,7 +79,6 @@ public User lastName(String lastName) {
this.lastName = lastName;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("lastName")
Expand All @@ -100,7 +96,6 @@ public User email(String email) {
this.email = email;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("email")
Expand All @@ -118,7 +113,6 @@ public User password(String password) {
this.password = password;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("password")
Expand All @@ -136,7 +130,6 @@ public User phone(String phone) {
this.phone = phone;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("phone")
Expand All @@ -155,7 +148,6 @@ public User userStatus(Integer userStatus) {
this.userStatus = userStatus;
return this;
}


@ApiModelProperty(example = "null", value = "User Status")
@JsonProperty("userStatus")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.swagger.client.auth.*;
import io.swagger.client.model.*;

import java.lang.reflect.Field;
import java.util.Map;
import java.text.SimpleDateFormat;

Expand Down Expand Up @@ -65,13 +66,20 @@ public void testDeleteOrder() throws Exception {

private Order createOrder() {
Order order = new Order();
order.setId(TestUtils.nextId());
order.setPetId(new Long(200));
order.setQuantity(new Integer(13));
order.setShipDate(new java.util.Date());
order.setStatus(Order.StatusEnum.PLACED);
order.setComplete(true);

try {
Field idField = Order.class.getDeclaredField("id");
idField.setAccessible(true);
idField.set(order, TestUtils.nextId());
} catch (Exception e) {
throw new RuntimeException(e);
}

return order;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:23.375+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-22T15:32:23.465+08:00")
public class Category {

private Long id = null;
Expand All @@ -22,7 +22,6 @@ public Category id(Long id) {
this.id = id;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("id")
Expand All @@ -40,7 +39,6 @@ public Category name(String name) {
this.name = name;
return this;
}


@ApiModelProperty(example = "null", value = "")
@JsonProperty("name")
Expand Down
Loading