Skip to content

Commit 930b1ea

Browse files
committed
updated java example
1 parent 8e8e530 commit 930b1ea

File tree

7 files changed

+175
-64
lines changed

7 files changed

+175
-64
lines changed

samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/PetApi.java

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.wordnik.client.ApiException;
44
import com.wordnik.client.ApiInvoker;
5+
import java.io.File;
56
import com.wordnik.petstore.model.Pet;
67
import java.util.*;
78

@@ -21,7 +22,7 @@ public String getBasePath() {
2122
return basePath;
2223
}
2324

24-
public Pet getPetById (String petId) throws ApiException {
25+
public Pet getPetById (Long petId) throws ApiException {
2526
// create path and map variables
2627
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
2728

@@ -83,6 +84,95 @@ public void deletePet (String petId) throws ApiException {
8384
}
8485
}
8586
}
87+
public List<Pet> partialUpdate (String petId, Pet body) throws ApiException {
88+
// create path and map variables
89+
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
90+
91+
// query params
92+
Map<String, String> queryParams = new HashMap<String, String>();
93+
Map<String, String> headerParams = new HashMap<String, String>();
94+
95+
// verify required params are set
96+
if(petId == null || body == null ) {
97+
throw new ApiException(400, "missing required params");
98+
}
99+
String contentType = "application/json";
100+
101+
try {
102+
String response = apiInvoker.invokeAPI(basePath, path, "PATCH", queryParams, body, headerParams, contentType);
103+
if(response != null){
104+
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
105+
}
106+
else {
107+
return null;
108+
}
109+
} catch (ApiException ex) {
110+
if(ex.getCode() == 404) {
111+
return null;
112+
}
113+
else {
114+
throw ex;
115+
}
116+
}
117+
}
118+
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
119+
// create path and map variables
120+
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
121+
122+
// query params
123+
Map<String, String> queryParams = new HashMap<String, String>();
124+
Map<String, String> headerParams = new HashMap<String, String>();
125+
126+
// verify required params are set
127+
if(petId == null ) {
128+
throw new ApiException(400, "missing required params");
129+
}
130+
String contentType = "application/json";
131+
132+
try {
133+
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, null, headerParams, contentType);
134+
if(response != null){
135+
return ;
136+
}
137+
else {
138+
return ;
139+
}
140+
} catch (ApiException ex) {
141+
if(ex.getCode() == 404) {
142+
return ;
143+
}
144+
else {
145+
throw ex;
146+
}
147+
}
148+
}
149+
public void uploadFile (String additionalMetadata, File body) throws ApiException {
150+
// create path and map variables
151+
String path = "/pet/uploadImage".replaceAll("\\{format\\}","json");
152+
153+
// query params
154+
Map<String, String> queryParams = new HashMap<String, String>();
155+
Map<String, String> headerParams = new HashMap<String, String>();
156+
157+
String contentType = "application/json";
158+
159+
try {
160+
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
161+
if(response != null){
162+
return ;
163+
}
164+
else {
165+
return ;
166+
}
167+
} catch (ApiException ex) {
168+
if(ex.getCode() == 404) {
169+
return ;
170+
}
171+
else {
172+
throw ex;
173+
}
174+
}
175+
}
86176
public void addPet (Pet body) throws ApiException {
87177
// create path and map variables
88178
String path = "/pet".replaceAll("\\{format\\}","json");
@@ -164,7 +254,7 @@ public List<Pet> findPetsByStatus (String status) throws ApiException {
164254
try {
165255
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
166256
if(response != null){
167-
return (List<Pet>) ApiInvoker.deserialize(response, "array", Pet.class);
257+
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
168258
}
169259
else {
170260
return null;
@@ -197,7 +287,7 @@ public List<Pet> findPetsByTags (String tags) throws ApiException {
197287
try {
198288
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
199289
if(response != null){
200-
return (List<Pet>) ApiInvoker.deserialize(response, "array", Pet.class);
290+
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
201291
}
202292
else {
203293
return null;

samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Category.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
package com.wordnik.petstore.model;
22

33
public class Category {
4-
private String name = null;
4+
/* Category unique identifier */
55
private Long id = null;
6-
public String getName() {
7-
return name;
8-
}
9-
public void setName(String name) {
10-
this.name = name;
11-
}
12-
6+
/* Name of the category */
7+
private String name = null;
138
public Long getId() {
149
return id;
1510
}
1611
public void setId(Long id) {
1712
this.id = id;
1813
}
1914

15+
public String getName() {
16+
return name;
17+
}
18+
public void setName(String name) {
19+
this.name = name;
20+
}
21+
2022
@Override
2123
public String toString() {
2224
StringBuilder sb = new StringBuilder();
2325
sb.append("class Category {\n");
24-
sb.append(" name: ").append(name).append("\n");
2526
sb.append(" id: ").append(id).append("\n");
27+
sb.append(" name: ").append(name).append("\n");
2628
sb.append("}\n");
2729
return sb.toString();
2830
}

samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import java.util.Date;
44
public class Order {
5+
/* Unique identifier for the order */
56
private Long id = null;
6-
/* Order Status */
7-
private String status = null;
7+
/* ID of pet being ordered */
88
private Long petId = null;
9+
/* Number of pets ordered */
910
private Integer quantity = null;
11+
/* Status of the order */
12+
private String status = null;
13+
/* Date shipped, only if it has been */
1014
private Date shipDate = null;
1115
public Long getId() {
1216
return id;
@@ -15,13 +19,6 @@ public void setId(Long id) {
1519
this.id = id;
1620
}
1721

18-
public String getStatus() {
19-
return status;
20-
}
21-
public void setStatus(String status) {
22-
this.status = status;
23-
}
24-
2522
public Long getPetId() {
2623
return petId;
2724
}
@@ -36,6 +33,13 @@ public void setQuantity(Integer quantity) {
3633
this.quantity = quantity;
3734
}
3835

36+
public String getStatus() {
37+
return status;
38+
}
39+
public void setStatus(String status) {
40+
this.status = status;
41+
}
42+
3943
public Date getShipDate() {
4044
return shipDate;
4145
}
@@ -48,9 +52,9 @@ public String toString() {
4852
StringBuilder sb = new StringBuilder();
4953
sb.append("class Order {\n");
5054
sb.append(" id: ").append(id).append("\n");
51-
sb.append(" status: ").append(status).append("\n");
5255
sb.append(" petId: ").append(petId).append("\n");
5356
sb.append(" quantity: ").append(quantity).append("\n");
57+
sb.append(" status: ").append(status).append("\n");
5458
sb.append(" shipDate: ").append(shipDate).append("\n");
5559
sb.append("}\n");
5660
return sb.toString();

samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,44 @@
44
import com.wordnik.petstore.model.Category;
55
import com.wordnik.petstore.model.Tag;
66
public class Pet {
7-
private String name = null;
7+
/* Unique identifier for the Pet */
88
private Long id = null;
9+
/* Category the pet is in */
10+
private Category category = null;
11+
/* Friendly name of the pet */
12+
private String name = null;
13+
/* Image URLs */
14+
private List<String> photoUrls = new ArrayList<String>();
15+
/* Tags assigned to this pet */
916
private List<Tag> tags = new ArrayList<Tag>();
1017
/* pet status in the store */
1118
private String status = null;
12-
private List<String> photoUrls = new ArrayList<String>();
13-
private Category category = null;
19+
public Long getId() {
20+
return id;
21+
}
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public Category getCategory() {
27+
return category;
28+
}
29+
public void setCategory(Category category) {
30+
this.category = category;
31+
}
32+
1433
public String getName() {
1534
return name;
1635
}
1736
public void setName(String name) {
1837
this.name = name;
1938
}
2039

21-
public Long getId() {
22-
return id;
40+
public List<String> getPhotoUrls() {
41+
return photoUrls;
2342
}
24-
public void setId(Long id) {
25-
this.id = id;
43+
public void setPhotoUrls(List<String> photoUrls) {
44+
this.photoUrls = photoUrls;
2645
}
2746

2847
public List<Tag> getTags() {
@@ -39,30 +58,16 @@ public void setStatus(String status) {
3958
this.status = status;
4059
}
4160

42-
public List<String> getPhotoUrls() {
43-
return photoUrls;
44-
}
45-
public void setPhotoUrls(List<String> photoUrls) {
46-
this.photoUrls = photoUrls;
47-
}
48-
49-
public Category getCategory() {
50-
return category;
51-
}
52-
public void setCategory(Category category) {
53-
this.category = category;
54-
}
55-
5661
@Override
5762
public String toString() {
5863
StringBuilder sb = new StringBuilder();
5964
sb.append("class Pet {\n");
60-
sb.append(" name: ").append(name).append("\n");
6165
sb.append(" id: ").append(id).append("\n");
66+
sb.append(" category: ").append(category).append("\n");
67+
sb.append(" name: ").append(name).append("\n");
68+
sb.append(" photoUrls: ").append(photoUrls).append("\n");
6269
sb.append(" tags: ").append(tags).append("\n");
6370
sb.append(" status: ").append(status).append("\n");
64-
sb.append(" photoUrls: ").append(photoUrls).append("\n");
65-
sb.append(" category: ").append(category).append("\n");
6671
sb.append("}\n");
6772
return sb.toString();
6873
}

samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Tag.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
package com.wordnik.petstore.model;
22

33
public class Tag {
4-
private String name = null;
4+
/* Unique identifier for the tag */
55
private Long id = null;
6-
public String getName() {
7-
return name;
8-
}
9-
public void setName(String name) {
10-
this.name = name;
11-
}
12-
6+
/* Friendly name for the tag */
7+
private String name = null;
138
public Long getId() {
149
return id;
1510
}
1611
public void setId(Long id) {
1712
this.id = id;
1813
}
1914

15+
public String getName() {
16+
return name;
17+
}
18+
public void setName(String name) {
19+
this.name = name;
20+
}
21+
2022
@Override
2123
public String toString() {
2224
StringBuilder sb = new StringBuilder();
2325
sb.append("class Tag {\n");
24-
sb.append(" name: ").append(name).append("\n");
2526
sb.append(" id: ").append(id).append("\n");
27+
sb.append(" name: ").append(name).append("\n");
2628
sb.append("}\n");
2729
return sb.toString();
2830
}

0 commit comments

Comments
 (0)