Fix concurrent_unit_version in android-volley build.gradle

Closes #2228
This commit is contained in:
xhh 2016-03-01 10:50:41 +08:00
parent 75c2cc9029
commit cc08be6eda
8 changed files with 1985 additions and 121 deletions

View File

@ -74,7 +74,7 @@ dependencies {
compile "com.mcxiaoke.volley:library:${volley_version}@aar"
testCompile "junit:junit:$junit_version"
testCompile "org.robolectric:robolectric:${robolectric_version}"
testCompile "net.jodah:concurrentunit:${concurrentunitVersion}"
testCompile "net.jodah:concurrentunit:${concurrent_unit_version}"
}
afterEvaluate {

View File

@ -24,11 +24,11 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 23
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
@ -45,6 +45,10 @@ android {
}
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
@ -54,6 +58,8 @@ ext {
httpclient_version = "4.3.3"
volley_version = "1.0.19"
junit_version = "4.8.1"
robolectric_version = "3.0"
concurrent_unit_version = "0.4.2"
}
dependencies {
@ -63,6 +69,8 @@ dependencies {
compile "org.apache.httpcomponents:httpmime:$httpclient_version"
compile "com.mcxiaoke.volley:library:${volley_version}@aar"
testCompile "junit:junit:$junit_version"
testCompile "org.robolectric:robolectric:${robolectric_version}"
testCompile "net.jodah:concurrentunit:${concurrent_unit_version}"
}
afterEvaluate {

View File

@ -1,10 +1,16 @@
package io.swagger.client;
import android.content.Context;
import com.android.volley.Cache;
import com.android.volley.Network;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;
import com.android.volley.ResponseDelivery;
import com.android.volley.toolbox.BasicNetwork;
import com.android.volley.toolbox.HttpStack;
import com.android.volley.toolbox.HurlStack;
import com.android.volley.toolbox.NoCache;
import com.android.volley.toolbox.RequestFuture;
import com.google.gson.JsonParseException;
import org.apache.http.Consts;
@ -22,6 +28,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import io.swagger.client.auth.Authentication;
import io.swagger.client.auth.ApiKeyAuth;
@ -36,11 +45,12 @@ public class ApiInvoker {
private static ApiInvoker INSTANCE;
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private Context context;
private RequestQueue mRequestQueue;
private Map<String, Authentication> authentications;
private int connectionTimeout;
/** Content type "text/plain" with UTF-8 encoding. */
public static final ContentType TEXT_PLAIN_UTF8 = ContentType.create("text/plain", Consts.UTF_8);
@ -165,8 +175,16 @@ public class ApiInvoker {
return params;
}
public static void initializeInstance(Context context) {
INSTANCE = new ApiInvoker(context);
public static void initializeInstance() {
initializeInstance(null);
}
public static void initializeInstance(Cache cache) {
initializeInstance(cache, null, 0, null, 30);
}
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
setUserAgent("Android-Volley-Swagger");
// Setup authentications (key: authentication name, value: authentication).
@ -175,21 +193,56 @@ public class ApiInvoker {
INSTANCE.authentications.put("petstore_auth", new OAuth());
INSTANCE.authentications.put("test_api_client_id", new ApiKeyAuth("header", "x-test_api_client_id"));
INSTANCE.authentications.put("test_api_client_secret", new ApiKeyAuth("header", "x-test_api_client_secret"));
INSTANCE.authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
INSTANCE.authentications.put("test_api_key_query", new ApiKeyAuth("query", "test_api_key_query"));
INSTANCE.authentications.put("test_api_key_header", new ApiKeyAuth("header", "test_api_key_header"));
// Prevent the authentications from being modified.
INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
private ApiInvoker(Context context) {
this.context = context;
initConnectionManager();
}
public ApiInvoker() {
initConnectionManager();
private ApiInvoker(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
if(cache == null) cache = new NoCache();
if(network == null) {
HttpStack stack = new HurlStack();
network = new BasicNetwork(stack);
}
if(delivery == null) {
initConnectionRequest(cache, network);
} else {
initConnectionRequest(cache, network, threadPoolSize, delivery);
}
this.connectionTimeout = connectionTimeout;
}
public static ApiInvoker getInstance() {
@ -305,6 +358,14 @@ public class ApiInvoker {
throw new RuntimeException("No API key authentication configured!");
}
public void setConnectionTimeout(int connectionTimeout){
this.connectionTimeout = connectionTimeout;
}
public int getConnectionTimeout() {
return connectionTimeout;
}
/**
* Update query and header parameters based on authentication settings.
*
@ -318,7 +379,21 @@ public class ApiInvoker {
}
}
public String invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames) throws ApiException, InterruptedException, ExecutionException, TimeoutException {
RequestFuture<String> future = RequestFuture.newFuture();
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, future, future);
if(request != null) {
mRequestQueue.add(request);
return future.get(connectionTimeout, TimeUnit.SECONDS);
} else return "no data";
}
public void invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException {
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, stringRequest, errorListener);
if (request != null) mRequestQueue.add(request);
}
public Request<String> createRequest(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException {
StringBuilder b = new StringBuilder();
b.append("?");
@ -375,13 +450,13 @@ public class ApiInvoker {
}
formParamStr = formParamBuilder.toString();
}
Request request = null;
if ("GET".equals(method)) {
GetRequest request = new GetRequest(url, headers, null, stringRequest, errorListener);
mRequestQueue.add(request);
request = new GetRequest(url, headers, null, stringRequest, errorListener);
}
else if ("POST".equals(method)) {
PostRequest request = null;
request = null;
if (formParamStr != null) {
request = new PostRequest(url, headers, contentType, new StringEntity(formParamStr, "UTF-8"), stringRequest, errorListener);
} else if (body != null) {
@ -390,11 +465,12 @@ public class ApiInvoker {
} else {
request = new PostRequest(url, headers, contentType, new StringEntity(serialize(body), "UTF-8"), stringRequest, errorListener);
}
} else {
request = new PostRequest(url, headers, null, null, stringRequest, errorListener);
}
if(request != null) mRequestQueue.add(request);
}
else if ("PUT".equals(method)) {
PutRequest request = null;
request = null;
if (formParamStr != null) {
request = new PutRequest(url, headers, contentType, new StringEntity(formParamStr, "UTF-8"), stringRequest, errorListener);
} else if (body != null) {
@ -403,11 +479,12 @@ public class ApiInvoker {
} else {
request = new PutRequest(url, headers, contentType, new StringEntity(serialize(body), "UTF-8"), stringRequest, errorListener);
}
} else {
request = new PutRequest(url, headers, null, null, stringRequest, errorListener);
}
if(request != null) mRequestQueue.add(request);
}
else if ("DELETE".equals(method)) {
DeleteRequest request = null;
request = null;
if (formParamStr != null) {
request = new DeleteRequest(url, headers, contentType, new StringEntity(formParamStr, "UTF-8"), stringRequest, errorListener);
} else if (body != null) {
@ -416,11 +493,12 @@ public class ApiInvoker {
} else {
request = new DeleteRequest(url, headers, contentType, new StringEntity(serialize(body), "UTF-8"), stringRequest, errorListener);
}
} else {
request = new DeleteRequest(url, headers, null, null, stringRequest, errorListener);
}
if(request != null) mRequestQueue.add(request);
}
else if ("PATCH".equals(method)) {
PatchRequest request = null;
request = null;
if (formParamStr != null) {
request = new PatchRequest(url, headers, contentType, new StringEntity(formParamStr, "UTF-8"), stringRequest, errorListener);
} else if (body != null) {
@ -429,12 +507,24 @@ public class ApiInvoker {
} else {
request = new PatchRequest(url, headers, contentType, new StringEntity(serialize(body), "UTF-8"), stringRequest, errorListener);
}
}
if(request != null) mRequestQueue.add(request);
} else {
request = new PatchRequest(url, headers, null, null, stringRequest, errorListener);
}
}
return request;
}
private void initConnectionManager() {
mRequestQueue = Volley.newRequestQueue(context);
private void initConnectionRequest(Cache cache, Network network) {
mRequestQueue = new RequestQueue(cache, network);
mRequestQueue.start();
}
private void initConnectionRequest(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery) {
mRequestQueue = new RequestQueue(cache, network, threadPoolSize, delivery);
mRequestQueue.start();
}
public void stopQueue() {
mRequestQueue.stop();
}
}

View File

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

View File

@ -1,6 +1,5 @@
package io.swagger.client.api;
import io.swagger.client.Responses;
import io.swagger.client.ApiInvoker;
import io.swagger.client.ApiException;
import io.swagger.client.Pair;
@ -18,9 +17,12 @@ import java.io.File;
import org.apache.http.HttpEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
public class PetApi {
String basePath = "http://petstore.swagger.io/v2";
@ -44,12 +46,75 @@ public class PetApi {
/**
* Update an existing pet
*
* @param body Pet object that needs to be added to the store
* @return void
*/
public void updatePet (Pet body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// create path and map variables
String path = "/pet".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
"application/json","application/xml"
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "PUT", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Update an existing pet
*
* @param body Pet object that needs to be added to the store
* @return void
*/
public void updatePet (Pet body, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void updatePet (Pet body, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
@ -110,12 +175,75 @@ public class PetApi {
}
/**
* Add a new pet to the store
*
* @param body Pet object that needs to be added to the store
* @return void
*/
public void addPet (Pet body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// create path and map variables
String path = "/pet".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
"application/json","application/xml"
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Add a new pet to the store
*
* @param body Pet object that needs to be added to the store
* @return void
*/
public void addPet (Pet body, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void addPet (Pet body, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
@ -176,12 +304,77 @@ public class PetApi {
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma seperated strings
* @param status Status values that need to be considered for filter
* Finds Pets by status
* Multiple status values can be provided with comma separated strings
* @param status Status values that need to be considered for query
* @return List<Pet>
*/
public void findPetsByStatus (List<String> status, final Responses.PetListResponse responseListener, final Response.ErrorListener errorListener) {
*/
public List<Pet> findPetsByStatus (List<String> status) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// create path and map variables
String path = "/pet/findByStatus".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
queryParams.addAll(ApiInvoker.parameterToPairs("multi", "status", status));
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (List<Pet>) ApiInvoker.deserialize(response, "array", Pet.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma separated strings
* @param status Status values that need to be considered for query
*/
public void findPetsByStatus (List<String> status, final Response.Listener<List<Pet>> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -249,12 +442,77 @@ public class PetApi {
}
/**
* Finds Pets by tags
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
* @param tags Tags to filter by
* @return List<Pet>
*/
public List<Pet> findPetsByTags (List<String> tags) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// create path and map variables
String path = "/pet/findByTags".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
queryParams.addAll(ApiInvoker.parameterToPairs("multi", "tags", tags));
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (List<Pet>) ApiInvoker.deserialize(response, "array", Pet.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Finds Pets by tags
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
* @param tags Tags to filter by
* @return List<Pet>
*/
public void findPetsByTags (List<String> tags, final Responses.PetListResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void findPetsByTags (List<String> tags, final Response.Listener<List<Pet>> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -322,12 +580,81 @@ public class PetApi {
}
/**
* Find pet by ID
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
* @return Pet
*/
public Pet getPetById (Long petId) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'petId' when calling getPetById",
new ApiException(400, "Missing the required parameter 'petId' when calling getPetById"));
}
// create path and map variables
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth", "api_key" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (Pet) ApiInvoker.deserialize(response, "", Pet.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Find pet by ID
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
* @return Pet
*/
public void getPetById (Long petId, final Responses.PetResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void getPetById (Long petId, final Response.Listener<Pet> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -369,7 +696,7 @@ public class PetApi {
}
String[] authNames = new String[] { "api_key" };
String[] authNames = new String[] { "petstore_auth", "api_key" };
try {
apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,
@ -399,14 +726,93 @@ public class PetApi {
}
/**
* Updates a pet in the store with form data
*
* Updates a pet in the store with form data
*
* @param petId ID of pet that needs to be updated
* @param name Updated name of the pet
* @param status Updated status of the pet
* @return void
*/
public void updatePetWithForm (String petId, String name, String status, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void updatePetWithForm (String petId, String name, String status) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'petId' when calling updatePetWithForm",
new ApiException(400, "Missing the required parameter 'petId' when calling updatePetWithForm"));
}
// create path and map variables
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
"application/x-www-form-urlencoded"
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
if (name != null) {
builder.addTextBody("name", ApiInvoker.parameterToString(name), ApiInvoker.TEXT_PLAIN_UTF8);
}
if (status != null) {
builder.addTextBody("status", ApiInvoker.parameterToString(status), ApiInvoker.TEXT_PLAIN_UTF8);
}
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
formParams.put("name", ApiInvoker.parameterToString(name));
formParams.put("status", ApiInvoker.parameterToString(status));
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Updates a pet in the store with form data
*
* @param petId ID of pet that needs to be updated * @param name Updated name of the pet * @param status Updated status of the pet
*/
public void updatePetWithForm (String petId, String name, String status, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -483,13 +889,84 @@ public class PetApi {
}
/**
* Deletes a pet
*
* Deletes a pet
*
* @param petId Pet id to delete
* @param apiKey
* @return void
*/
public void deletePet (Long petId, String apiKey, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void deletePet (Long petId, String apiKey) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'petId' when calling deletePet",
new ApiException(400, "Missing the required parameter 'petId' when calling deletePet"));
}
// create path and map variables
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("api_key", ApiInvoker.parameterToString(apiKey));
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Deletes a pet
*
* @param petId Pet id to delete * @param apiKey
*/
public void deletePet (Long petId, String apiKey, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -558,14 +1035,93 @@ public class PetApi {
}
/**
* uploads an image
*
* uploads an image
*
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
* @return void
*/
public void uploadFile (Long petId, String additionalMetadata, File file, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void uploadFile (Long petId, String additionalMetadata, File file) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'petId' when calling uploadFile",
new ApiException(400, "Missing the required parameter 'petId' when calling uploadFile"));
}
// create path and map variables
String path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
"multipart/form-data"
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
if (additionalMetadata != null) {
builder.addTextBody("additionalMetadata", ApiInvoker.parameterToString(additionalMetadata), ApiInvoker.TEXT_PLAIN_UTF8);
}
if (file != null) {
builder.addBinaryBody("file", file);
}
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
formParams.put("additionalMetadata", ApiInvoker.parameterToString(additionalMetadata));
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* uploads an image
*
* @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload
*/
public void uploadFile (Long petId, String additionalMetadata, File file, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -641,4 +1197,279 @@ public class PetApi {
}
}
/**
* Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
* @return byte[]
*/
public byte[] petPetIdtestingByteArraytrueGet (Long petId) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet",
new ApiException(400, "Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet"));
}
// create path and map variables
String path = "/pet/{petId}?testing_byte_array=true".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth", "api_key" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (byte[]) ApiInvoker.deserialize(response, "", byte[].class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
*/
public void petPetIdtestingByteArraytrueGet (Long petId, final Response.Listener<byte[]> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet",
new ApiException(400, "Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet"));
}
// create path and map variables
String path = "/pet/{petId}?testing_byte_array=true".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth", "api_key" };
try {
apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
responseListener.onResponse((byte[]) ApiInvoker.deserialize(response, "", byte[].class));
} catch (ApiException exception) {
errorListener.onErrorResponse(new VolleyError(exception));
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
errorListener.onErrorResponse(error);
}
});
} catch (ApiException ex) {
errorListener.onErrorResponse(new VolleyError(ex));
}
}
/**
* Fake endpoint to test byte array in body parameter for adding a new pet to the store
*
* @param body Pet object in the form of byte array
* @return void
*/
public void addPetUsingByteArray (byte[] body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// create path and map variables
String path = "/pet?testing_byte_array=true".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
"application/json","application/xml"
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Fake endpoint to test byte array in body parameter for adding a new pet to the store
*
* @param body Pet object in the form of byte array
*/
public void addPetUsingByteArray (byte[] body, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
// create path and map variables
String path = "/pet?testing_byte_array=true".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
"application/json","application/xml"
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "petstore_auth" };
try {
apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
responseListener.onResponse(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
errorListener.onErrorResponse(error);
}
});
} catch (ApiException ex) {
errorListener.onErrorResponse(new VolleyError(ex));
}
}
}

View File

@ -1,6 +1,5 @@
package io.swagger.client.api;
import io.swagger.client.Responses;
import io.swagger.client.ApiInvoker;
import io.swagger.client.ApiException;
import io.swagger.client.Pair;
@ -12,15 +11,18 @@ import java.util.*;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import java.util.Map;
import io.swagger.client.model.Order;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
public class StoreApi {
String basePath = "http://petstore.swagger.io/v2";
@ -44,11 +46,212 @@ public class StoreApi {
/**
* Finds orders by status
* A single status value can be provided as a string
* @param status Status value that needs to be considered for query
* @return List<Order>
*/
public List<Order> findOrdersByStatus (String status) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// create path and map variables
String path = "/store/findByStatus".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
queryParams.addAll(ApiInvoker.parameterToPairs("", "status", status));
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "test_api_client_id", "test_api_client_secret" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (List<Order>) ApiInvoker.deserialize(response, "array", Order.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Finds orders by status
* A single status value can be provided as a string
* @param status Status value that needs to be considered for query
*/
public void findOrdersByStatus (String status, final Response.Listener<List<Order>> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
// create path and map variables
String path = "/store/findByStatus".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
queryParams.addAll(ApiInvoker.parameterToPairs("", "status", status));
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "test_api_client_id", "test_api_client_secret" };
try {
apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
responseListener.onResponse((List<Order>) ApiInvoker.deserialize(response, "array", Order.class));
} catch (ApiException exception) {
errorListener.onErrorResponse(new VolleyError(exception));
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
errorListener.onErrorResponse(error);
}
});
} catch (ApiException ex) {
errorListener.onErrorResponse(new VolleyError(ex));
}
}
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
* @return Map<String, Integer>
*/
public Map<String, Integer> getInventory () throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// create path and map variables
String path = "/store/inventory".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "api_key" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (Map<String, Integer>) ApiInvoker.deserialize(response, "map", Map.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
* @return Map<String, Integer>
*/
public void getInventory (final Responses.MapResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void getInventory (final Response.Listener<Map<String, Integer>> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -114,12 +317,75 @@ public class StoreApi {
}
/**
* Place an order for a pet
*
* @param body order placed for purchasing the pet
* @return Order
*/
public Order placeOrder (Order body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// create path and map variables
String path = "/store/order".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "test_api_client_id", "test_api_client_secret" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (Order) ApiInvoker.deserialize(response, "", Order.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Place an order for a pet
*
* @param body order placed for purchasing the pet
* @return Order
*/
public void placeOrder (Order body, final Responses.OrderResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void placeOrder (Order body, final Response.Listener<Order> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
@ -155,7 +421,7 @@ public class StoreApi {
}
String[] authNames = new String[] { };
String[] authNames = new String[] { "test_api_client_id", "test_api_client_secret" };
try {
apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames,
@ -185,12 +451,81 @@ public class StoreApi {
}
/**
* Find purchase order by ID
* For valid response try integer IDs with value &lt;= 5 or &gt; 10. Other values will generated exceptions
* @param orderId ID of pet that needs to be fetched
* @return Order
*/
public Order getOrderById (String orderId) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'orderId' when calling getOrderById",
new ApiException(400, "Missing the required parameter 'orderId' when calling getOrderById"));
}
// create path and map variables
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { "test_api_key_query", "test_api_key_header" };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (Order) ApiInvoker.deserialize(response, "", Order.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Find purchase order by ID
* For valid response try integer IDs with value &lt;= 5 or &gt; 10. Other values will generated exceptions
* @param orderId ID of pet that needs to be fetched
* @return Order
*/
public void getOrderById (String orderId, final Responses.OrderResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void getOrderById (String orderId, final Response.Listener<Order> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -232,7 +567,7 @@ public class StoreApi {
}
String[] authNames = new String[] { };
String[] authNames = new String[] { "test_api_key_query", "test_api_key_header" };
try {
apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,
@ -262,12 +597,81 @@ public class StoreApi {
}
/**
* Delete purchase order by ID
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
* @param orderId ID of the order that needs to be deleted
* @return void
*/
public void deleteOrder (String orderId) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
VolleyError error = new VolleyError("Missing the required parameter 'orderId' when calling deleteOrder",
new ApiException(400, "Missing the required parameter 'orderId' when calling deleteOrder"));
}
// create path and map variables
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Delete purchase order by ID
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
* @param orderId ID of the order that needs to be deleted
* @return void
*/
public void deleteOrder (String orderId, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void deleteOrder (String orderId, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;

View File

@ -1,6 +1,5 @@
package io.swagger.client.api;
import io.swagger.client.Responses;
import io.swagger.client.ApiInvoker;
import io.swagger.client.ApiException;
import io.swagger.client.Pair;
@ -18,9 +17,12 @@ import java.util.*;
import org.apache.http.HttpEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
public class UserApi {
String basePath = "http://petstore.swagger.io/v2";
@ -44,12 +46,75 @@ public class UserApi {
/**
* Create user
* This can only be done by the logged in user.
* @param body Created user object
* @return void
*/
public void createUser (User body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// create path and map variables
String path = "/user".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Create user
* This can only be done by the logged in user.
* @param body Created user object
* @return void
*/
public void createUser (User body, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void createUser (User body, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
@ -110,12 +175,75 @@ public class UserApi {
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @return void
*/
public void createUsersWithArrayInput (List<User> body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// create path and map variables
String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @return void
*/
public void createUsersWithArrayInput (List<User> body, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void createUsersWithArrayInput (List<User> body, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
@ -176,12 +304,75 @@ public class UserApi {
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @return void
*/
public void createUsersWithListInput (List<User> body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// create path and map variables
String path = "/user/createWithList".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @return void
*/
public void createUsersWithListInput (List<User> body, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void createUsersWithListInput (List<User> body, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
@ -242,13 +433,80 @@ public class UserApi {
}
/**
* Logs user into the system
*
* Logs user into the system
*
* @param username The user name for login
* @param password The password for login in clear text
* @return String
*/
public void loginUser (String username, String password, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public String loginUser (String username, String password) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// create path and map variables
String path = "/user/login".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
queryParams.addAll(ApiInvoker.parameterToPairs("", "username", username));
queryParams.addAll(ApiInvoker.parameterToPairs("", "password", password));
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (String) ApiInvoker.deserialize(response, "", String.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Logs user into the system
*
* @param username The user name for login * @param password The password for login in clear text
*/
public void loginUser (String username, String password, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -318,11 +576,74 @@ public class UserApi {
}
/**
* Logs out current logged in user session
*
* @return void
*/
public void logoutUser () throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// create path and map variables
String path = "/user/logout".replaceAll("\\{format\\}","json");
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Logs out current logged in user session
*
* @return void
*/
public void logoutUser (final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void logoutUser (final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -383,12 +704,81 @@ public class UserApi {
}
/**
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
* @return User
*/
public User getUserByName (String username) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
VolleyError error = new VolleyError("Missing the required parameter 'username' when calling getUserByName",
new ApiException(400, "Missing the required parameter 'username' when calling getUserByName"));
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return (User) ApiInvoker.deserialize(response, "", User.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
* @return User
*/
public void getUserByName (String username, final Responses.UserResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void getUserByName (String username, final Response.Listener<User> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;
@ -460,13 +850,82 @@ public class UserApi {
}
/**
* Updated user
* This can only be done by the logged in user.
* Updated user
* This can only be done by the logged in user.
* @param username name that need to be deleted
* @param body Updated user object
* @return void
*/
public void updateUser (String username, User body, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void updateUser (String username, User body) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = body;
// verify the required parameter 'username' is set
if (username == null) {
VolleyError error = new VolleyError("Missing the required parameter 'username' when calling updateUser",
new ApiException(400, "Missing the required parameter 'username' when calling updateUser"));
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "PUT", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Updated user
* This can only be done by the logged in user.
* @param username name that need to be deleted * @param body Updated user object
*/
public void updateUser (String username, User body, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = body;
@ -533,12 +992,81 @@ public class UserApi {
}
/**
* Delete user
* This can only be done by the logged in user.
* @param username The name that needs to be deleted
* @return void
*/
public void deleteUser (String username) throws TimeoutException, ExecutionException, InterruptedException, ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
VolleyError error = new VolleyError("Missing the required parameter 'username' when calling deleteUser",
new ApiException(400, "Missing the required parameter 'username' when calling deleteUser"));
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
// query params
List<Pair> queryParams = new ArrayList<Pair>();
// header params
Map<String, String> headerParams = new HashMap<String, String>();
// form params
Map<String, String> formParams = new HashMap<String, String>();
String[] contentTypes = {
};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if (contentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity httpEntity = builder.build();
postBody = httpEntity;
} else {
// normal form params
}
String[] authNames = new String[] { };
try {
String response = apiInvoker.invokeAPI (basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(response != null){
return ;
} else {
return ;
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}
/**
* Delete user
* This can only be done by the logged in user.
* @param username The name that needs to be deleted
* @return void
*/
public void deleteUser (String username, final Responses.StringResponse responseListener, final Response.ErrorListener errorListener) {
*/
public void deleteUser (String username, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
Object postBody = null;

View File

@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
String value;
if (apiKey == null) {
return;
}
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;
} else {