Code reformatting

This commit is contained in:
Ron
2015-06-07 11:56:08 -04:00
parent 22d7db2cb4
commit 1c2d0656b0
732 changed files with 61242 additions and 55773 deletions

View File

@@ -1,167 +1,167 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>swagger-java-client</artifactId>
<packaging>jar</packaging>
<name>swagger-java-client</name>
<version>1.0.0</version>
<scm>
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>swagger-java-client</artifactId>
<packaging>jar</packaging>
<name>swagger-java-client</name>
<version>1.0.0</version>
<scm>
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<swagger-annotations-version>1.5.0</swagger-annotations-version>
<jersey-version>1.18</jersey-version>
<jackson-version>2.4.2</jackson-version>
<jodatime-version>2.3</jodatime-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<swagger-annotations-version>1.5.0</swagger-annotations-version>
<jersey-version>1.18</jersey-version>
<jackson-version>2.4.2</jackson-version>
<jodatime-version>2.3</jodatime-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>
</project>

View File

@@ -1,506 +1,495 @@
package io.swagger.client;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.MediaType;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.HashMap;
import java.util.List;
import java.util.Date;
import java.util.TimeZone;
import java.net.URLEncoder;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import io.swagger.client.auth.ApiKeyAuth;
import io.swagger.client.auth.Authentication;
import io.swagger.client.auth.HttpBasicAuth;
import io.swagger.client.auth.ApiKeyAuth;
import io.swagger.client.auth.OAuth;
import javax.ws.rs.core.Response.Status.Family;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
public class ApiClient {
private Map<String, Client> hostMap = new HashMap<String, Client>();
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private boolean debugging = false;
private String basePath = "http://petstore.swagger.io/v2";
private Map<String, Client> hostMap = new HashMap<String, Client>();
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private boolean debugging = false;
private String basePath = "http://petstore.swagger.io/v2";
private Map<String, Authentication> authentications;
private Map<String, Authentication> authentications;
private DateFormat dateFormat;
private DateFormat dateFormat;
public ApiClient() {
// Use ISO 8601 format for date and datetime.
// See https://en.wikipedia.org/wiki/ISO_8601
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
public ApiClient() {
// Use ISO 8601 format for date and datetime.
// See https://en.wikipedia.org/wiki/ISO_8601
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
// Use UTC as the default time zone.
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Use UTC as the default time zone.
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Set default User-Agent.
setUserAgent("Java-Swagger");
// Set default User-Agent.
setUserAgent("Java-Swagger");
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("petstore_auth", new OAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
public String getBasePath() {
return basePath;
}
public ApiClient setBasePath(String basePath) {
this.basePath = basePath;
return this;
}
/**
* Get authentications (key: authentication name, value: authentication).
*/
public Map<String, Authentication> getAuthentications() {
return authentications;
}
/**
* Get authentication for the given name.
*
* @param authName The authentication name
* @return The authentication, null if not found
*/
public Authentication getAuthentication(String authName) {
return authentications.get(authName);
}
/**
* Helper method to set username for the first HTTP basic authentication.
*/
public void setUsername(String username) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setUsername(username);
return;
}
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("petstore_auth", new OAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
throw new RuntimeException("No HTTP basic authentication configured!");
}
/**
* Helper method to set password for the first HTTP basic authentication.
*/
public void setPassword(String password) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setPassword(password);
return;
}
public String getBasePath() {
return basePath;
}
throw new RuntimeException("No HTTP basic authentication configured!");
}
/**
* Helper method to set API key value for the first API key authentication.
*/
public void setApiKey(String apiKey) {
for (Authentication auth : authentications.values()) {
if (auth instanceof ApiKeyAuth) {
((ApiKeyAuth) auth).setApiKey(apiKey);
return;
}
public ApiClient setBasePath(String basePath) {
this.basePath = basePath;
return this;
}
throw new RuntimeException("No API key authentication configured!");
}
/**
* Helper method to set API key prefix for the first API key authentication.
*/
public void setApiKeyPrefix(String apiKeyPrefix) {
for (Authentication auth : authentications.values()) {
if (auth instanceof ApiKeyAuth) {
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
return;
}
/**
* Get authentications (key: authentication name, value: authentication).
*/
public Map<String, Authentication> getAuthentications() {
return authentications;
}
throw new RuntimeException("No API key authentication configured!");
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*/
public ApiClient setUserAgent(String userAgent) {
addDefaultHeader("User-Agent", userAgent);
return this;
}
/**
* Add a default header.
*
* @param key The header's key
* @param value The header's value
*/
public ApiClient addDefaultHeader(String key, String value) {
defaultHeaderMap.put(key, value);
return this;
}
/**
* Check that whether debugging is enabled for this API client.
*/
public boolean isDebugging() {
return debugging;
}
/**
* Enable/disable debugging for this API client.
*
* @param debugging To enable (true) or disable (false) debugging
*/
public ApiClient setDebugging(boolean debugging) {
this.debugging = debugging;
return this;
}
/**
* Get the date format used to parse/format date parameters.
*/
public DateFormat getDateFormat() {
return dateFormat;
}
/**
* Set the date format used to parse/format date parameters.
*/
public ApiClient getDateFormat(DateFormat dateFormat) {
this.dateFormat = dateFormat;
return this;
}
/**
* Parse the given string into Date object.
*/
public Date parseDate(String str) {
try {
return dateFormat.parse(str);
} catch (java.text.ParseException e) {
throw new RuntimeException(e);
/**
* Get authentication for the given name.
*
* @param authName The authentication name
* @return The authentication, null if not found
*/
public Authentication getAuthentication(String authName) {
return authentications.get(authName);
}
}
/**
* Format the given Date object into string.
*/
public String formatDate(Date date) {
return dateFormat.format(date);
}
/**
* Format the given parameter object into string.
*/
public String parameterToString(Object param) {
if (param == null) {
return "";
} else if (param instanceof Date) {
return formatDate((Date) param);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection)param) {
if(b.length() > 0) {
b.append(",");
/**
* Helper method to set username for the first HTTP basic authentication.
*/
public void setUsername(String username) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setUsername(username);
return;
}
}
b.append(String.valueOf(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
}
/**
* Select the Accept header's value from the given accepts array:
* if JSON exists in the given array, use it;
* otherwise use all of them (joining into a string)
*
* @param accepts The accepts array to select from
* @return The Accept header to use. If the given array is empty,
* null will be returned (not to set the Accept header explicitly).
*/
public String selectHeaderAccept(String[] accepts) {
if (accepts.length == 0) return null;
if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json";
return StringUtil.join(accepts, ",");
}
/**
* Select the Content-Type header's value from the given array:
* if JSON exists in the given array, use it;
* otherwise use the first one of the array.
*
* @param contentTypes The Content-Type array to select from
* @return The Content-Type header to use. If the given array is empty,
* JSON will be used.
*/
public String selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0) return "application/json";
if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json";
return contentTypes[0];
}
/**
* Escape the given string to be used as URL query value.
*/
public String escapeString(String str) {
try {
return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
} catch (UnsupportedEncodingException e) {
return str;
}
}
/**
* Deserialize the given JSON string to Java object.
*
* @param json The JSON string
* @param containerType The container type, one of "list", "array" or ""
* @param cls The type of the Java object
* @return The deserialized Java object
*/
public Object deserialize(String json, String containerType, Class cls) throws ApiException {
if(null != containerType) {
containerType = containerType.toLowerCase();
}
try{
if("list".equals(containerType) || "array".equals(containerType)) {
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
return response;
}
else if(String.class.equals(cls)) {
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
return json.substring(1, json.length() - 2);
else
return json;
}
else {
return JsonUtil.getJsonMapper().readValue(json, cls);
}
}
catch (IOException e) {
throw new ApiException(500, e.getMessage(), null, json);
}
}
/**
* Serialize the given Java object into JSON string.
*/
public String serialize(Object obj) throws ApiException {
try {
if (obj != null)
return JsonUtil.getJsonMapper().writeValueAsString(obj);
else
return null;
}
catch (Exception e) {
throw new ApiException(500, e.getMessage());
}
}
/**
* Invoke API by sending HTTP request with the given options.
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "POST", "PUT", and "DELETE"
* @param queryParams The query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param formParams The form parameters
* @param accept The request's Accept header
* @param contentType The request's Content-Type header
* @param authNames The authentications to apply
* @return The response body in type of string
*/
public String invokeAPI(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
updateParamsForAuth(authNames, queryParams, headerParams);
Client client = getClient();
StringBuilder b = new StringBuilder();
for(String key : queryParams.keySet()) {
String value = queryParams.get(key);
if (value != null){
if(b.toString().length() == 0)
b.append("?");
else
b.append("&");
b.append(escapeString(key)).append("=").append(escapeString(value));
}
}
String querystring = b.toString();
Builder builder;
if (accept == null)
builder = client.resource(basePath + path + querystring).getRequestBuilder();
else
builder = client.resource(basePath + path + querystring).accept(accept);
for(String key : headerParams.keySet()) {
builder = builder.header(key, headerParams.get(key));
}
for(String key : defaultHeaderMap.keySet()) {
if(!headerParams.containsKey(key)) {
builder = builder.header(key, defaultHeaderMap.get(key));
}
throw new RuntimeException("No HTTP basic authentication configured!");
}
ClientResponse response = null;
if("GET".equals(method)) {
response = (ClientResponse) builder.get(ClientResponse.class);
}
else if ("POST".equals(method)) {
if (contentType.startsWith("application/x-www-form-urlencoded")) {
String encodedFormParams = this
.getXWWWFormUrlencodedParams(formParams);
response = builder.type(contentType).post(ClientResponse.class,
encodedFormParams);
} else if (body == null) {
response = builder.post(ClientResponse.class, null);
} else if(body instanceof FormDataMultiPart) {
response = builder.type(contentType).post(ClientResponse.class, body);
}
else
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
}
else if ("PUT".equals(method)) {
if ("application/x-www-form-urlencoded".equals(contentType)) {
String encodedFormParams = this
.getXWWWFormUrlencodedParams(formParams);
response = builder.type(contentType).put(ClientResponse.class,
encodedFormParams);
} else if(body == null) {
response = builder.put(ClientResponse.class, serialize(body));
} else {
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
}
}
else if ("DELETE".equals(method)) {
if ("application/x-www-form-urlencoded".equals(contentType)) {
String encodedFormParams = this
.getXWWWFormUrlencodedParams(formParams);
response = builder.type(contentType).delete(ClientResponse.class,
encodedFormParams);
} else if(body == null) {
response = builder.delete(ClientResponse.class);
} else {
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
}
}
else {
throw new ApiException(500, "unknown method type " + method);
}
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
return null;
}
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
if(response.hasEntity()) {
return (String) response.getEntity(String.class);
}
else {
return "";
}
}
else {
String message = "error";
String respBody = null;
if(response.hasEntity()) {
try{
respBody = String.valueOf(response.getEntity(String.class));
message = respBody;
/**
* Helper method to set password for the first HTTP basic authentication.
*/
public void setPassword(String password) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setPassword(password);
return;
}
}
catch (RuntimeException e) {
// e.printStackTrace();
throw new RuntimeException("No HTTP basic authentication configured!");
}
/**
* Helper method to set API key value for the first API key authentication.
*/
public void setApiKey(String apiKey) {
for (Authentication auth : authentications.values()) {
if (auth instanceof ApiKeyAuth) {
((ApiKeyAuth) auth).setApiKey(apiKey);
return;
}
}
}
throw new ApiException(
response.getClientResponseStatus().getStatusCode(),
message,
response.getHeaders(),
respBody);
throw new RuntimeException("No API key authentication configured!");
}
}
/**
* Update query and header parameters based on authentication settings.
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
auth.applyToParams(queryParams, headerParams);
/**
* Helper method to set API key prefix for the first API key authentication.
*/
public void setApiKeyPrefix(String apiKeyPrefix) {
for (Authentication auth : authentications.values()) {
if (auth instanceof ApiKeyAuth) {
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
return;
}
}
throw new RuntimeException("No API key authentication configured!");
}
}
/**
* Encode the given form parameters as request body.
*/
private String getXWWWFormUrlencodedParams(Map<String, String> formParams) {
StringBuilder formParamBuilder = new StringBuilder();
for (Entry<String, String> param : formParams.entrySet()) {
String keyStr = parameterToString(param.getKey());
String valueStr = parameterToString(param.getValue());
try {
formParamBuilder.append(URLEncoder.encode(keyStr, "utf8"))
.append("=")
.append(URLEncoder.encode(valueStr, "utf8"));
formParamBuilder.append("&");
} catch (UnsupportedEncodingException e) {
// move on to next
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*/
public ApiClient setUserAgent(String userAgent) {
addDefaultHeader("User-Agent", userAgent);
return this;
}
String encodedFormParams = formParamBuilder.toString();
if (encodedFormParams.endsWith("&")) {
encodedFormParams = encodedFormParams.substring(0,
encodedFormParams.length() - 1);
}
return encodedFormParams;
}
/**
* Get an existing client or create a new client to handle HTTP request.
*/
private Client getClient() {
if(!hostMap.containsKey(basePath)) {
Client client = Client.create();
if (debugging)
client.addFilter(new LoggingFilter());
hostMap.put(basePath, client);
/**
* Add a default header.
*
* @param key The header's key
* @param value The header's value
*/
public ApiClient addDefaultHeader(String key, String value) {
defaultHeaderMap.put(key, value);
return this;
}
/**
* Check that whether debugging is enabled for this API client.
*/
public boolean isDebugging() {
return debugging;
}
/**
* Enable/disable debugging for this API client.
*
* @param debugging To enable (true) or disable (false) debugging
*/
public ApiClient setDebugging(boolean debugging) {
this.debugging = debugging;
return this;
}
/**
* Get the date format used to parse/format date parameters.
*/
public DateFormat getDateFormat() {
return dateFormat;
}
/**
* Set the date format used to parse/format date parameters.
*/
public ApiClient getDateFormat(DateFormat dateFormat) {
this.dateFormat = dateFormat;
return this;
}
/**
* Parse the given string into Date object.
*/
public Date parseDate(String str) {
try {
return dateFormat.parse(str);
} catch (java.text.ParseException e) {
throw new RuntimeException(e);
}
}
/**
* Format the given Date object into string.
*/
public String formatDate(Date date) {
return dateFormat.format(date);
}
/**
* Format the given parameter object into string.
*/
public String parameterToString(Object param) {
if (param == null) {
return "";
} else if (param instanceof Date) {
return formatDate((Date) param);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for (Object o : (Collection) param) {
if (b.length() > 0) {
b.append(",");
}
b.append(String.valueOf(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
}
/**
* Select the Accept header's value from the given accepts array:
* if JSON exists in the given array, use it;
* otherwise use all of them (joining into a string)
*
* @param accepts The accepts array to select from
* @return The Accept header to use. If the given array is empty,
* null will be returned (not to set the Accept header explicitly).
*/
public String selectHeaderAccept(String[] accepts) {
if (accepts.length == 0) {
return null;
}
if (StringUtil.containsIgnoreCase(accepts, "application/json")) {
return "application/json";
}
return StringUtil.join(accepts, ",");
}
/**
* Select the Content-Type header's value from the given array:
* if JSON exists in the given array, use it;
* otherwise use the first one of the array.
*
* @param contentTypes The Content-Type array to select from
* @return The Content-Type header to use. If the given array is empty,
* JSON will be used.
*/
public String selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0) {
return "application/json";
}
if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) {
return "application/json";
}
return contentTypes[0];
}
/**
* Escape the given string to be used as URL query value.
*/
public String escapeString(String str) {
try {
return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
} catch (UnsupportedEncodingException e) {
return str;
}
}
/**
* Deserialize the given JSON string to Java object.
*
* @param json The JSON string
* @param containerType The container type, one of "list", "array" or ""
* @param cls The type of the Java object
* @return The deserialized Java object
*/
public Object deserialize(String json, String containerType, Class cls) throws ApiException {
if (null != containerType) {
containerType = containerType.toLowerCase();
}
try {
if ("list".equals(containerType) || "array".equals(containerType)) {
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
return response;
} else if (String.class.equals(cls)) {
if (json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1) {
return json.substring(1, json.length() - 2);
} else {
return json;
}
} else {
return JsonUtil.getJsonMapper().readValue(json, cls);
}
} catch (IOException e) {
throw new ApiException(500, e.getMessage(), null, json);
}
}
/**
* Serialize the given Java object into JSON string.
*/
public String serialize(Object obj) throws ApiException {
try {
if (obj != null) {
return JsonUtil.getJsonMapper().writeValueAsString(obj);
} else {
return null;
}
} catch (Exception e) {
throw new ApiException(500, e.getMessage());
}
}
/**
* Invoke API by sending HTTP request with the given options.
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "POST", "PUT", and "DELETE"
* @param queryParams The query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param formParams The form parameters
* @param accept The request's Accept header
* @param contentType The request's Content-Type header
* @param authNames The authentications to apply
* @return The response body in type of string
*/
public String invokeAPI(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
updateParamsForAuth(authNames, queryParams, headerParams);
Client client = getClient();
StringBuilder b = new StringBuilder();
for (String key : queryParams.keySet()) {
String value = queryParams.get(key);
if (value != null) {
if (b.toString().length() == 0) {
b.append("?");
} else {
b.append("&");
}
b.append(escapeString(key)).append("=").append(escapeString(value));
}
}
String querystring = b.toString();
Builder builder;
if (accept == null) {
builder = client.resource(basePath + path + querystring).getRequestBuilder();
} else {
builder = client.resource(basePath + path + querystring).accept(accept);
}
for (String key : headerParams.keySet()) {
builder = builder.header(key, headerParams.get(key));
}
for (String key : defaultHeaderMap.keySet()) {
if (!headerParams.containsKey(key)) {
builder = builder.header(key, defaultHeaderMap.get(key));
}
}
ClientResponse response = null;
if ("GET".equals(method)) {
response = (ClientResponse) builder.get(ClientResponse.class);
} else if ("POST".equals(method)) {
if (contentType.startsWith("application/x-www-form-urlencoded")) {
String encodedFormParams = this
.getXWWWFormUrlencodedParams(formParams);
response = builder.type(contentType).post(ClientResponse.class,
encodedFormParams);
} else if (body == null) {
response = builder.post(ClientResponse.class, null);
} else if (body instanceof FormDataMultiPart) {
response = builder.type(contentType).post(ClientResponse.class, body);
} else {
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
}
} else if ("PUT".equals(method)) {
if ("application/x-www-form-urlencoded".equals(contentType)) {
String encodedFormParams = this
.getXWWWFormUrlencodedParams(formParams);
response = builder.type(contentType).put(ClientResponse.class,
encodedFormParams);
} else if (body == null) {
response = builder.put(ClientResponse.class, serialize(body));
} else {
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
}
} else if ("DELETE".equals(method)) {
if ("application/x-www-form-urlencoded".equals(contentType)) {
String encodedFormParams = this
.getXWWWFormUrlencodedParams(formParams);
response = builder.type(contentType).delete(ClientResponse.class,
encodedFormParams);
} else if (body == null) {
response = builder.delete(ClientResponse.class);
} else {
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
}
} else {
throw new ApiException(500, "unknown method type " + method);
}
if (response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
return null;
} else if (response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
if (response.hasEntity()) {
return (String) response.getEntity(String.class);
} else {
return "";
}
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.getEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getClientResponseStatus().getStatusCode(),
message,
response.getHeaders(),
respBody);
}
}
/**
* Update query and header parameters based on authentication settings.
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) {
throw new RuntimeException("Authentication undefined: " + authName);
}
auth.applyToParams(queryParams, headerParams);
}
}
/**
* Encode the given form parameters as request body.
*/
private String getXWWWFormUrlencodedParams(Map<String, String> formParams) {
StringBuilder formParamBuilder = new StringBuilder();
for (Entry<String, String> param : formParams.entrySet()) {
String keyStr = parameterToString(param.getKey());
String valueStr = parameterToString(param.getValue());
try {
formParamBuilder.append(URLEncoder.encode(keyStr, "utf8"))
.append("=")
.append(URLEncoder.encode(valueStr, "utf8"));
formParamBuilder.append("&");
} catch (UnsupportedEncodingException e) {
// move on to next
}
}
String encodedFormParams = formParamBuilder.toString();
if (encodedFormParams.endsWith("&")) {
encodedFormParams = encodedFormParams.substring(0,
encodedFormParams.length() - 1);
}
return encodedFormParams;
}
/**
* Get an existing client or create a new client to handle HTTP request.
*/
private Client getClient() {
if (!hostMap.containsKey(basePath)) {
Client client = Client.create();
if (debugging) {
client.addFilter(new LoggingFilter());
}
hostMap.put(basePath, client);
}
return hostMap.get(basePath);
}
return hostMap.get(basePath);
}
}

View File

@@ -1,47 +1,48 @@
package io.swagger.client;
import java.util.Map;
import java.util.List;
import java.util.Map;
public class ApiException extends Exception {
private int code = 0;
private String message = null;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
private int code = 0;
private String message = null;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
public ApiException() {}
public ApiException() {
}
public ApiException(int code, String message) {
this.code = code;
this.message = message;
}
public ApiException(int code, String message) {
this.code = code;
this.message = message;
}
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
this.code = code;
this.message = message;
this.responseHeaders = responseHeaders;
this.responseBody = responseBody;
}
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
this.code = code;
this.message = message;
this.responseHeaders = responseHeaders;
this.responseBody = responseBody;
}
public int getCode() {
return code;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
public String getMessage() {
return message;
}
/**
* Get the HTTP response headers.
*/
public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
}
/**
* Get the HTTP response headers.
*/
public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
}
/**
* Get the HTTP response body.
*/
public String getResponseBody() {
return responseBody;
}
/**
* Get the HTTP response body.
*/
public String getResponseBody() {
return responseBody;
}
}

View File

@@ -1,21 +1,21 @@
package io.swagger.client;
public class Configuration {
private static ApiClient defaultApiClient = new ApiClient();
private static ApiClient defaultApiClient = new ApiClient();
/**
* Get the default API client, which would be used when creating API
* instances without providing an API client.
*/
public static ApiClient getDefaultApiClient() {
return defaultApiClient;
}
/**
* Get the default API client, which would be used when creating API
* instances without providing an API client.
*/
public static ApiClient getDefaultApiClient() {
return defaultApiClient;
}
/**
* Set the default API client, which would be used when creating API
* instances without providing an API client.
*/
public static void setDefaultApiClient(ApiClient apiClient) {
defaultApiClient = apiClient;
}
/**
* Set the default API client, which would be used when creating API
* instances without providing an API client.
*/
public static void setDefaultApiClient(ApiClient apiClient) {
defaultApiClient = apiClient;
}
}

View File

@@ -1,23 +1,16 @@
package io.swagger.client;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.datatype.joda.*;
public class JsonUtil {
public static ObjectMapper mapper;
public static ObjectMapper mapper;
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JodaModule());
}
public static ObjectMapper getJsonMapper() {
return mapper;
}
public static ObjectMapper getJsonMapper() {
return mapper;
}
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JodaModule());
}
}

View File

@@ -1,41 +1,47 @@
package io.swagger.client;
public class StringUtil {
/**
* Check if the given array contains the given value (with case-insensitive comparison).
*
* @param array The array
* @param value The value to search
* @return true if the array contains the value
*/
public static boolean containsIgnoreCase(String[] array, String value) {
for (String str : array) {
if (value == null && str == null) return true;
if (value != null && value.equalsIgnoreCase(str)) return true;
/**
* Check if the given array contains the given value (with case-insensitive comparison).
*
* @param array The array
* @param value The value to search
* @return true if the array contains the value
*/
public static boolean containsIgnoreCase(String[] array, String value) {
for (String str : array) {
if (value == null && str == null) {
return true;
}
if (value != null && value.equalsIgnoreCase(str)) {
return true;
}
}
return false;
}
return false;
}
/**
* Join an array of strings with the given separator.
* <p>
* Note: This might be replaced by utility method from commons-lang or guava someday
* if one of those libraries is added as dependency.
* </p>
*
* @param array The array of strings
* @param separator The separator
* @return the resulting string
*/
public static String join(String[] array, String separator) {
int len = array.length;
if (len == 0) return "";
/**
* Join an array of strings with the given separator.
* <p>
* Note: This might be replaced by utility method from commons-lang or guava someday
* if one of those libraries is added as dependency.
* </p>
*
* @param array The array of strings
* @param separator The separator
* @return the resulting string
*/
public static String join(String[] array, String separator) {
int len = array.length;
if (len == 0) {
return "";
}
StringBuilder out = new StringBuilder();
out.append(array[0]);
for (int i = 1; i < len; i++) {
out.append(separator).append(array[i]);
StringBuilder out = new StringBuilder();
out.append(array[0]);
for (int i = 1; i < len; i++) {
out.append(separator).append(array[i]);
}
return out.toString();
}
return out.toString();
}
}

View File

@@ -1,282 +1,258 @@
package io.swagger.client.api;
import io.swagger.client.ApiException;
import com.sun.jersey.multipart.FormDataMultiPart;
import io.swagger.client.ApiClient;
import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.model.*;
import java.util.*;
import java.util.Map;
import io.swagger.client.model.Order;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;
import javax.ws.rs.core.MediaType;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
public class StoreApi {
private ApiClient apiClient;
private ApiClient apiClient;
public StoreApi() {
this(Configuration.getDefaultApiClient());
}
public StoreApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
* @return Map<String, Integer>
*/
public Map<String, Integer> getInventory () throws ApiException {
Object postBody = null;
// create path and map variables
String path = "/store/inventory".replaceAll("\\{format\\}","json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public StoreApi() {
this(Configuration.getDefaultApiClient());
}
try {
String[] authNames = new String[] { "api_key" };
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return (Map<String, Integer>) apiClient.deserialize(response, "map", Map.class);
}
else {
return null;
}
} catch (ApiException ex) {
throw ex;
}
}
/**
* Place an order for a pet
*
* @param body order placed for purchasing the pet
* @return Order
*/
public Order placeOrder (Order body) throws ApiException {
Object postBody = body;
// create path and map variables
String path = "/store/order".replaceAll("\\{format\\}","json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public StoreApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return (Order) apiClient.deserialize(response, "", Order.class);
}
else {
return null;
}
} catch (ApiException 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 Order getOrderById (String orderId) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw 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" + "\\}", apiClient.escapeString(orderId.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public ApiClient getApiClient() {
return apiClient;
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return (Order) apiClient.deserialize(response, "", Order.class);
}
else {
return null;
}
} catch (ApiException 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) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw 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" + "\\}", apiClient.escapeString(orderId.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
throw ex;
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
*
* @return Map<String, Integer>
*/
public Map<String, Integer> getInventory() throws ApiException {
Object postBody = null;
// create path and map variables
String path = "/store/inventory".replaceAll("\\{format\\}", "json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{"api_key"};
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return (Map<String, Integer>) apiClient.deserialize(response, "map", Map.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
}
}
}
/**
* Place an order for a pet
*
* @param body order placed for purchasing the pet
* @return Order
*/
public Order placeOrder(Order body) throws ApiException {
Object postBody = body;
// create path and map variables
String path = "/store/order".replaceAll("\\{format\\}", "json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return (Order) apiClient.deserialize(response, "", Order.class);
} else {
return null;
}
} catch (ApiException 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 Order getOrderById(String orderId) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw 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" + "\\}", apiClient.escapeString(orderId.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return (Order) apiClient.deserialize(response, "", Order.class);
} else {
return null;
}
} catch (ApiException 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) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw 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" + "\\}", apiClient.escapeString(orderId.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return;
} else {
return;
}
} catch (ApiException ex) {
throw ex;
}
}
}

View File

@@ -1,522 +1,486 @@
package io.swagger.client.api;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.model.*;
import java.util.*;
import io.swagger.client.model.User;
import java.util.*;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;
import io.swagger.client.ApiClient;
import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.model.User;
import javax.ws.rs.core.MediaType;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class UserApi {
private ApiClient apiClient;
private ApiClient apiClient;
public UserApi() {
this(Configuration.getDefaultApiClient());
}
public UserApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* 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 ApiException {
Object postBody = body;
// create path and map variables
String path = "/user".replaceAll("\\{format\\}","json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public UserApi() {
this(Configuration.getDefaultApiClient());
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException 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) throws ApiException {
Object postBody = body;
// create path and map variables
String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public UserApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException 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) throws ApiException {
Object postBody = body;
// create path and map variables
String path = "/user/createWithList".replaceAll("\\{format\\}","json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public ApiClient getApiClient() {
return apiClient;
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
throw ex;
}
}
/**
* Logs user into the system
*
* @param username The user name for login
* @param password The password for login in clear text
* @return String
*/
public String loginUser (String username, String password) throws ApiException {
Object postBody = null;
// create path and map variables
String path = "/user/login".replaceAll("\\{format\\}","json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if (username != null)
queryParams.put("username", apiClient.parameterToString(username));
if (password != null)
queryParams.put("password", apiClient.parameterToString(password));
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return (String) apiClient.deserialize(response, "", String.class);
}
else {
return null;
}
} catch (ApiException ex) {
throw ex;
}
}
/**
* Logs out current logged in user session
*
* @return void
*/
public void logoutUser () throws ApiException {
Object postBody = null;
// create path and map variables
String path = "/user/logout".replaceAll("\\{format\\}","json");
/**
* 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 ApiException {
Object postBody = body;
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
// create path and map variables
String path = "/user".replaceAll("\\{format\\}", "json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return;
} else {
return;
}
} catch (ApiException ex) {
throw ex;
}
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
throw ex;
}
}
/**
* 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 ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName");
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @return void
*/
public void createUsersWithArrayInput(List<User> body) throws ApiException {
Object postBody = body;
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json")
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
// create path and map variables
String path = "/user/createWithArray".replaceAll("\\{format\\}", "json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
final String[] contentTypes = {
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return;
} else {
return;
}
} catch (ApiException ex) {
throw ex;
}
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return (User) apiClient.deserialize(response, "", User.class);
}
else {
return null;
}
} catch (ApiException 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
* @return void
*/
public void updateUser (String username, User body) throws ApiException {
Object postBody = body;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser");
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @return void
*/
public void createUsersWithListInput(List<User> body) throws ApiException {
Object postBody = body;
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json")
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
// create path and map variables
String path = "/user/createWithList".replaceAll("\\{format\\}", "json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
final String[] contentTypes = {
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return;
} else {
return;
}
} catch (ApiException ex) {
throw ex;
}
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "PUT", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException 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) throws ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser");
}
/**
* Logs user into the system
*
* @param username The user name for login
* @param password The password for login in clear text
* @return String
*/
public String loginUser(String username, String password) throws ApiException {
Object postBody = null;
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json")
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
// create path and map variables
String path = "/user/login".replaceAll("\\{format\\}", "json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if (username != null) {
queryParams.put("username", apiClient.parameterToString(username));
}
if (password != null) {
queryParams.put("password", apiClient.parameterToString(password));
}
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return (String) apiClient.deserialize(response, "", String.class);
} else {
return null;
}
} catch (ApiException ex) {
throw ex;
}
}
try {
String[] authNames = new String[] { };
String response = apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
throw ex;
/**
* Logs out current logged in user session
*
* @return void
*/
public void logoutUser() throws ApiException {
Object postBody = null;
// create path and map variables
String path = "/user/logout".replaceAll("\\{format\\}", "json");
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return;
} else {
return;
}
} catch (ApiException ex) {
throw ex;
}
}
}
/**
* 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 ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName");
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}", "json")
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return (User) apiClient.deserialize(response, "", User.class);
} else {
return null;
}
} catch (ApiException 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
* @return void
*/
public void updateUser(String username, User body) throws ApiException {
Object postBody = body;
// verify the required parameter 'username' is set
if (username == null) {
throw 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" + "\\}", apiClient.escapeString(username.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "PUT", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return;
} else {
return;
}
} catch (ApiException 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) throws ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser");
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}", "json")
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
final String[] accepts = {
"application/json", "application/xml"
};
final String accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
if (contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if (hasFields) {
postBody = mp;
}
} else {
}
try {
String[] authNames = new String[]{};
String response = apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if (response != null) {
return;
} else {
return;
}
} catch (ApiException ex) {
throw ex;
}
}
}

View File

@@ -3,53 +3,53 @@ package io.swagger.client.auth;
import java.util.Map;
public class ApiKeyAuth implements Authentication {
private final String location;
private final String paramName;
private final String location;
private final String paramName;
private String apiKey;
private String apiKeyPrefix;
private String apiKey;
private String apiKeyPrefix;
public ApiKeyAuth(String location, String paramName) {
this.location = location;
this.paramName = paramName;
}
public String getLocation() {
return location;
}
public String getParamName() {
return paramName;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getApiKeyPrefix() {
return apiKeyPrefix;
}
public void setApiKeyPrefix(String apiKeyPrefix) {
this.apiKeyPrefix = apiKeyPrefix;
}
@Override
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;
} else {
value = apiKey;
public ApiKeyAuth(String location, String paramName) {
this.location = location;
this.paramName = paramName;
}
if (location == "query") {
queryParams.put(paramName, value);
} else if (location == "header") {
headerParams.put(paramName, value);
public String getLocation() {
return location;
}
public String getParamName() {
return paramName;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getApiKeyPrefix() {
return apiKeyPrefix;
}
public void setApiKeyPrefix(String apiKeyPrefix) {
this.apiKeyPrefix = apiKeyPrefix;
}
@Override
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;
} else {
value = apiKey;
}
if (location == "query") {
queryParams.put(paramName, value);
} else if (location == "header") {
headerParams.put(paramName, value);
}
}
}
}

View File

@@ -3,6 +3,8 @@ package io.swagger.client.auth;
import java.util.Map;
public interface Authentication {
/** Apply authentication settings to header and query params. */
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
/**
* Apply authentication settings to header and query params.
*/
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
}

View File

@@ -1,37 +1,36 @@
package io.swagger.client.auth;
import javax.xml.bind.DatatypeConverter;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
public class HttpBasicAuth implements Authentication {
private String username;
private String password;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
}

View File

@@ -3,8 +3,8 @@ package io.swagger.client.auth;
import java.util.Map;
public class OAuth implements Authentication {
@Override
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
// TODO: support oauth
}
@Override
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
// TODO: support oauth
}
}

View File

@@ -1,50 +1,50 @@
package io.swagger.client.model;
import io.swagger.annotations.*;
import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
public class Category {
private Long id = null;
private String name = null;
public class Category {
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private Long id = null;
private String name = null;
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Category {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" name: ").append(name).append("\n");
sb.append("}\n");
return sb.toString();
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Category {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" name: ").append(name).append("\n");
sb.append("}\n");
return sb.toString();
}
}

View File

@@ -1,111 +1,112 @@
package io.swagger.client.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
import io.swagger.annotations.*;
import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
public class Order {
private Long id = null;
private Long petId = null;
private Integer quantity = null;
private Date shipDate = null;
public enum StatusEnum {
placed, approved, delivered,
};
private StatusEnum status = null;
private Boolean complete = null;
public class Order {
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private Long id = null;
private Long petId = null;
private Integer quantity = null;
private Date shipDate = null;
private StatusEnum status = null;
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("petId")
public Long getPetId() {
return petId;
}
public void setPetId(Long petId) {
this.petId = petId;
}
;
private Boolean complete = null;
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("quantity")
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("shipDate")
public Date getShipDate() {
return shipDate;
}
public void setShipDate(Date shipDate) {
this.shipDate = shipDate;
}
public void setId(Long id) {
this.id = id;
}
/**
* Order Status
**/
@ApiModelProperty(value = "Order Status")
@JsonProperty("status")
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("petId")
public Long getPetId() {
return petId;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("complete")
public Boolean getComplete() {
return complete;
}
public void setComplete(Boolean complete) {
this.complete = complete;
}
public void setPetId(Long petId) {
this.petId = petId;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("quantity")
public Integer getQuantity() {
return quantity;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Order {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" petId: ").append(petId).append("\n");
sb.append(" quantity: ").append(quantity).append("\n");
sb.append(" shipDate: ").append(shipDate).append("\n");
sb.append(" status: ").append(status).append("\n");
sb.append(" complete: ").append(complete).append("\n");
sb.append("}\n");
return sb.toString();
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("shipDate")
public Date getShipDate() {
return shipDate;
}
public void setShipDate(Date shipDate) {
this.shipDate = shipDate;
}
/**
* Order Status
**/
@ApiModelProperty(value = "Order Status")
@JsonProperty("status")
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("complete")
public Boolean getComplete() {
return complete;
}
public void setComplete(Boolean complete) {
this.complete = complete;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Order {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" petId: ").append(petId).append("\n");
sb.append(" quantity: ").append(quantity).append("\n");
sb.append(" shipDate: ").append(shipDate).append("\n");
sb.append(" status: ").append(status).append("\n");
sb.append(" complete: ").append(complete).append("\n");
sb.append("}\n");
return sb.toString();
}
public enum StatusEnum {
placed, approved, delivered,
}
}

View File

@@ -1,113 +1,115 @@
package io.swagger.client.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import io.swagger.annotations.*;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
@ApiModel(description = "")
public class Pet {
private Long id = null;
private Category category = null;
private String name = null;
private List<String> photoUrls = new ArrayList<String>() ;
private List<Tag> tags = new ArrayList<Tag>() ;
public enum StatusEnum {
available, pending, sold,
};
private StatusEnum status = null;
public class Pet {
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private Long id = null;
private Category category = null;
private String name = null;
private List<String> photoUrls = new ArrayList<String>();
private List<Tag> tags = new ArrayList<Tag>();
private StatusEnum status = null;
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("category")
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
;
/**
**/
@ApiModelProperty(required = true, value = "")
@JsonProperty("name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
/**
**/
@ApiModelProperty(required = true, value = "")
@JsonProperty("photoUrls")
public List<String> getPhotoUrls() {
return photoUrls;
}
public void setPhotoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("tags")
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("category")
public Category getCategory() {
return category;
}
/**
* pet status in the store
**/
@ApiModelProperty(value = "pet status in the store")
@JsonProperty("status")
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
public void setCategory(Category category) {
this.category = category;
}
/**
**/
@ApiModelProperty(required = true, value = "")
@JsonProperty("name")
public String getName() {
return name;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Pet {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" category: ").append(category).append("\n");
sb.append(" name: ").append(name).append("\n");
sb.append(" photoUrls: ").append(photoUrls).append("\n");
sb.append(" tags: ").append(tags).append("\n");
sb.append(" status: ").append(status).append("\n");
sb.append("}\n");
return sb.toString();
}
public void setName(String name) {
this.name = name;
}
/**
**/
@ApiModelProperty(required = true, value = "")
@JsonProperty("photoUrls")
public List<String> getPhotoUrls() {
return photoUrls;
}
public void setPhotoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("tags")
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
/**
* pet status in the store
**/
@ApiModelProperty(value = "pet status in the store")
@JsonProperty("status")
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Pet {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" category: ").append(category).append("\n");
sb.append(" name: ").append(name).append("\n");
sb.append(" photoUrls: ").append(photoUrls).append("\n");
sb.append(" tags: ").append(tags).append("\n");
sb.append(" status: ").append(status).append("\n");
sb.append("}\n");
return sb.toString();
}
public enum StatusEnum {
available, pending, sold,
}
}

View File

@@ -1,50 +1,50 @@
package io.swagger.client.model;
import io.swagger.annotations.*;
import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
public class Tag {
private Long id = null;
private String name = null;
public class Tag {
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private Long id = null;
private String name = null;
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Tag {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" name: ").append(name).append("\n");
sb.append("}\n");
return sb.toString();
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Tag {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" name: ").append(name).append("\n");
sb.append("}\n");
return sb.toString();
}
}

View File

@@ -1,135 +1,141 @@
package io.swagger.client.model;
import io.swagger.annotations.*;
import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
public class User {
private Long id = null;
private String username = null;
private String firstName = null;
private String lastName = null;
private String email = null;
private String password = null;
private String phone = null;
private Integer userStatus = null;
public class User {
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private Long id = null;
private String username = null;
private String firstName = null;
private String lastName = null;
private String email = null;
private String password = null;
private String phone = null;
private Integer userStatus = null;
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("username")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("firstName")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public Long getId() {
return id;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("lastName")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("password")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("username")
public String getUsername() {
return username;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("phone")
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setUsername(String username) {
this.username = username;
}
/**
* User Status
**/
@ApiModelProperty(value = "User Status")
@JsonProperty("userStatus")
public Integer getUserStatus() {
return userStatus;
}
public void setUserStatus(Integer userStatus) {
this.userStatus = userStatus;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("firstName")
public String getFirstName() {
return firstName;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class User {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" username: ").append(username).append("\n");
sb.append(" firstName: ").append(firstName).append("\n");
sb.append(" lastName: ").append(lastName).append("\n");
sb.append(" email: ").append(email).append("\n");
sb.append(" password: ").append(password).append("\n");
sb.append(" phone: ").append(phone).append("\n");
sb.append(" userStatus: ").append(userStatus).append("\n");
sb.append("}\n");
return sb.toString();
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("lastName")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("password")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("phone")
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
/**
* User Status
**/
@ApiModelProperty(value = "User Status")
@JsonProperty("userStatus")
public Integer getUserStatus() {
return userStatus;
}
public void setUserStatus(Integer userStatus) {
this.userStatus = userStatus;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class User {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" username: ").append(username).append("\n");
sb.append(" firstName: ").append(firstName).append("\n");
sb.append(" lastName: ").append(lastName).append("\n");
sb.append(" email: ").append(email).append("\n");
sb.append(" password: ").append(password).append("\n");
sb.append(" phone: ").append(phone).append("\n");
sb.append(" userStatus: ").append(userStatus).append("\n");
sb.append("}\n");
return sb.toString();
}
}

View File

@@ -5,107 +5,106 @@ import io.swagger.client.auth.*;
import java.util.Map;
import static org.junit.Assert.*;
import org.junit.*;
public class ApiClientTest {
ApiClient apiClient = null;
ApiClient apiClient = null;
@Before
public void setup() {
apiClient = new ApiClient();
}
@Test
public void testSelectHeaderAccept() {
String[] accepts = { "APPLICATION/JSON", "APPLICATION/XML" };
assertEquals("application/json", apiClient.selectHeaderAccept(accepts));
accepts = new String[] { "application/json", "application/xml" };
assertEquals("application/json", apiClient.selectHeaderAccept(accepts));
accepts = new String[] { "application/xml", "application/json" };
assertEquals("application/json", apiClient.selectHeaderAccept(accepts));
accepts = new String[] { "text/plain", "application/xml" };
assertEquals("text/plain,application/xml", apiClient.selectHeaderAccept(accepts));
accepts = new String[] { };
assertNull(apiClient.selectHeaderAccept(accepts));
}
@Test
public void testSelectHeaderContentType() {
String[] contentTypes = { "APPLICATION/JSON", "APPLICATION/XML" };
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[] { "application/json", "application/xml" };
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[] { "application/xml", "application/json" };
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[] { "text/plain", "application/xml" };
assertEquals("text/plain", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[] { };
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
}
@Test
public void testGetAuthentications() {
Map<String, Authentication> auths = apiClient.getAuthentications();
Authentication auth = auths.get("api_key");
assertNotNull(auth);
assertTrue(auth instanceof ApiKeyAuth);
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) auth;
assertEquals("header", apiKeyAuth.getLocation());
assertEquals("api_key", apiKeyAuth.getParamName());
auth = auths.get("petstore_auth");
assertTrue(auth instanceof OAuth);
assertSame(auth, apiClient.getAuthentication("petstore_auth"));
assertNull(auths.get("unknown"));
try {
auths.put("my_auth", new HttpBasicAuth());
fail("the authentications returned should not be modifiable");
} catch (UnsupportedOperationException e) {
@Before
public void setup() {
apiClient = new ApiClient();
}
}
@Test
public void testSetUsername() {
try {
apiClient.setUsername("my-username");
fail("there should be no HTTP basic authentications");
} catch (RuntimeException e) {
@Test
public void testSelectHeaderAccept() {
String[] accepts = {"APPLICATION/JSON", "APPLICATION/XML"};
assertEquals("application/json", apiClient.selectHeaderAccept(accepts));
accepts = new String[]{"application/json", "application/xml"};
assertEquals("application/json", apiClient.selectHeaderAccept(accepts));
accepts = new String[]{"application/xml", "application/json"};
assertEquals("application/json", apiClient.selectHeaderAccept(accepts));
accepts = new String[]{"text/plain", "application/xml"};
assertEquals("text/plain,application/xml", apiClient.selectHeaderAccept(accepts));
accepts = new String[]{};
assertNull(apiClient.selectHeaderAccept(accepts));
}
}
@Test
public void testSetPassword() {
try {
apiClient.setPassword("my-password");
fail("there should be no HTTP basic authentications");
} catch (RuntimeException e) {
@Test
public void testSelectHeaderContentType() {
String[] contentTypes = {"APPLICATION/JSON", "APPLICATION/XML"};
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[]{"application/json", "application/xml"};
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[]{"application/xml", "application/json"};
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[]{"text/plain", "application/xml"};
assertEquals("text/plain", apiClient.selectHeaderContentType(contentTypes));
contentTypes = new String[]{};
assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes));
}
}
@Test
public void testSetApiKeyAndPrefix() {
ApiKeyAuth auth = (ApiKeyAuth) apiClient.getAuthentications().get("api_key");
auth.setApiKey(null);
auth.setApiKeyPrefix(null);
@Test
public void testGetAuthentications() {
Map<String, Authentication> auths = apiClient.getAuthentications();
apiClient.setApiKey("my-api-key");
apiClient.setApiKeyPrefix("Token");
assertEquals("my-api-key", auth.getApiKey());
assertEquals("Token", auth.getApiKeyPrefix());
Authentication auth = auths.get("api_key");
assertNotNull(auth);
assertTrue(auth instanceof ApiKeyAuth);
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) auth;
assertEquals("header", apiKeyAuth.getLocation());
assertEquals("api_key", apiKeyAuth.getParamName());
// reset values
auth.setApiKey(null);
auth.setApiKeyPrefix(null);
}
auth = auths.get("petstore_auth");
assertTrue(auth instanceof OAuth);
assertSame(auth, apiClient.getAuthentication("petstore_auth"));
assertNull(auths.get("unknown"));
try {
auths.put("my_auth", new HttpBasicAuth());
fail("the authentications returned should not be modifiable");
} catch (UnsupportedOperationException e) {
}
}
@Test
public void testSetUsername() {
try {
apiClient.setUsername("my-username");
fail("there should be no HTTP basic authentications");
} catch (RuntimeException e) {
}
}
@Test
public void testSetPassword() {
try {
apiClient.setPassword("my-password");
fail("there should be no HTTP basic authentications");
} catch (RuntimeException e) {
}
}
@Test
public void testSetApiKeyAndPrefix() {
ApiKeyAuth auth = (ApiKeyAuth) apiClient.getAuthentications().get("api_key");
auth.setApiKey(null);
auth.setApiKeyPrefix(null);
apiClient.setApiKey("my-api-key");
apiClient.setApiKeyPrefix("Token");
assertEquals("my-api-key", auth.getApiKey());
assertEquals("Token", auth.getApiKeyPrefix());
// reset values
auth.setApiKey(null);
auth.setApiKeyPrefix(null);
}
}

View File

@@ -1,14 +1,13 @@
package io.swagger.client;
import static org.junit.Assert.*;
import org.junit.*;
public class ConfigurationTest {
@Test
public void testDefaultApiClient() {
ApiClient apiClient = Configuration.getDefaultApiClient();
assertNotNull(apiClient);
assertEquals("http://petstore.swagger.io/v2", apiClient.getBasePath());
assertFalse(apiClient.isDebugging());
}
@Test
public void testDefaultApiClient() {
ApiClient apiClient = Configuration.getDefaultApiClient();
assertNotNull(apiClient);
assertEquals("http://petstore.swagger.io/v2", apiClient.getBasePath());
assertFalse(apiClient.isDebugging());
}
}

View File

@@ -1,32 +1,31 @@
package io.swagger.client;
import static org.junit.Assert.*;
import org.junit.*;
public class StringUtilTest {
@Test
public void testContainsIgnoreCase() {
assertTrue(StringUtil.containsIgnoreCase(new String[]{ "abc" }, "abc"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ "abc" }, "ABC"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ "ABC" }, "abc"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ null, "abc" }, "ABC"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ null, "abc" }, null));
@Test
public void testContainsIgnoreCase() {
assertTrue(StringUtil.containsIgnoreCase(new String[]{"abc"}, "abc"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{"abc"}, "ABC"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{"ABC"}, "abc"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{null, "abc"}, "ABC"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{null, "abc"}, null));
assertFalse(StringUtil.containsIgnoreCase(new String[]{ "abc" }, "def"));
assertFalse(StringUtil.containsIgnoreCase(new String[]{ }, "ABC"));
assertFalse(StringUtil.containsIgnoreCase(new String[]{ }, null));
}
assertFalse(StringUtil.containsIgnoreCase(new String[]{"abc"}, "def"));
assertFalse(StringUtil.containsIgnoreCase(new String[]{}, "ABC"));
assertFalse(StringUtil.containsIgnoreCase(new String[]{}, null));
}
@Test
public void testJoin() {
String[] array = { "aa", "bb", "cc" };
assertEquals("aa,bb,cc", StringUtil.join(array, ","));
assertEquals("aa, bb, cc", StringUtil.join(array, ", "));
assertEquals("aabbcc", StringUtil.join(array, ""));
assertEquals("aa bb cc", StringUtil.join(array, " "));
assertEquals("aa\nbb\ncc", StringUtil.join(array, "\n"));
@Test
public void testJoin() {
String[] array = {"aa", "bb", "cc"};
assertEquals("aa,bb,cc", StringUtil.join(array, ","));
assertEquals("aa, bb, cc", StringUtil.join(array, ", "));
assertEquals("aabbcc", StringUtil.join(array, ""));
assertEquals("aa bb cc", StringUtil.join(array, " "));
assertEquals("aa\nbb\ncc", StringUtil.join(array, "\n"));
assertEquals("", StringUtil.join(new String[]{ }, ","));
assertEquals("abc", StringUtil.join(new String[]{ "abc" }, ","));
}
assertEquals("", StringUtil.join(new String[]{}, ","));
assertEquals("abc", StringUtil.join(new String[]{"abc"}, ","));
}
}

View File

@@ -1,40 +1,39 @@
package io.swagger.client.auth;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
import org.junit.*;
public class ApiKeyAuthTest {
@Test
public void testApplyToParamsInQuery() {
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
@Test
public void testApplyToParamsInQuery() {
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
ApiKeyAuth auth = new ApiKeyAuth("query", "api_key");
auth.setApiKey("my-api-key");
auth.applyToParams(queryParams, headerParams);
ApiKeyAuth auth = new ApiKeyAuth("query", "api_key");
auth.setApiKey("my-api-key");
auth.applyToParams(queryParams, headerParams);
assertEquals(1, queryParams.size());
assertEquals("my-api-key", queryParams.get("api_key"));
// no changes to header parameters
assertEquals(0, headerParams.size());
}
assertEquals(1, queryParams.size());
assertEquals("my-api-key", queryParams.get("api_key"));
// no changes to header parameters
assertEquals(0, headerParams.size());
}
@Test
public void testApplyToParamsInHeaderWithPrefix() {
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
@Test
public void testApplyToParamsInHeaderWithPrefix() {
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN");
auth.setApiKey("my-api-token");
auth.setApiKeyPrefix("Token");
auth.applyToParams(queryParams, headerParams);
ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN");
auth.setApiKey("my-api-token");
auth.setApiKeyPrefix("Token");
auth.applyToParams(queryParams, headerParams);
// no changes to query parameters
assertEquals(0, queryParams.size());
assertEquals(1, headerParams.size());
assertEquals("Token my-api-token", headerParams.get("X-API-TOKEN"));
}
// no changes to query parameters
assertEquals(0, queryParams.size());
assertEquals(1, headerParams.size());
assertEquals("Token my-api-token", headerParams.get("X-API-TOKEN"));
}
}

View File

@@ -1,48 +1,47 @@
package io.swagger.client.auth;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
import org.junit.*;
public class HttpBasicAuthTest {
HttpBasicAuth auth = null;
HttpBasicAuth auth = null;
@Before
public void setup() {
auth = new HttpBasicAuth();
}
@Before
public void setup() {
auth = new HttpBasicAuth();
}
@Test
public void testApplyToParams() {
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
@Test
public void testApplyToParams() {
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
auth.setUsername("my-username");
auth.setPassword("my-password");
auth.applyToParams(queryParams, headerParams);
auth.setUsername("my-username");
auth.setPassword("my-password");
auth.applyToParams(queryParams, headerParams);
// no changes to query parameters
assertEquals(0, queryParams.size());
assertEquals(1, headerParams.size());
// the string below is base64-encoded result of "my-username:my-password" with the "Basic " prefix
String expected = "Basic bXktdXNlcm5hbWU6bXktcGFzc3dvcmQ=";
assertEquals(expected, headerParams.get("Authorization"));
// no changes to query parameters
assertEquals(0, queryParams.size());
assertEquals(1, headerParams.size());
// the string below is base64-encoded result of "my-username:my-password" with the "Basic " prefix
String expected = "Basic bXktdXNlcm5hbWU6bXktcGFzc3dvcmQ=";
assertEquals(expected, headerParams.get("Authorization"));
// null username should be treated as empty string
auth.setUsername(null);
auth.applyToParams(queryParams, headerParams);
// the string below is base64-encoded result of ":my-password" with the "Basic " prefix
expected = "Basic Om15LXBhc3N3b3Jk";
assertEquals(expected, headerParams.get("Authorization"));
// null username should be treated as empty string
auth.setUsername(null);
auth.applyToParams(queryParams, headerParams);
// the string below is base64-encoded result of ":my-password" with the "Basic " prefix
expected = "Basic Om15LXBhc3N3b3Jk";
assertEquals(expected, headerParams.get("Authorization"));
// null password should be treated as empty string
auth.setUsername("my-username");
auth.setPassword(null);
auth.applyToParams(queryParams, headerParams);
// the string below is base64-encoded result of "my-username:" with the "Basic " prefix
expected = "Basic bXktdXNlcm5hbWU6";
assertEquals(expected, headerParams.get("Authorization"));
}
// null password should be treated as empty string
auth.setUsername("my-username");
auth.setPassword(null);
auth.applyToParams(queryParams, headerParams);
// the string below is base64-encoded result of "my-username:" with the "Basic " prefix
expected = "Basic bXktdXNlcm5hbWU6";
assertEquals(expected, headerParams.get("Authorization"));
}
}

View File

@@ -1,188 +1,188 @@
package io.swagger.petstore.test;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
import io.swagger.client.auth.*;
import java.util.*;
import java.io.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.*;
public class PetApiTest {
PetApi api = null;
PetApi api = null;
@Before
public void setup() {
api = new PetApi();
// setup authentication
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key");
apiKeyAuth.setApiKey("special-key");
}
@Test
public void testApiClient() {
// the default api client is used
assertEquals(Configuration.getDefaultApiClient(), api.getApiClient());
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());
ApiClient oldClient = api.getApiClient();
ApiClient newClient = new ApiClient();
newClient.setBasePath("http://example.com");
newClient.setDebugging(true);
// set api client via constructor
api = new PetApi(newClient);
assertNotNull(api.getApiClient());
assertEquals("http://example.com", api.getApiClient().getBasePath());
assertTrue(api.getApiClient().isDebugging());
// set api client via setter method
api.setApiClient(oldClient);
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());
}
@Test
public void testCreateAndGetPet() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
}
@Test
public void testUpdatePet() throws Exception {
Pet pet = createRandomPet();
pet.setName("programmer");
api.updatePet(pet);
Pet fetched = api.getPetById(pet.getId());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
}
@Test
public void testFindPetsByStatus() throws Exception {
Pet pet = createRandomPet();
pet.setName("programmer");
pet.setStatus(Pet.StatusEnum.available);
api.updatePet(pet);
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
assertNotNull(pets);
boolean found = false;
for(Pet fetched : pets) {
if(fetched.getId().equals(pet.getId())) {
found = true;
break;
}
@Before
public void setup() {
api = new PetApi();
// setup authentication
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key");
apiKeyAuth.setApiKey("special-key");
}
assertTrue(found);
}
@Test
public void testApiClient() {
// the default api client is used
assertEquals(Configuration.getDefaultApiClient(), api.getApiClient());
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());
@Test
public void testFindPetsByTags() throws Exception {
Pet pet = createRandomPet();
pet.setName("monster");
pet.setStatus(Pet.StatusEnum.available);
ApiClient oldClient = api.getApiClient();
List<Tag> tags = new ArrayList<Tag>();
Tag tag1 = new Tag();
tag1.setName("friendly");
tags.add(tag1);
pet.setTags(tags);
ApiClient newClient = new ApiClient();
newClient.setBasePath("http://example.com");
newClient.setDebugging(true);
api.updatePet(pet);
// set api client via constructor
api = new PetApi(newClient);
assertNotNull(api.getApiClient());
assertEquals("http://example.com", api.getApiClient().getBasePath());
assertTrue(api.getApiClient().isDebugging());
List<Pet> pets = api.findPetsByTags(Arrays.asList(new String[]{"friendly"}));
assertNotNull(pets);
boolean found = false;
for(Pet fetched : pets) {
if(fetched.getId().equals(pet.getId())) {
found = true;
break;
}
// set api client via setter method
api.setApiClient(oldClient);
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());
}
assertTrue(found);
}
@Test
public void testUpdatePetWithForm() throws Exception {
Pet pet = createRandomPet();
pet.setName("frank");
api.addPet(pet);
@Test
public void testCreateAndGetPet() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.updatePetWithForm(String.valueOf(fetched.getId()), "furt", null);
Pet updated = api.getPetById(fetched.getId());
assertEquals(updated.getName(), "furt");
}
@Test
public void testDeletePet() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.deletePet(null, fetched.getId());
try {
fetched = api.getPetById(fetched.getId());
fail("expected an error");
Pet fetched = api.getPetById(pet.getId());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
}
catch (ApiException e) {
assertEquals(404, e.getCode());
@Test
public void testUpdatePet() throws Exception {
Pet pet = createRandomPet();
pet.setName("programmer");
api.updatePet(pet);
Pet fetched = api.getPetById(pet.getId());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
}
}
@Test
public void testUploadFile() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
@Test
public void testFindPetsByStatus() throws Exception {
Pet pet = createRandomPet();
pet.setName("programmer");
pet.setStatus(Pet.StatusEnum.available);
File file = new File("hello.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write("Hello world!");
writer.close();
api.updatePet(pet);
api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath()));
}
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
assertNotNull(pets);
private Pet createRandomPet() {
Pet pet = new Pet();
pet.setId(System.currentTimeMillis());
pet.setName("gorilla");
boolean found = false;
for (Pet fetched : pets) {
if (fetched.getId().equals(pet.getId())) {
found = true;
break;
}
}
Category category = new Category();
category.setName("really-happy");
assertTrue(found);
}
pet.setCategory(category);
pet.setStatus(Pet.StatusEnum.available);
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"});
pet.setPhotoUrls(photos);
@Test
public void testFindPetsByTags() throws Exception {
Pet pet = createRandomPet();
pet.setName("monster");
pet.setStatus(Pet.StatusEnum.available);
return pet;
}
List<Tag> tags = new ArrayList<Tag>();
Tag tag1 = new Tag();
tag1.setName("friendly");
tags.add(tag1);
pet.setTags(tags);
api.updatePet(pet);
List<Pet> pets = api.findPetsByTags(Arrays.asList(new String[]{"friendly"}));
assertNotNull(pets);
boolean found = false;
for (Pet fetched : pets) {
if (fetched.getId().equals(pet.getId())) {
found = true;
break;
}
}
assertTrue(found);
}
@Test
public void testUpdatePetWithForm() throws Exception {
Pet pet = createRandomPet();
pet.setName("frank");
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.updatePetWithForm(String.valueOf(fetched.getId()), "furt", null);
Pet updated = api.getPetById(fetched.getId());
assertEquals(updated.getName(), "furt");
}
@Test
public void testDeletePet() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.deletePet(null, fetched.getId());
try {
fetched = api.getPetById(fetched.getId());
fail("expected an error");
} catch (ApiException e) {
assertEquals(404, e.getCode());
}
}
@Test
public void testUploadFile() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
File file = new File("hello.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write("Hello world!");
writer.close();
api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath()));
}
private Pet createRandomPet() {
Pet pet = new Pet();
pet.setId(System.currentTimeMillis());
pet.setName("gorilla");
Category category = new Category();
category.setName("really-happy");
pet.setCategory(category);
pet.setStatus(Pet.StatusEnum.available);
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"});
pet.setPhotoUrls(photos);
return pet;
}
}

View File

@@ -1,73 +1,67 @@
package io.swagger.petstore.test;
import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
import io.swagger.client.auth.*;
import java.util.*;
import java.io.*;
import java.util.Map;
import static org.junit.Assert.*;
import org.junit.*;
public class StoreApiTest {
StoreApi api = null;
StoreApi api = null;
@Before
public void setup() {
api = new StoreApi();
// setup authentication
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key");
apiKeyAuth.setApiKey("special-key");
}
@Test
public void testGetInventory() throws Exception {
Map<String, Integer> inventory = api.getInventory();
assertTrue(inventory.keySet().size() > 0);
}
@Test
public void testPlaceOrder() throws Exception {
Order order = createOrder();
api.placeOrder(order);
Order fetched = api.getOrderById(String.valueOf(order.getId()));
assertEquals(order.getId(), fetched.getId());
assertEquals(order.getPetId(), fetched.getPetId());
assertEquals(order.getQuantity(), fetched.getQuantity());
}
@Test
public void testDeleteOrder() throws Exception {
Order order = createOrder();
api.placeOrder(order);
Order fetched = api.getOrderById(String.valueOf(order.getId()));
assertEquals(fetched.getId(), order.getId());
api.deleteOrder(String.valueOf(order.getId()));
try {
api.getOrderById(String.valueOf(order.getId()));
// fail("expected an error");
@Before
public void setup() {
api = new StoreApi();
// setup authentication
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key");
apiKeyAuth.setApiKey("special-key");
}
catch (ApiException e) {
// ok
@Test
public void testGetInventory() throws Exception {
Map<String, Integer> inventory = api.getInventory();
assertTrue(inventory.keySet().size() > 0);
}
}
private Order createOrder() {
Order order = new Order();
order.setId(new Long(System.currentTimeMillis()));
order.setPetId(new Long(200));
order.setQuantity(new Integer(13));
order.setShipDate(new java.util.Date());
order.setStatus(Order.StatusEnum.placed);
order.setComplete(true);
@Test
public void testPlaceOrder() throws Exception {
Order order = createOrder();
api.placeOrder(order);
return order;
}
Order fetched = api.getOrderById(String.valueOf(order.getId()));
assertEquals(order.getId(), fetched.getId());
assertEquals(order.getPetId(), fetched.getPetId());
assertEquals(order.getQuantity(), fetched.getQuantity());
}
@Test
public void testDeleteOrder() throws Exception {
Order order = createOrder();
api.placeOrder(order);
Order fetched = api.getOrderById(String.valueOf(order.getId()));
assertEquals(fetched.getId(), order.getId());
api.deleteOrder(String.valueOf(order.getId()));
try {
api.getOrderById(String.valueOf(order.getId()));
// fail("expected an error");
} catch (ApiException e) {
// ok
}
}
private Order createOrder() {
Order order = new Order();
order.setId(new Long(System.currentTimeMillis()));
order.setPetId(new Long(200));
order.setQuantity(new Integer(13));
order.setShipDate(new java.util.Date());
order.setStatus(Order.StatusEnum.placed);
order.setComplete(true);
return order;
}
}

View File

@@ -1,89 +1,83 @@
package io.swagger.petstore.test;
import io.swagger.client.ApiException;
import io.swagger.client.Configuration;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
import io.swagger.client.auth.*;
import java.util.*;
import java.io.*;
import java.util.Arrays;
import static org.junit.Assert.*;
import org.junit.*;
public class UserApiTest {
UserApi api = null;
UserApi api = null;
@Before
public void setup() {
api = new UserApi();
// setup authentication
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key");
apiKeyAuth.setApiKey("special-key");
}
@Before
public void setup() {
api = new UserApi();
// setup authentication
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key");
apiKeyAuth.setApiKey("special-key");
}
@Test
public void testCreateUser() throws Exception {
User user = createUser();
@Test
public void testCreateUser() throws Exception {
User user = createUser();
api.createUser(user);
api.createUser(user);
User fetched = api.getUserByName(user.getUsername());
assertEquals(user.getId(), fetched.getId());
}
User fetched = api.getUserByName(user.getUsername());
assertEquals(user.getId(), fetched.getId());
}
@Test
public void testCreateUsersWithArray() throws Exception {
User user1 = createUser();
user1.setUsername("abc123");
User user2 = createUser();
user2.setUsername("123abc");
@Test
public void testCreateUsersWithArray() throws Exception {
User user1 = createUser();
user1.setUsername("abc123");
User user2 = createUser();
user2.setUsername("123abc");
api.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2}));
api.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2}));
User fetched = api.getUserByName(user1.getUsername());
assertEquals(user1.getId(), fetched.getId());
}
User fetched = api.getUserByName(user1.getUsername());
assertEquals(user1.getId(), fetched.getId());
}
@Test
public void testCreateUsersWithList() throws Exception {
User user1 = createUser();
user1.setUsername("abc123");
User user2 = createUser();
user2.setUsername("123abc");
@Test
public void testCreateUsersWithList() throws Exception {
User user1 = createUser();
user1.setUsername("abc123");
User user2 = createUser();
user2.setUsername("123abc");
api.createUsersWithListInput(Arrays.asList(new User[]{user1, user2}));
api.createUsersWithListInput(Arrays.asList(new User[]{user1, user2}));
User fetched = api.getUserByName(user1.getUsername());
assertEquals(user1.getId(), fetched.getId());
}
User fetched = api.getUserByName(user1.getUsername());
assertEquals(user1.getId(), fetched.getId());
}
@Test
public void testLoginUser() throws Exception {
User user = createUser();
api.createUser(user);
@Test
public void testLoginUser() throws Exception {
User user = createUser();
api.createUser(user);
String token = api.loginUser(user.getUsername(), user.getPassword());
assertTrue(token.startsWith("logged in user session:"));
}
String token = api.loginUser(user.getUsername(), user.getPassword());
assertTrue(token.startsWith("logged in user session:"));
}
@Test
public void logoutUser() throws Exception {
api.logoutUser();
}
@Test
public void logoutUser() throws Exception {
api.logoutUser();
}
private User createUser() {
User user = new User();
user.setId(System.currentTimeMillis());
user.setUsername("fred");
user.setFirstName("Fred");
user.setLastName("Meyer");
user.setEmail("fred@fredmeyer.com");
user.setPassword("xxXXxx");
user.setPhone("408-867-5309");
user.setUserStatus(123);
private User createUser() {
User user = new User();
user.setId(System.currentTimeMillis());
user.setUsername("fred");
user.setFirstName("Fred");
user.setLastName("Meyer");
user.setEmail("fred@fredmeyer.com");
user.setPassword("xxXXxx");
user.setPhone("408-867-5309");
user.setUserStatus(123);
return user;
}
return user;
}
}