Regenerate Android-Java sample

This commit is contained in:
Eran Stiller 2015-10-12 08:51:48 +03:00
parent 6fd54d5285
commit 15f5eae2a8
12 changed files with 196 additions and 27 deletions

View File

@ -1,6 +1,8 @@
group = 'io.swagger' group = 'io.swagger'
project.version = '1.0.0' project.version = '1.0.0'
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@ -21,8 +23,10 @@ allprojects {
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.github.dcendents.android-maven'
android { android {
compileSdkVersion 22 compileSdkVersion 22
buildToolsVersion '22.0.0' buildToolsVersion '22.0.0'
@ -81,6 +85,7 @@ afterEvaluate {
} }
} }
task sourcesJar(type: Jar) { task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs from android.sourceSets.main.java.srcDirs
classifier = 'sources' classifier = 'sources'
@ -89,3 +94,4 @@ task sourcesJar(type: Jar) {
artifacts { artifacts {
archives sourcesJar archives sourcesJar
} }

View File

@ -365,8 +365,10 @@ public class ApiInvoker {
int code = response.getStatusLine().getStatusCode(); int code = response.getStatusLine().getStatusCode();
String responseString = null; String responseString = null;
if(code == 204) if(code == 204) {
responseString = ""; responseString = "";
return responseString;
}
else if(code >= 200 && code < 300) { else if(code >= 200 && code < 300) {
if(response.getEntity() != null) { if(response.getEntity() != null) {
HttpEntity resEntity = response.getEntity(); HttpEntity resEntity = response.getEntity();

View File

@ -35,6 +35,10 @@ public class JsonUtil {
public static Type getListTypeForDeserialization(Class cls) { public static Type getListTypeForDeserialization(Class cls) {
String className = cls.getSimpleName(); String className = cls.getSimpleName();
if ("Order".equalsIgnoreCase(className)) {
return new TypeToken<List<Order>>(){}.getType();
}
if ("User".equalsIgnoreCase(className)) { if ("User".equalsIgnoreCase(className)) {
return new TypeToken<List<User>>(){}.getType(); return new TypeToken<List<User>>(){}.getType();
} }
@ -43,16 +47,16 @@ public class JsonUtil {
return new TypeToken<List<Category>>(){}.getType(); return new TypeToken<List<Category>>(){}.getType();
} }
if ("Pet".equalsIgnoreCase(className)) {
return new TypeToken<List<Pet>>(){}.getType();
}
if ("Tag".equalsIgnoreCase(className)) { if ("Tag".equalsIgnoreCase(className)) {
return new TypeToken<List<Tag>>(){}.getType(); return new TypeToken<List<Tag>>(){}.getType();
} }
if ("Order".equalsIgnoreCase(className)) { if ("Pet".equalsIgnoreCase(className)) {
return new TypeToken<List<Order>>(){}.getType(); return new TypeToken<List<Pet>>(){}.getType();
}
if ("ApiResponse".equalsIgnoreCase(className)) {
return new TypeToken<List<ApiResponse>>(){}.getType();
} }
return new TypeToken<List<Object>>(){}.getType(); return new TypeToken<List<Object>>(){}.getType();
@ -61,6 +65,10 @@ public class JsonUtil {
public static Type getTypeForDeserialization(Class cls) { public static Type getTypeForDeserialization(Class cls) {
String className = cls.getSimpleName(); String className = cls.getSimpleName();
if ("Order".equalsIgnoreCase(className)) {
return new TypeToken<Order>(){}.getType();
}
if ("User".equalsIgnoreCase(className)) { if ("User".equalsIgnoreCase(className)) {
return new TypeToken<User>(){}.getType(); return new TypeToken<User>(){}.getType();
} }
@ -69,16 +77,16 @@ public class JsonUtil {
return new TypeToken<Category>(){}.getType(); return new TypeToken<Category>(){}.getType();
} }
if ("Pet".equalsIgnoreCase(className)) {
return new TypeToken<Pet>(){}.getType();
}
if ("Tag".equalsIgnoreCase(className)) { if ("Tag".equalsIgnoreCase(className)) {
return new TypeToken<Tag>(){}.getType(); return new TypeToken<Tag>(){}.getType();
} }
if ("Order".equalsIgnoreCase(className)) { if ("Pet".equalsIgnoreCase(className)) {
return new TypeToken<Order>(){}.getType(); return new TypeToken<Pet>(){}.getType();
}
if ("ApiResponse".equalsIgnoreCase(className)) {
return new TypeToken<ApiResponse>(){}.getType();
} }
return new TypeToken<Object>(){}.getType(); return new TypeToken<Object>(){}.getType();

View File

@ -10,6 +10,8 @@ import java.util.*;
import io.swagger.client.model.Pet; import io.swagger.client.model.Pet;
import java.io.File; import java.io.File;
import io.swagger.client.model.ApiResponse;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.MultipartEntityBuilder;
@ -18,6 +20,7 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.io.File; import java.io.File;
public class PetApi { public class PetApi {
String basePath = "http://petstore.swagger.io/v2"; String basePath = "http://petstore.swagger.io/v2";
ApiInvoker apiInvoker = ApiInvoker.getInstance(); ApiInvoker apiInvoker = ApiInvoker.getInstance();
@ -48,6 +51,11 @@ public class PetApi {
public void updatePet (Pet body) throws ApiException { public void updatePet (Pet body) throws ApiException {
Object postBody = body; 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 // create path and map variables
String path = "/pet".replaceAll("\\{format\\}","json"); String path = "/pet".replaceAll("\\{format\\}","json");
@ -102,6 +110,11 @@ public class PetApi {
public void addPet (Pet body) throws ApiException { public void addPet (Pet body) throws ApiException {
Object postBody = body; 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 // create path and map variables
String path = "/pet".replaceAll("\\{format\\}","json"); String path = "/pet".replaceAll("\\{format\\}","json");
@ -156,6 +169,11 @@ public class PetApi {
public List<Pet> findPetsByStatus (List<String> status) throws ApiException { public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
Object postBody = null; 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 // create path and map variables
String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); String path = "/pet/findByStatus".replaceAll("\\{format\\}","json");
@ -168,7 +186,7 @@ public class PetApi {
Map<String, String> formParams = new HashMap<String, String>(); Map<String, String> formParams = new HashMap<String, String>();
queryParams.addAll(ApiInvoker.parameterToPairs("multi", "status", status)); queryParams.addAll(ApiInvoker.parameterToPairs("csv", "status", status));
@ -212,6 +230,11 @@ public class PetApi {
public List<Pet> findPetsByTags (List<String> tags) throws ApiException { public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
Object postBody = null; 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 // create path and map variables
String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); String path = "/pet/findByTags".replaceAll("\\{format\\}","json");
@ -224,7 +247,7 @@ public class PetApi {
Map<String, String> formParams = new HashMap<String, String>(); Map<String, String> formParams = new HashMap<String, String>();
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 * Find pet by ID
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions * Returns a single pet
* @param petId ID of pet that needs to be fetched * @param petId ID of pet to return
* @return Pet * @return Pet
*/ */
public Pet getPetById (Long petId) throws ApiException { public Pet getPetById (Long petId) throws ApiException {
@ -326,7 +349,7 @@ public class PetApi {
* @param status Updated status of the pet * @param status Updated status of the pet
* @return void * @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; Object postBody = null;
// verify the required parameter 'petId' is set // verify the required parameter 'petId' is set
@ -457,9 +480,9 @@ public class PetApi {
* @param petId ID of pet to update * @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server * @param additionalMetadata Additional data to pass to server
* @param file file to upload * @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; Object postBody = null;
// verify the required parameter 'petId' is set // verify the required parameter 'petId' is set
@ -512,10 +535,10 @@ public class PetApi {
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return (ApiResponse) ApiInvoker.deserialize(response, "", ApiResponse.class);
} }
else { else {
return ; return null;
} }
} catch (ApiException ex) { } catch (ApiException ex) {
throw ex; throw ex;
@ -523,3 +546,4 @@ public class PetApi {
} }
} }

View File

@ -11,6 +11,7 @@ import java.util.*;
import java.util.Map; import java.util.Map;
import io.swagger.client.model.Order; import io.swagger.client.model.Order;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.MultipartEntityBuilder;
@ -18,6 +19,7 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.io.File; import java.io.File;
public class StoreApi { public class StoreApi {
String basePath = "http://petstore.swagger.io/v2"; String basePath = "http://petstore.swagger.io/v2";
ApiInvoker apiInvoker = ApiInvoker.getInstance(); ApiInvoker apiInvoker = ApiInvoker.getInstance();
@ -101,6 +103,11 @@ public class StoreApi {
public Order placeOrder (Order body) throws ApiException { public Order placeOrder (Order body) throws ApiException {
Object postBody = body; 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 // create path and map variables
String path = "/store/order".replaceAll("\\{format\\}","json"); String path = "/store/order".replaceAll("\\{format\\}","json");
@ -152,7 +159,7 @@ public class StoreApi {
* @param orderId ID of pet that needs to be fetched * @param orderId ID of pet that needs to be fetched
* @return Order * @return Order
*/ */
public Order getOrderById (String orderId) throws ApiException { public Order getOrderById (Long orderId) throws ApiException {
Object postBody = null; Object postBody = null;
// verify the required parameter 'orderId' is set // verify the required parameter 'orderId' is set
@ -265,3 +272,4 @@ public class StoreApi {
} }
} }

View File

@ -11,6 +11,7 @@ import java.util.*;
import io.swagger.client.model.User; import io.swagger.client.model.User;
import java.util.*; import java.util.*;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.MultipartEntityBuilder;
@ -18,6 +19,7 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.io.File; import java.io.File;
public class UserApi { public class UserApi {
String basePath = "http://petstore.swagger.io/v2"; String basePath = "http://petstore.swagger.io/v2";
ApiInvoker apiInvoker = ApiInvoker.getInstance(); ApiInvoker apiInvoker = ApiInvoker.getInstance();
@ -48,6 +50,11 @@ public class UserApi {
public void createUser (User body) throws ApiException { public void createUser (User body) throws ApiException {
Object postBody = body; 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 // create path and map variables
String path = "/user".replaceAll("\\{format\\}","json"); String path = "/user".replaceAll("\\{format\\}","json");
@ -102,6 +109,11 @@ public class UserApi {
public void createUsersWithArrayInput (List<User> body) throws ApiException { public void createUsersWithArrayInput (List<User> body) throws ApiException {
Object postBody = body; 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 // create path and map variables
String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
@ -156,6 +168,11 @@ public class UserApi {
public void createUsersWithListInput (List<User> body) throws ApiException { public void createUsersWithListInput (List<User> body) throws ApiException {
Object postBody = body; 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 // create path and map variables
String path = "/user/createWithList".replaceAll("\\{format\\}","json"); String path = "/user/createWithList".replaceAll("\\{format\\}","json");
@ -211,6 +228,16 @@ public class UserApi {
public String loginUser (String username, String password) throws ApiException { public String loginUser (String username, String password) throws ApiException {
Object postBody = null; 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 // create path and map variables
String path = "/user/login".replaceAll("\\{format\\}","json"); String path = "/user/login".replaceAll("\\{format\\}","json");
@ -387,6 +414,11 @@ public class UserApi {
throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); 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 // create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
@ -492,3 +524,4 @@ public class UserApi {
} }
} }

View File

@ -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();
}
}

View File

@ -1,10 +1,12 @@
package io.swagger.client.model; package io.swagger.client.model;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ApiModel(description = "") @ApiModel(description = "")
public class Category { public class Category {
@ -48,3 +50,5 @@ public class Category {
return sb.toString(); return sb.toString();
} }
} }

View File

@ -2,10 +2,12 @@ package io.swagger.client.model;
import java.util.Date; import java.util.Date;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ApiModel(description = "") @ApiModel(description = "")
public class Order { public class Order {
@ -109,3 +111,5 @@ public class Order {
return sb.toString(); return sb.toString();
} }
} }

View File

@ -1,13 +1,15 @@
package io.swagger.client.model; package io.swagger.client.model;
import io.swagger.client.model.Category; import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*; import java.util.*;
import io.swagger.client.model.Tag;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ApiModel(description = "") @ApiModel(description = "")
public class Pet { public class Pet {
@ -18,9 +20,9 @@ public class Pet {
@SerializedName("name") @SerializedName("name")
private String name = null; private String name = null;
@SerializedName("photoUrls") @SerializedName("photoUrls")
private List<String> photoUrls = new ArrayList<String>() ; private List<String> photoUrls = null;
@SerializedName("tags") @SerializedName("tags")
private List<Tag> tags = new ArrayList<Tag>() ; private List<Tag> tags = null;
public enum StatusEnum { public enum StatusEnum {
available, pending, sold, available, pending, sold,
}; };
@ -111,3 +113,5 @@ public class Pet {
return sb.toString(); return sb.toString();
} }
} }

View File

@ -1,10 +1,12 @@
package io.swagger.client.model; package io.swagger.client.model;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ApiModel(description = "") @ApiModel(description = "")
public class Tag { public class Tag {
@ -48,3 +50,5 @@ public class Tag {
return sb.toString(); return sb.toString();
} }
} }

View File

@ -1,10 +1,12 @@
package io.swagger.client.model; package io.swagger.client.model;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ApiModel(description = "") @ApiModel(description = "")
public class User { public class User {
@ -133,3 +135,5 @@ public class User {
return sb.toString(); return sb.toString();
} }
} }