From 15f5eae2a80da4c658b466da04d11d5d51532cee Mon Sep 17 00:00:00 2001 From: Eran Stiller Date: Mon, 12 Oct 2015 08:51:48 +0300 Subject: [PATCH] Regenerate Android-Java sample --- .../client/petstore/android-java/build.gradle | 6 ++ .../java/io/swagger/client/ApiInvoker.java | 4 +- .../main/java/io/swagger/client/JsonUtil.java | 32 +++++---- .../java/io/swagger/client/api/PetApi.java | 42 +++++++++--- .../java/io/swagger/client/api/StoreApi.java | 10 ++- .../java/io/swagger/client/api/UserApi.java | 35 +++++++++- .../io/swagger/client/model/ApiResponse.java | 68 +++++++++++++++++++ .../io/swagger/client/model/Category.java | 4 ++ .../java/io/swagger/client/model/Order.java | 4 ++ .../java/io/swagger/client/model/Pet.java | 10 ++- .../java/io/swagger/client/model/Tag.java | 4 ++ .../java/io/swagger/client/model/User.java | 4 ++ 12 files changed, 196 insertions(+), 27 deletions(-) create mode 100644 samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java diff --git a/samples/client/petstore/android-java/build.gradle b/samples/client/petstore/android-java/build.gradle index 417503cb51e..c5f4edf79cb 100644 --- a/samples/client/petstore/android-java/build.gradle +++ b/samples/client/petstore/android-java/build.gradle @@ -1,6 +1,8 @@ + group = 'io.swagger' project.version = '1.0.0' + buildscript { repositories { jcenter() @@ -21,8 +23,10 @@ allprojects { apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + android { compileSdkVersion 22 buildToolsVersion '22.0.0' @@ -81,6 +85,7 @@ afterEvaluate { } } + task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' @@ -89,3 +94,4 @@ task sourcesJar(type: Jar) { artifacts { archives sourcesJar } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java index eabb47e818d..aa786ff5b31 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java @@ -365,8 +365,10 @@ public class ApiInvoker { int code = response.getStatusLine().getStatusCode(); String responseString = null; - if(code == 204) + if(code == 204) { responseString = ""; + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java index 5aa10d3ea82..93a59d71b5e 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java @@ -35,6 +35,10 @@ public class JsonUtil { public static Type getListTypeForDeserialization(Class cls) { String className = cls.getSimpleName(); + if ("Order".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); + } + if ("User".equalsIgnoreCase(className)) { return new TypeToken>(){}.getType(); } @@ -43,16 +47,16 @@ public class JsonUtil { return new TypeToken>(){}.getType(); } - if ("Pet".equalsIgnoreCase(className)) { - return new TypeToken>(){}.getType(); - } - if ("Tag".equalsIgnoreCase(className)) { return new TypeToken>(){}.getType(); } - if ("Order".equalsIgnoreCase(className)) { - return new TypeToken>(){}.getType(); + if ("Pet".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); + } + + if ("ApiResponse".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); } return new TypeToken>(){}.getType(); @@ -61,6 +65,10 @@ public class JsonUtil { public static Type getTypeForDeserialization(Class cls) { String className = cls.getSimpleName(); + if ("Order".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); + } + if ("User".equalsIgnoreCase(className)) { return new TypeToken(){}.getType(); } @@ -69,16 +77,16 @@ public class JsonUtil { return new TypeToken(){}.getType(); } - if ("Pet".equalsIgnoreCase(className)) { - return new TypeToken(){}.getType(); - } - if ("Tag".equalsIgnoreCase(className)) { return new TypeToken(){}.getType(); } - if ("Order".equalsIgnoreCase(className)) { - return new TypeToken(){}.getType(); + if ("Pet".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); + } + + if ("ApiResponse".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); } return new TypeToken(){}.getType(); diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java index f6b6403a342..5a607ba393f 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java @@ -10,6 +10,8 @@ import java.util.*; import io.swagger.client.model.Pet; import java.io.File; +import io.swagger.client.model.ApiResponse; + import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -18,6 +20,7 @@ import java.util.Map; import java.util.HashMap; import java.io.File; + public class PetApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -48,6 +51,11 @@ public class PetApi { public void updatePet (Pet body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling updatePet"); + } + // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -102,6 +110,11 @@ public class PetApi { public void addPet (Pet body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling addPet"); + } + // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -156,6 +169,11 @@ public class PetApi { public List findPetsByStatus (List status) throws ApiException { Object postBody = null; + // verify the required parameter 'status' is set + if (status == null) { + throw new ApiException(400, "Missing the required parameter 'status' when calling findPetsByStatus"); + } + // create path and map variables String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); @@ -168,7 +186,7 @@ public class PetApi { Map formParams = new HashMap(); - queryParams.addAll(ApiInvoker.parameterToPairs("multi", "status", status)); + queryParams.addAll(ApiInvoker.parameterToPairs("csv", "status", status)); @@ -212,6 +230,11 @@ public class PetApi { public List findPetsByTags (List tags) throws ApiException { Object postBody = null; + // verify the required parameter 'tags' is set + if (tags == null) { + throw new ApiException(400, "Missing the required parameter 'tags' when calling findPetsByTags"); + } + // create path and map variables String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); @@ -224,7 +247,7 @@ public class PetApi { Map formParams = new HashMap(); - queryParams.addAll(ApiInvoker.parameterToPairs("multi", "tags", tags)); + queryParams.addAll(ApiInvoker.parameterToPairs("csv", "tags", tags)); @@ -261,8 +284,8 @@ public class PetApi { /** * Find pet by ID - * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - * @param petId ID of pet that needs to be fetched + * Returns a single pet + * @param petId ID of pet to return * @return Pet */ public Pet getPetById (Long petId) throws ApiException { @@ -326,7 +349,7 @@ public class PetApi { * @param status Updated status of the pet * @return void */ - public void updatePetWithForm (String petId, String name, String status) throws ApiException { + public void updatePetWithForm (Long petId, String name, String status) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -457,9 +480,9 @@ public class PetApi { * @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload - * @return void + * @return ApiResponse */ - public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { + public ApiResponse uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -512,10 +535,10 @@ public class PetApi { try { String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); if(response != null){ - return ; + return (ApiResponse) ApiInvoker.deserialize(response, "", ApiResponse.class); } else { - return ; + return null; } } catch (ApiException ex) { throw ex; @@ -523,3 +546,4 @@ public class PetApi { } } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java index 49a3ac4aa9a..b89a0ddbd47 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java @@ -11,6 +11,7 @@ import java.util.*; import java.util.Map; import io.swagger.client.model.Order; + import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -18,6 +19,7 @@ import java.util.Map; import java.util.HashMap; import java.io.File; + public class StoreApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -101,6 +103,11 @@ public class StoreApi { public Order placeOrder (Order body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling placeOrder"); + } + // create path and map variables String path = "/store/order".replaceAll("\\{format\\}","json"); @@ -152,7 +159,7 @@ public class StoreApi { * @param orderId ID of pet that needs to be fetched * @return Order */ - public Order getOrderById (String orderId) throws ApiException { + public Order getOrderById (Long orderId) throws ApiException { Object postBody = null; // verify the required parameter 'orderId' is set @@ -265,3 +272,4 @@ public class StoreApi { } } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java index a16a745c7f8..6703b54f758 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java @@ -11,6 +11,7 @@ import java.util.*; import io.swagger.client.model.User; import java.util.*; + import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -18,6 +19,7 @@ import java.util.Map; import java.util.HashMap; import java.io.File; + public class UserApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -48,6 +50,11 @@ public class UserApi { public void createUser (User body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling createUser"); + } + // create path and map variables String path = "/user".replaceAll("\\{format\\}","json"); @@ -102,6 +109,11 @@ public class UserApi { public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithArrayInput"); + } + // create path and map variables String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); @@ -156,6 +168,11 @@ public class UserApi { public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithListInput"); + } + // create path and map variables String path = "/user/createWithList".replaceAll("\\{format\\}","json"); @@ -211,6 +228,16 @@ public class UserApi { public String loginUser (String username, String password) throws ApiException { Object postBody = null; + // verify the required parameter 'username' is set + if (username == null) { + throw new ApiException(400, "Missing the required parameter 'username' when calling loginUser"); + } + + // verify the required parameter 'password' is set + if (password == null) { + throw new ApiException(400, "Missing the required parameter 'password' when calling loginUser"); + } + // create path and map variables String path = "/user/login".replaceAll("\\{format\\}","json"); @@ -316,7 +343,7 @@ public class UserApi { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ public User getUserByName (String username) throws ApiException { @@ -387,6 +414,11 @@ public class UserApi { throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); } + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling updateUser"); + } + // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -492,3 +524,4 @@ public class UserApi { } } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java new file mode 100644 index 00000000000..6dd0a9c2fc2 --- /dev/null +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java @@ -0,0 +1,68 @@ +package io.swagger.client.model; + + + +import io.swagger.annotations.*; +import com.google.gson.annotations.SerializedName; + + + +@ApiModel(description = "") +public class ApiResponse { + + @SerializedName("code") + private Integer code = null; + @SerializedName("type") + private String type = null; + @SerializedName("message") + private String message = null; + + + /** + **/ + @ApiModelProperty(value = "") + public Integer getCode() { + return code; + } + public void setCode(Integer code) { + this.code = code; + } + + + /** + **/ + @ApiModelProperty(value = "") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + + /** + **/ + @ApiModelProperty(value = "") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiResponse {\n"); + + sb.append(" code: ").append(code).append("\n"); + sb.append(" type: ").append(type).append("\n"); + sb.append(" message: ").append(message).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java index 44c71e8a620..98e5c25c80f 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java @@ -1,10 +1,12 @@ package io.swagger.client.model; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Category { @@ -48,3 +50,5 @@ public class Category { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java index f3f42db615c..4ef664deba2 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java @@ -2,10 +2,12 @@ package io.swagger.client.model; import java.util.Date; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Order { @@ -109,3 +111,5 @@ public class Order { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java index 90a840e6e42..cf7eb877b2a 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java @@ -1,13 +1,15 @@ package io.swagger.client.model; import io.swagger.client.model.Category; -import io.swagger.client.model.Tag; import java.util.*; +import io.swagger.client.model.Tag; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Pet { @@ -18,9 +20,9 @@ public class Pet { @SerializedName("name") private String name = null; @SerializedName("photoUrls") - private List photoUrls = new ArrayList() ; + private List photoUrls = null; @SerializedName("tags") - private List tags = new ArrayList() ; + private List tags = null; public enum StatusEnum { available, pending, sold, }; @@ -111,3 +113,5 @@ public class Pet { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java index 7c9651b1ba8..e87a002a144 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java @@ -1,10 +1,12 @@ package io.swagger.client.model; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Tag { @@ -48,3 +50,5 @@ public class Tag { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java index dc022697eb0..fabdab0b4e3 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java @@ -1,10 +1,12 @@ package io.swagger.client.model; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class User { @@ -133,3 +135,5 @@ public class User { return sb.toString(); } } + +