Skip to content

Commit 442be86

Browse files
committed
rebuilt client, added tests
1 parent 287bb7d commit 442be86

File tree

7 files changed

+269
-127
lines changed

7 files changed

+269
-127
lines changed

samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ else if ("PUT".equals(method)) {
226226
}
227227
else if ("DELETE".equals(method)) {
228228
if(body == null)
229-
response = builder.delete(ClientResponse.class, serialize(body));
229+
response = builder.delete(ClientResponse.class);
230230
else
231231
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
232232
}
@@ -237,12 +237,26 @@ else if ("DELETE".equals(method)) {
237237
return null;
238238
}
239239
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
240-
return (String) response.getEntity(String.class);
240+
if(response.hasEntity()) {
241+
return (String) response.getEntity(String.class);
242+
}
243+
else {
244+
return "";
245+
}
241246
}
242247
else {
248+
String message = "error";
249+
if(response.hasEntity()) {
250+
try{
251+
message = String.valueOf(response.getEntity(String.class));
252+
}
253+
catch (RuntimeException e) {
254+
// e.printStackTrace();
255+
}
256+
}
243257
throw new ApiException(
244258
response.getClientResponseStatus().getStatusCode(),
245-
response.getEntity(String.class));
259+
message);
246260
}
247261
}
248262

samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.File;
1212

1313
import com.sun.jersey.multipart.FormDataMultiPart;
14+
import com.sun.jersey.multipart.file.FileDataBodyPart;
1415

1516
import javax.ws.rs.core.MediaType;
1617

@@ -76,12 +77,7 @@ public void updatePet (Pet body) throws ApiException {
7677
return ;
7778
}
7879
} catch (ApiException ex) {
79-
if(ex.getCode() == 404) {
80-
return ;
81-
}
82-
else {
83-
throw ex;
84-
}
80+
throw ex;
8581
}
8682
}
8783

@@ -126,12 +122,7 @@ public void addPet (Pet body) throws ApiException {
126122
return ;
127123
}
128124
} catch (ApiException ex) {
129-
if(ex.getCode() == 404) {
130-
return ;
131-
}
132-
else {
133-
throw ex;
134-
}
125+
throw ex;
135126
}
136127
}
137128

@@ -178,12 +169,7 @@ public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
178169
return null;
179170
}
180171
} catch (ApiException ex) {
181-
if(ex.getCode() == 404) {
182-
return null;
183-
}
184-
else {
185-
throw ex;
186-
}
172+
throw ex;
187173
}
188174
}
189175

@@ -230,12 +216,7 @@ public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
230216
return null;
231217
}
232218
} catch (ApiException ex) {
233-
if(ex.getCode() == 404) {
234-
return null;
235-
}
236-
else {
237-
throw ex;
238-
}
219+
throw ex;
239220
}
240221
}
241222

@@ -281,12 +262,7 @@ public Pet getPetById (Long petId) throws ApiException {
281262
return null;
282263
}
283264
} catch (ApiException ex) {
284-
if(ex.getCode() == 404) {
285-
return null;
286-
}
287-
else {
288-
throw ex;
289-
}
265+
throw ex;
290266
}
291267
}
292268

@@ -340,12 +316,7 @@ public void updatePetWithForm (String petId, String name, String status) throws
340316
return ;
341317
}
342318
} catch (ApiException ex) {
343-
if(ex.getCode() == 404) {
344-
return ;
345-
}
346-
else {
347-
throw ex;
348-
}
319+
throw ex;
349320
}
350321
}
351322

@@ -392,12 +363,7 @@ public void deletePet (String apiKey, Long petId) throws ApiException {
392363
return ;
393364
}
394365
} catch (ApiException ex) {
395-
if(ex.getCode() == 404) {
396-
return ;
397-
}
398-
else {
399-
throw ex;
400-
}
366+
throw ex;
401367
}
402368
}
403369

@@ -431,7 +397,8 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throws
431397
mp.field("additionalMetadata", ApiInvoker.parameterToString(additionalMetadata), MediaType.MULTIPART_FORM_DATA_TYPE);
432398

433399
hasFields = true;
434-
mp.field("file", file, MediaType.MULTIPART_FORM_DATA_TYPE);
400+
mp.field("file", file.getName());
401+
mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE));
435402

436403
if(hasFields)
437404
postBody = mp;
@@ -451,12 +418,7 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throws
451418
return ;
452419
}
453420
} catch (ApiException ex) {
454-
if(ex.getCode() == 404) {
455-
return ;
456-
}
457-
else {
458-
throw ex;
459-
}
421+
throw ex;
460422
}
461423
}
462424

samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.swagger.client.model.Order;
1212

1313
import com.sun.jersey.multipart.FormDataMultiPart;
14+
import com.sun.jersey.multipart.file.FileDataBodyPart;
1415

1516
import javax.ws.rs.core.MediaType;
1617

@@ -76,12 +77,7 @@ public Map<String, Integer> getInventory () throws ApiException {
7677
return null;
7778
}
7879
} catch (ApiException ex) {
79-
if(ex.getCode() == 404) {
80-
return null;
81-
}
82-
else {
83-
throw ex;
84-
}
80+
throw ex;
8581
}
8682
}
8783

@@ -126,12 +122,7 @@ public Order placeOrder (Order body) throws ApiException {
126122
return null;
127123
}
128124
} catch (ApiException ex) {
129-
if(ex.getCode() == 404) {
130-
return null;
131-
}
132-
else {
133-
throw ex;
134-
}
125+
throw ex;
135126
}
136127
}
137128

@@ -177,12 +168,7 @@ public Order getOrderById (String orderId) throws ApiException {
177168
return null;
178169
}
179170
} catch (ApiException ex) {
180-
if(ex.getCode() == 404) {
181-
return null;
182-
}
183-
else {
184-
throw ex;
185-
}
171+
throw ex;
186172
}
187173
}
188174

@@ -228,12 +214,7 @@ public void deleteOrder (String orderId) throws ApiException {
228214
return ;
229215
}
230216
} catch (ApiException ex) {
231-
if(ex.getCode() == 404) {
232-
return ;
233-
}
234-
else {
235-
throw ex;
236-
}
217+
throw ex;
237218
}
238219
}
239220

samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.*;
1212

1313
import com.sun.jersey.multipart.FormDataMultiPart;
14+
import com.sun.jersey.multipart.file.FileDataBodyPart;
1415

1516
import javax.ws.rs.core.MediaType;
1617

@@ -76,12 +77,7 @@ public void createUser (User body) throws ApiException {
7677
return ;
7778
}
7879
} catch (ApiException ex) {
79-
if(ex.getCode() == 404) {
80-
return ;
81-
}
82-
else {
83-
throw ex;
84-
}
80+
throw ex;
8581
}
8682
}
8783

@@ -126,12 +122,7 @@ public void createUsersWithArrayInput (List<User> body) throws ApiException {
126122
return ;
127123
}
128124
} catch (ApiException ex) {
129-
if(ex.getCode() == 404) {
130-
return ;
131-
}
132-
else {
133-
throw ex;
134-
}
125+
throw ex;
135126
}
136127
}
137128

@@ -176,12 +167,7 @@ public void createUsersWithListInput (List<User> body) throws ApiException {
176167
return ;
177168
}
178169
} catch (ApiException ex) {
179-
if(ex.getCode() == 404) {
180-
return ;
181-
}
182-
else {
183-
throw ex;
184-
}
170+
throw ex;
185171
}
186172
}
187173

@@ -230,12 +216,7 @@ public String loginUser (String username, String password) throws ApiException {
230216
return null;
231217
}
232218
} catch (ApiException ex) {
233-
if(ex.getCode() == 404) {
234-
return null;
235-
}
236-
else {
237-
throw ex;
238-
}
219+
throw ex;
239220
}
240221
}
241222

@@ -280,12 +261,7 @@ public void logoutUser () throws ApiException {
280261
return ;
281262
}
282263
} catch (ApiException ex) {
283-
if(ex.getCode() == 404) {
284-
return ;
285-
}
286-
else {
287-
throw ex;
288-
}
264+
throw ex;
289265
}
290266
}
291267

@@ -331,12 +307,7 @@ public User getUserByName (String username) throws ApiException {
331307
return null;
332308
}
333309
} catch (ApiException ex) {
334-
if(ex.getCode() == 404) {
335-
return null;
336-
}
337-
else {
338-
throw ex;
339-
}
310+
throw ex;
340311
}
341312
}
342313

@@ -382,12 +353,7 @@ public void updateUser (String username, User body) throws ApiException {
382353
return ;
383354
}
384355
} catch (ApiException ex) {
385-
if(ex.getCode() == 404) {
386-
return ;
387-
}
388-
else {
389-
throw ex;
390-
}
356+
throw ex;
391357
}
392358
}
393359

@@ -433,12 +399,7 @@ public void deleteUser (String username) throws ApiException {
433399
return ;
434400
}
435401
} catch (ApiException ex) {
436-
if(ex.getCode() == 404) {
437-
return ;
438-
}
439-
else {
440-
throw ex;
441-
}
402+
throw ex;
442403
}
443404
}
444405

0 commit comments

Comments
 (0)