Skip to content

Commit 15f5eae

Browse files
committed
Regenerate Android-Java sample
1 parent 6fd54d5 commit 15f5eae

File tree

12 files changed

+196
-27
lines changed

12 files changed

+196
-27
lines changed

samples/client/petstore/android-java/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
12
group = 'io.swagger'
23
project.version = '1.0.0'
34

5+
46
buildscript {
57
repositories {
68
jcenter()
@@ -21,8 +23,10 @@ allprojects {
2123

2224

2325
apply plugin: 'com.android.library'
26+
2427
apply plugin: 'com.github.dcendents.android-maven'
2528

29+
2630
android {
2731
compileSdkVersion 22
2832
buildToolsVersion '22.0.0'
@@ -81,6 +85,7 @@ afterEvaluate {
8185
}
8286
}
8387

88+
8489
task sourcesJar(type: Jar) {
8590
from android.sourceSets.main.java.srcDirs
8691
classifier = 'sources'
@@ -89,3 +94,4 @@ task sourcesJar(type: Jar) {
8994
artifacts {
9095
archives sourcesJar
9196
}
97+

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,10 @@ else if ("PATCH".equals(method)) {
365365

366366
int code = response.getStatusLine().getStatusCode();
367367
String responseString = null;
368-
if(code == 204)
368+
if(code == 204) {
369369
responseString = "";
370+
return responseString;
371+
}
370372
else if(code >= 200 && code < 300) {
371373
if(response.getEntity() != null) {
372374
HttpEntity resEntity = response.getEntity();

samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public static <T> T deserializeToObject(String jsonString, Class cls){
3535
public static Type getListTypeForDeserialization(Class cls) {
3636
String className = cls.getSimpleName();
3737

38+
if ("Order".equalsIgnoreCase(className)) {
39+
return new TypeToken<List<Order>>(){}.getType();
40+
}
41+
3842
if ("User".equalsIgnoreCase(className)) {
3943
return new TypeToken<List<User>>(){}.getType();
4044
}
@@ -43,16 +47,16 @@ public static Type getListTypeForDeserialization(Class cls) {
4347
return new TypeToken<List<Category>>(){}.getType();
4448
}
4549

46-
if ("Pet".equalsIgnoreCase(className)) {
47-
return new TypeToken<List<Pet>>(){}.getType();
48-
}
49-
5050
if ("Tag".equalsIgnoreCase(className)) {
5151
return new TypeToken<List<Tag>>(){}.getType();
5252
}
5353

54-
if ("Order".equalsIgnoreCase(className)) {
55-
return new TypeToken<List<Order>>(){}.getType();
54+
if ("Pet".equalsIgnoreCase(className)) {
55+
return new TypeToken<List<Pet>>(){}.getType();
56+
}
57+
58+
if ("ApiResponse".equalsIgnoreCase(className)) {
59+
return new TypeToken<List<ApiResponse>>(){}.getType();
5660
}
5761

5862
return new TypeToken<List<Object>>(){}.getType();
@@ -61,6 +65,10 @@ public static Type getListTypeForDeserialization(Class cls) {
6165
public static Type getTypeForDeserialization(Class cls) {
6266
String className = cls.getSimpleName();
6367

68+
if ("Order".equalsIgnoreCase(className)) {
69+
return new TypeToken<Order>(){}.getType();
70+
}
71+
6472
if ("User".equalsIgnoreCase(className)) {
6573
return new TypeToken<User>(){}.getType();
6674
}
@@ -69,16 +77,16 @@ public static Type getTypeForDeserialization(Class cls) {
6977
return new TypeToken<Category>(){}.getType();
7078
}
7179

72-
if ("Pet".equalsIgnoreCase(className)) {
73-
return new TypeToken<Pet>(){}.getType();
74-
}
75-
7680
if ("Tag".equalsIgnoreCase(className)) {
7781
return new TypeToken<Tag>(){}.getType();
7882
}
7983

80-
if ("Order".equalsIgnoreCase(className)) {
81-
return new TypeToken<Order>(){}.getType();
84+
if ("Pet".equalsIgnoreCase(className)) {
85+
return new TypeToken<Pet>(){}.getType();
86+
}
87+
88+
if ("ApiResponse".equalsIgnoreCase(className)) {
89+
return new TypeToken<ApiResponse>(){}.getType();
8290
}
8391

8492
return new TypeToken<Object>(){}.getType();

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import io.swagger.client.model.Pet;
1212
import java.io.File;
13+
import io.swagger.client.model.ApiResponse;
14+
1315

1416
import org.apache.http.HttpEntity;
1517
import org.apache.http.entity.mime.MultipartEntityBuilder;
@@ -18,6 +20,7 @@
1820
import java.util.HashMap;
1921
import java.io.File;
2022

23+
2124
public class PetApi {
2225
String basePath = "http://petstore.swagger.io/v2";
2326
ApiInvoker apiInvoker = ApiInvoker.getInstance();
@@ -48,6 +51,11 @@ public String getBasePath() {
4851
public void updatePet (Pet body) throws ApiException {
4952
Object postBody = body;
5053

54+
// verify the required parameter 'body' is set
55+
if (body == null) {
56+
throw new ApiException(400, "Missing the required parameter 'body' when calling updatePet");
57+
}
58+
5159

5260
// create path and map variables
5361
String path = "/pet".replaceAll("\\{format\\}","json");
@@ -102,6 +110,11 @@ public void updatePet (Pet body) throws ApiException {
102110
public void addPet (Pet body) throws ApiException {
103111
Object postBody = body;
104112

113+
// verify the required parameter 'body' is set
114+
if (body == null) {
115+
throw new ApiException(400, "Missing the required parameter 'body' when calling addPet");
116+
}
117+
105118

106119
// create path and map variables
107120
String path = "/pet".replaceAll("\\{format\\}","json");
@@ -156,6 +169,11 @@ public void addPet (Pet body) throws ApiException {
156169
public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
157170
Object postBody = null;
158171

172+
// verify the required parameter 'status' is set
173+
if (status == null) {
174+
throw new ApiException(400, "Missing the required parameter 'status' when calling findPetsByStatus");
175+
}
176+
159177

160178
// create path and map variables
161179
String path = "/pet/findByStatus".replaceAll("\\{format\\}","json");
@@ -168,7 +186,7 @@ public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
168186
Map<String, String> formParams = new HashMap<String, String>();
169187

170188

171-
queryParams.addAll(ApiInvoker.parameterToPairs("multi", "status", status));
189+
queryParams.addAll(ApiInvoker.parameterToPairs("csv", "status", status));
172190

173191

174192

@@ -212,6 +230,11 @@ public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
212230
public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
213231
Object postBody = null;
214232

233+
// verify the required parameter 'tags' is set
234+
if (tags == null) {
235+
throw new ApiException(400, "Missing the required parameter 'tags' when calling findPetsByTags");
236+
}
237+
215238

216239
// create path and map variables
217240
String path = "/pet/findByTags".replaceAll("\\{format\\}","json");
@@ -224,7 +247,7 @@ public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
224247
Map<String, String> formParams = new HashMap<String, String>();
225248

226249

227-
queryParams.addAll(ApiInvoker.parameterToPairs("multi", "tags", tags));
250+
queryParams.addAll(ApiInvoker.parameterToPairs("csv", "tags", tags));
228251

229252

230253

@@ -261,8 +284,8 @@ public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
261284

262285
/**
263286
* Find pet by ID
264-
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
265-
* @param petId ID of pet that needs to be fetched
287+
* Returns a single pet
288+
* @param petId ID of pet to return
266289
* @return Pet
267290
*/
268291
public Pet getPetById (Long petId) throws ApiException {
@@ -326,7 +349,7 @@ public Pet getPetById (Long petId) throws ApiException {
326349
* @param status Updated status of the pet
327350
* @return void
328351
*/
329-
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
352+
public void updatePetWithForm (Long petId, String name, String status) throws ApiException {
330353
Object postBody = null;
331354

332355
// verify the required parameter 'petId' is set
@@ -457,9 +480,9 @@ public void deletePet (Long petId, String apiKey) throws ApiException {
457480
* @param petId ID of pet to update
458481
* @param additionalMetadata Additional data to pass to server
459482
* @param file file to upload
460-
* @return void
483+
* @return ApiResponse
461484
*/
462-
public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException {
485+
public ApiResponse uploadFile (Long petId, String additionalMetadata, File file) throws ApiException {
463486
Object postBody = null;
464487

465488
// verify the required parameter 'petId' is set
@@ -512,14 +535,15 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throw
512535
try {
513536
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
514537
if(response != null){
515-
return ;
538+
return (ApiResponse) ApiInvoker.deserialize(response, "", ApiResponse.class);
516539
}
517540
else {
518-
return ;
541+
return null;
519542
}
520543
} catch (ApiException ex) {
521544
throw ex;
522545
}
523546
}
524547

525548
}
549+

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import java.util.Map;
1212
import io.swagger.client.model.Order;
1313

14+
1415
import org.apache.http.HttpEntity;
1516
import org.apache.http.entity.mime.MultipartEntityBuilder;
1617

1718
import java.util.Map;
1819
import java.util.HashMap;
1920
import java.io.File;
2021

22+
2123
public class StoreApi {
2224
String basePath = "http://petstore.swagger.io/v2";
2325
ApiInvoker apiInvoker = ApiInvoker.getInstance();
@@ -101,6 +103,11 @@ public Map<String, Integer> getInventory () throws ApiException {
101103
public Order placeOrder (Order body) throws ApiException {
102104
Object postBody = body;
103105

106+
// verify the required parameter 'body' is set
107+
if (body == null) {
108+
throw new ApiException(400, "Missing the required parameter 'body' when calling placeOrder");
109+
}
110+
104111

105112
// create path and map variables
106113
String path = "/store/order".replaceAll("\\{format\\}","json");
@@ -152,7 +159,7 @@ public Order placeOrder (Order body) throws ApiException {
152159
* @param orderId ID of pet that needs to be fetched
153160
* @return Order
154161
*/
155-
public Order getOrderById (String orderId) throws ApiException {
162+
public Order getOrderById (Long orderId) throws ApiException {
156163
Object postBody = null;
157164

158165
// verify the required parameter 'orderId' is set
@@ -265,3 +272,4 @@ public void deleteOrder (String orderId) throws ApiException {
265272
}
266273

267274
}
275+

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import io.swagger.client.model.User;
1212
import java.util.*;
1313

14+
1415
import org.apache.http.HttpEntity;
1516
import org.apache.http.entity.mime.MultipartEntityBuilder;
1617

1718
import java.util.Map;
1819
import java.util.HashMap;
1920
import java.io.File;
2021

22+
2123
public class UserApi {
2224
String basePath = "http://petstore.swagger.io/v2";
2325
ApiInvoker apiInvoker = ApiInvoker.getInstance();
@@ -48,6 +50,11 @@ public String getBasePath() {
4850
public void createUser (User body) throws ApiException {
4951
Object postBody = body;
5052

53+
// verify the required parameter 'body' is set
54+
if (body == null) {
55+
throw new ApiException(400, "Missing the required parameter 'body' when calling createUser");
56+
}
57+
5158

5259
// create path and map variables
5360
String path = "/user".replaceAll("\\{format\\}","json");
@@ -102,6 +109,11 @@ public void createUser (User body) throws ApiException {
102109
public void createUsersWithArrayInput (List<User> body) throws ApiException {
103110
Object postBody = body;
104111

112+
// verify the required parameter 'body' is set
113+
if (body == null) {
114+
throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithArrayInput");
115+
}
116+
105117

106118
// create path and map variables
107119
String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
@@ -156,6 +168,11 @@ public void createUsersWithArrayInput (List<User> body) throws ApiException {
156168
public void createUsersWithListInput (List<User> body) throws ApiException {
157169
Object postBody = body;
158170

171+
// verify the required parameter 'body' is set
172+
if (body == null) {
173+
throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithListInput");
174+
}
175+
159176

160177
// create path and map variables
161178
String path = "/user/createWithList".replaceAll("\\{format\\}","json");
@@ -211,6 +228,16 @@ public void createUsersWithListInput (List<User> body) throws ApiException {
211228
public String loginUser (String username, String password) throws ApiException {
212229
Object postBody = null;
213230

231+
// verify the required parameter 'username' is set
232+
if (username == null) {
233+
throw new ApiException(400, "Missing the required parameter 'username' when calling loginUser");
234+
}
235+
236+
// verify the required parameter 'password' is set
237+
if (password == null) {
238+
throw new ApiException(400, "Missing the required parameter 'password' when calling loginUser");
239+
}
240+
214241

215242
// create path and map variables
216243
String path = "/user/login".replaceAll("\\{format\\}","json");
@@ -316,7 +343,7 @@ public void logoutUser () throws ApiException {
316343
/**
317344
* Get user by user name
318345
*
319-
* @param username The name that needs to be fetched. Use user1 for testing.
346+
* @param username The name that needs to be fetched. Use user1 for testing.
320347
* @return User
321348
*/
322349
public User getUserByName (String username) throws ApiException {
@@ -387,6 +414,11 @@ public void updateUser (String username, User body) throws ApiException {
387414
throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser");
388415
}
389416

417+
// verify the required parameter 'body' is set
418+
if (body == null) {
419+
throw new ApiException(400, "Missing the required parameter 'body' when calling updateUser");
420+
}
421+
390422

391423
// create path and map variables
392424
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
@@ -492,3 +524,4 @@ public void deleteUser (String username) throws ApiException {
492524
}
493525

494526
}
527+

0 commit comments

Comments
 (0)