Skip to content

Commit 026c93a

Browse files
committed
fixed models
1 parent 15fde46 commit 026c93a

File tree

8 files changed

+129
-82
lines changed

8 files changed

+129
-82
lines changed

modules/swagger-codegen/src/main/resources/JavaJaxRS/model.mustache

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@ package {{package}};
44
{{/imports}}
55

66
import com.wordnik.swagger.annotations.*;
7+
import com.fasterxml.jackson.annotation.JsonProperty;
78
{{#models}}
89

910
{{#model}}{{#description}}
1011
/**
1112
* {{description}}
1213
**/{{/description}}
1314
@ApiModel(description = "{{{description}}}")
14-
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{#vars}}
15+
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
16+
{{#vars}}{{#isEnum}}
17+
public enum {{datatypeWithEnum}} {
18+
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
19+
};
20+
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
21+
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
22+
23+
{{#vars}}
1524
/**{{#description}}
1625
* {{{description}}}{{/description}}{{#minimum}}
1726
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
1827
* maximum: {{maximum}}{{/maximum}}
1928
**/
20-
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{#isEnum}}
21-
22-
public enum {{datatype}} { {{#_enum}}{{.}}{{^-last}}, {{/-last}}{{/_enum}} };
23-
{{/isEnum}}{{/vars}}
24-
25-
{{#vars}}
2629
@ApiModelProperty(required = {{required}}, value = "{{{description}}}")
27-
public {{{datatype}}} {{getter}}() {
30+
@JsonProperty("{{name}}")
31+
public {{{datatypeWithEnum}}} {{getter}}() {
2832
return {{name}};
2933
}
30-
public void {{setter}}({{{datatype}}} {{name}}) {
34+
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
3135
this.{{name}} = {{name}};
3236
}
3337

@@ -44,4 +48,4 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{#vars}
4448
}
4549
}
4650
{{/model}}
47-
{{/models}}
51+
{{/models}}

samples/dynamic-html/docs/operations/PetApi.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ <h3 class="section">Parameters</h3>
207207

208208

209209

210+
<p class="param-description">ID of pet to update</p>
211+
</div>
212+
213+
<div class="parameter">
214+
215+
216+
217+
210218
<p class="param-description">Additional data to pass to server</p>
211219
</div>
212220

samples/server/petstore/jaxrs/src/main/java/io/swagger/api/PetApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public Response deletePet(@ApiParam(value = "" )@HeaderParam("api_key") String
152152
@ApiOperation(value = "uploads an image", notes = "", response = Void.class)
153153
@ApiResponses(value = { })
154154

155-
public Response uploadFile(@ApiParam(value = "Additional data to pass to server" )@FormParam("additionalMetadata") String additionalMetadata,
155+
public Response uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathParam("petId") Long petId,
156+
@ApiParam(value = "Additional data to pass to server" )@FormParam("additionalMetadata") String additionalMetadata,
156157
@ApiParam(value = "file to upload") @FormDataParam("file") InputStream inputStream,
157158
@ApiParam(value = "file detail") @FormDataParam("file") FormDataContentDisposition fileDetail)
158159
throws NotFoundException {

samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Category.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33

44
import com.wordnik.swagger.annotations.*;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
56

67

78
@ApiModel(description = "")
8-
public class Category {
9-
/**
10-
**/
9+
public class Category {
10+
1111
private Long id = null;
12-
/**
13-
**/
1412
private String name = null;
13+
1514

16-
15+
/**
16+
**/
1717
@ApiModelProperty(required = false, value = "")
18+
@JsonProperty("id")
1819
public Long getId() {
1920
return id;
2021
}
@@ -23,7 +24,10 @@ public void setId(Long id) {
2324
}
2425

2526

27+
/**
28+
**/
2629
@ApiModelProperty(required = false, value = "")
30+
@JsonProperty("name")
2731
public String getName() {
2832
return name;
2933
}

samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Order.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,27 @@
33
import java.util.Date;
44

55
import com.wordnik.swagger.annotations.*;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
67

78

89
@ApiModel(description = "")
9-
public class Order {
10-
/**
11-
**/
10+
public class Order {
11+
1212
private Long id = null;
13-
/**
14-
**/
1513
private Long petId = null;
16-
/**
17-
**/
1814
private Integer quantity = null;
19-
/**
20-
**/
2115
private Date shipDate = null;
22-
/**
23-
* Order Status
24-
**/
25-
private String status = null;
26-
27-
public enum String { placed, approved, delivered };
16+
public enum StatusEnum {
17+
placed, approved, delivered,
18+
};
19+
private StatusEnum status = null;
20+
private Boolean complete = null;
21+
2822

2923
/**
3024
**/
31-
private Boolean complete = null;
32-
33-
3425
@ApiModelProperty(required = false, value = "")
26+
@JsonProperty("id")
3527
public Long getId() {
3628
return id;
3729
}
@@ -40,7 +32,10 @@ public void setId(Long id) {
4032
}
4133

4234

35+
/**
36+
**/
4337
@ApiModelProperty(required = false, value = "")
38+
@JsonProperty("petId")
4439
public Long getPetId() {
4540
return petId;
4641
}
@@ -49,7 +44,10 @@ public void setPetId(Long petId) {
4944
}
5045

5146

47+
/**
48+
**/
5249
@ApiModelProperty(required = false, value = "")
50+
@JsonProperty("quantity")
5351
public Integer getQuantity() {
5452
return quantity;
5553
}
@@ -58,7 +56,10 @@ public void setQuantity(Integer quantity) {
5856
}
5957

6058

59+
/**
60+
**/
6161
@ApiModelProperty(required = false, value = "")
62+
@JsonProperty("shipDate")
6263
public Date getShipDate() {
6364
return shipDate;
6465
}
@@ -67,16 +68,23 @@ public void setShipDate(Date shipDate) {
6768
}
6869

6970

71+
/**
72+
* Order Status
73+
**/
7074
@ApiModelProperty(required = false, value = "Order Status")
71-
public String getStatus() {
75+
@JsonProperty("status")
76+
public StatusEnum getStatus() {
7277
return status;
7378
}
74-
public void setStatus(String status) {
79+
public void setStatus(StatusEnum status) {
7580
this.status = status;
7681
}
7782

7883

84+
/**
85+
**/
7986
@ApiModelProperty(required = false, value = "")
87+
@JsonProperty("complete")
8088
public Boolean getComplete() {
8189
return complete;
8290
}

samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Pet.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,27 @@
55
import io.swagger.model.Tag;
66

77
import com.wordnik.swagger.annotations.*;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
89

910

1011
@ApiModel(description = "")
11-
public class Pet {
12-
/**
13-
**/
12+
public class Pet {
13+
1414
private Long id = null;
15-
/**
16-
**/
1715
private Category category = null;
18-
/**
19-
**/
2016
private String name = null;
21-
/**
22-
**/
2317
private List<String> photoUrls = new ArrayList<String>() ;
24-
/**
25-
**/
2618
private List<Tag> tags = new ArrayList<Tag>() ;
19+
public enum StatusEnum {
20+
available, pending, sold,
21+
};
22+
private StatusEnum status = null;
23+
24+
2725
/**
28-
* pet status in the store
2926
**/
30-
private String status = null;
31-
32-
public enum String { available, pending, sold };
33-
34-
35-
3627
@ApiModelProperty(required = false, value = "")
28+
@JsonProperty("id")
3729
public Long getId() {
3830
return id;
3931
}
@@ -42,7 +34,10 @@ public void setId(Long id) {
4234
}
4335

4436

37+
/**
38+
**/
4539
@ApiModelProperty(required = false, value = "")
40+
@JsonProperty("category")
4641
public Category getCategory() {
4742
return category;
4843
}
@@ -51,7 +46,10 @@ public void setCategory(Category category) {
5146
}
5247

5348

49+
/**
50+
**/
5451
@ApiModelProperty(required = true, value = "")
52+
@JsonProperty("name")
5553
public String getName() {
5654
return name;
5755
}
@@ -60,7 +58,10 @@ public void setName(String name) {
6058
}
6159

6260

61+
/**
62+
**/
6363
@ApiModelProperty(required = true, value = "")
64+
@JsonProperty("photoUrls")
6465
public List<String> getPhotoUrls() {
6566
return photoUrls;
6667
}
@@ -69,7 +70,10 @@ public void setPhotoUrls(List<String> photoUrls) {
6970
}
7071

7172

73+
/**
74+
**/
7275
@ApiModelProperty(required = false, value = "")
76+
@JsonProperty("tags")
7377
public List<Tag> getTags() {
7478
return tags;
7579
}
@@ -78,11 +82,15 @@ public void setTags(List<Tag> tags) {
7882
}
7983

8084

85+
/**
86+
* pet status in the store
87+
**/
8188
@ApiModelProperty(required = false, value = "pet status in the store")
82-
public String getStatus() {
89+
@JsonProperty("status")
90+
public StatusEnum getStatus() {
8391
return status;
8492
}
85-
public void setStatus(String status) {
93+
public void setStatus(StatusEnum status) {
8694
this.status = status;
8795
}
8896

samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Tag.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33

44
import com.wordnik.swagger.annotations.*;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
56

67

78
@ApiModel(description = "")
8-
public class Tag {
9-
/**
10-
**/
9+
public class Tag {
10+
1111
private Long id = null;
12-
/**
13-
**/
1412
private String name = null;
13+
1514

16-
15+
/**
16+
**/
1717
@ApiModelProperty(required = false, value = "")
18+
@JsonProperty("id")
1819
public Long getId() {
1920
return id;
2021
}
@@ -23,7 +24,10 @@ public void setId(Long id) {
2324
}
2425

2526

27+
/**
28+
**/
2629
@ApiModelProperty(required = false, value = "")
30+
@JsonProperty("name")
2731
public String getName() {
2832
return name;
2933
}

0 commit comments

Comments
 (0)