added support in feign for binary uploads

This commit is contained in:
David Kiss 2015-12-07 22:34:38 -05:00
parent 538ccb3f12
commit 1723078508
18 changed files with 256 additions and 200 deletions

View File

@ -4,21 +4,31 @@ import java.io.*;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import feign.RequestTemplate;
{{>generatedAnnotation}}
public class FormAwareEncoder implements Encoder {
public static final String UTF_8 = "utf-8";
private static final String LINE_FEED = "\r\n";
private static final String TWO_DASH = "--";
private static final String BOUNDARY = "----------------314159265358979323846";
private byte[] lineFeedBytes;
private byte[] boundaryBytes;
private byte[] twoDashBytes;
private byte[] atBytes;
private byte[] eqBytes;
private final Encoder delegate;
private DateFormat dateFormat;
private final DateFormat dateFormat;
public FormAwareEncoder(Encoder delegate) {
this.delegate = delegate;
@ -28,93 +38,121 @@ public class FormAwareEncoder implements Encoder {
// Use UTC as the default time zone.
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
this.lineFeedBytes = LINE_FEED.getBytes(UTF_8);
this.boundaryBytes = BOUNDARY.getBytes(UTF_8);
this.twoDashBytes = TWO_DASH.getBytes(UTF_8);
this.atBytes = "&".getBytes(UTF_8);
this.eqBytes = "=".getBytes(UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public void encode(Object object, Type bodyType, RequestTemplate template) {
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
if (object instanceof Map) {
StringBuilder formParamBuilder = new StringBuilder();
Map<String, Object> formParams = (Map<String, Object>) object;
boolean isMultiPart = isMultiPart(formParams);
for (Map.Entry<String, Object> param : formParams.entrySet()) {
String keyStr = param.getKey();
if (param.getValue() instanceof File) {
addFilePart(formParamBuilder, keyStr, (File) param.getValue());
} else {
String valueStr = parameterToString(param.getValue());
if (isMultiPart) {
addMultiPartFormField(formParamBuilder, keyStr, valueStr);
} else {
addEncodedFormField(formParamBuilder, keyStr, valueStr);
}
}
try {
encodeFormParams(template, (Map<String, Object>) object);
} catch (IOException e) {
throw new EncodeException("Failed to create request", e);
}
if (isMultiPart) {
formParamBuilder.append(LINE_FEED);
formParamBuilder.append("--").append(BOUNDARY).append("--").append(LINE_FEED);
}
String contentType = isMultiPart ? "multipart/form-data; boundary=" + BOUNDARY : "application/x-www-form-urlencoded";
template.header("Content-type");
template.header("Content-type", contentType);
template.header("MIME-Version", "1.0");
template.body(formParamBuilder.toString());
} else {
delegate.encode(object, bodyType, template);
}
}
private void encodeFormParams(RequestTemplate template, Map<String, Object> formParams) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
boolean isMultiPart = isMultiPart(formParams);
boolean isFirstField = true;
for (Map.Entry<String, Object> param : formParams.entrySet()) {
String keyStr = param.getKey();
if (param.getValue() instanceof File) {
addFilePart(baos, keyStr, (File) param.getValue());
} else {
String valueStr = parameterToString(param.getValue());
if (isMultiPart) {
addMultiPartFormField(baos, keyStr, valueStr);
} else {
addEncodedFormField(baos, keyStr, valueStr, isFirstField);
isFirstField = false;
}
}
}
if (isMultiPart) {
baos.write(lineFeedBytes);
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(twoDashBytes);
baos.write(lineFeedBytes);
}
String contentType = isMultiPart ? "multipart/form-data; boundary=" + BOUNDARY : "application/x-www-form-urlencoded";
template.header("Content-type");
template.header("Content-type", contentType);
template.header("MIME-Version", "1.0");
template.body(baos.toByteArray(), Charset.forName(UTF_8));
}
/*
* Currently only supports text files
*/
private void addFilePart(StringBuilder formParamBuilder, String fieldName, File uploadFile) {
try {
String fileName = uploadFile.getName();
formParamBuilder.append("--").append(BOUNDARY).append(LINE_FEED);
formParamBuilder.append(
"Content-Disposition: form-data; name=\"" + fieldName
+ "\"; filename=\"" + fileName + "\"")
.append(LINE_FEED);
formParamBuilder.append(
"Content-Type: "
+ URLConnection.guessContentTypeFromName(fileName))
.append(LINE_FEED);
formParamBuilder.append(LINE_FEED);
private void addFilePart(ByteArrayOutputStream baos, String fieldName, File uploadFile) throws IOException {
String fileName = uploadFile.getName();
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(lineFeedBytes);
BufferedReader reader = new BufferedReader(new FileReader(uploadFile));
String line = "";
while ((line = reader.readLine()) != null) {
formParamBuilder.append(line).append(LINE_FEED);
}
String contentDisposition = "Content-Disposition: form-data; name=\"" + fieldName
+ "\"; filename=\"" + fileName + "\"";
baos.write(contentDisposition.getBytes(UTF_8));
baos.write(lineFeedBytes);
String contentType = "Content-Type: " + URLConnection.guessContentTypeFromName(fileName);
baos.write(contentType.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(lineFeedBytes);
formParamBuilder.append(LINE_FEED);
} catch (IOException e) {
e.printStackTrace();
BufferedReader reader = new BufferedReader(new FileReader(uploadFile));
InputStream input = new FileInputStream(uploadFile);
byte[] bytes = new byte[4096];
int len = bytes.length;
while ((len = input.read(bytes)) != -1) {
baos.write(bytes, 0, len);
baos.write(lineFeedBytes);
}
baos.write(lineFeedBytes);
}
private void addEncodedFormField(StringBuilder formParamBuilder, String name, String value) {
if (formParamBuilder.length() > 0) {
formParamBuilder.append("&");
private void addEncodedFormField(ByteArrayOutputStream baos, String name, String value, boolean isFirstField) throws IOException {
if (!isFirstField) {
baos.write(atBytes);
}
try {
formParamBuilder.append(URLEncoder.encode(name, "utf8"))
.append("=")
.append(URLEncoder.encode(value, "utf8"));
} catch (UnsupportedEncodingException e) {
// move on to next
}
String encodedName = URLEncoder.encode(name, UTF_8);
String encodedValue = URLEncoder.encode(value, UTF_8);
baos.write(encodedName.getBytes(UTF_8));
baos.write("=".getBytes(UTF_8));
baos.write(encodedValue.getBytes(UTF_8));
}
private void addMultiPartFormField(StringBuilder formParamBuilder, String name, String value) {
formParamBuilder.append("--").append(BOUNDARY).append(LINE_FEED);
formParamBuilder.append("Content-Disposition: form-data; name=\"" + name + "\"")
.append(LINE_FEED);
formParamBuilder.append("Content-Type: text/plain; charset=utf-8").append(
LINE_FEED);
formParamBuilder.append(LINE_FEED);
formParamBuilder.append(value).append(LINE_FEED);
private void addMultiPartFormField(ByteArrayOutputStream baos, String name, String value) throws IOException {
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(lineFeedBytes);
String contentDisposition = "Content-Disposition: form-data; name=\"" + name + "\"";
String contentType = "Content-Type: text/plain; charset=utf-8";
baos.write(contentDisposition.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(contentType.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(lineFeedBytes);
baos.write(value.getBytes(UTF_8));
baos.write(lineFeedBytes);
}
private boolean isMultiPart(Map<String, Object> formParams) {

View File

@ -1,10 +1,6 @@
package {{package}};
import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.ApiClient;
import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.TypeRef;
{{#imports}}import {{import}};
{{/imports}}
@ -14,7 +10,7 @@ import {{invokerPackage}}.TypeRef;
import feign.*;
{{>generatedAnnotation}}
public interface {{classname}} extends {{invokerPackage}}.ApiClient.Api {
public interface {{classname}} extends ApiClient.Api {
{{#operations}}{{#operation}}
/**
@ -30,7 +26,7 @@ public interface {{classname}} extends {{invokerPackage}}.ApiClient.Api {
"{{paramName}}: {{=<% %>=}}{<%paramName%>}<%={{ }}=%>"{{#hasMore}},
{{/hasMore}}{{/headerParams}}
})
{{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}}({{#allParams}}{{^vendorExtensions.x-isBody}}@Param("{{paramName}}") {{/vendorExtensions.x-isBody}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException;
{{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}}({{#allParams}}{{^vendorExtensions.x-isBody}}@Param("{{paramName}}") {{/vendorExtensions.x-isBody}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/operation}}
{{/operations}}
}

View File

@ -1,4 +1,4 @@
# swagger-petstore-feign
# swagger-java-client
## Requirements
@ -25,7 +25,7 @@ After the client libarary is installed/deployed, you can use it in your Maven pr
```xml
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-petstore-feign</artifactId>
<artifactId>swagger-java-client</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>

View File

@ -2,9 +2,9 @@
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-petstore-feign</artifactId>
<artifactId>swagger-java-client</artifactId>
<packaging>jar</packaging>
<name>swagger-petstore-feign</name>
<name>swagger-java-client</name>
<version>1.0.0</version>
<scm>
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>

View File

@ -1 +1 @@
rootProject.name = "swagger-petstore-feign"
rootProject.name = "swagger-java-client"

View File

@ -8,7 +8,7 @@ import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.slf4j.Slf4jLogger;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class ApiClient {
public interface Api {}

View File

@ -4,21 +4,31 @@ import java.io.*;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import feign.RequestTemplate;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class FormAwareEncoder implements Encoder {
public static final String UTF_8 = "utf-8";
private static final String LINE_FEED = "\r\n";
private static final String TWO_DASH = "--";
private static final String BOUNDARY = "----------------314159265358979323846";
private byte[] lineFeedBytes;
private byte[] boundaryBytes;
private byte[] twoDashBytes;
private byte[] atBytes;
private byte[] eqBytes;
private final Encoder delegate;
private DateFormat dateFormat;
private final DateFormat dateFormat;
public FormAwareEncoder(Encoder delegate) {
this.delegate = delegate;
@ -28,93 +38,121 @@ public class FormAwareEncoder implements Encoder {
// Use UTC as the default time zone.
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
this.lineFeedBytes = LINE_FEED.getBytes(UTF_8);
this.boundaryBytes = BOUNDARY.getBytes(UTF_8);
this.twoDashBytes = TWO_DASH.getBytes(UTF_8);
this.atBytes = "&".getBytes(UTF_8);
this.eqBytes = "=".getBytes(UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public void encode(Object object, Type bodyType, RequestTemplate template) {
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
if (object instanceof Map) {
StringBuilder formParamBuilder = new StringBuilder();
Map<String, Object> formParams = (Map<String, Object>) object;
boolean isMultiPart = isMultiPart(formParams);
for (Map.Entry<String, Object> param : formParams.entrySet()) {
String keyStr = param.getKey();
if (param.getValue() instanceof File) {
addFilePart(formParamBuilder, keyStr, (File) param.getValue());
} else {
String valueStr = parameterToString(param.getValue());
if (isMultiPart) {
addMultiPartFormField(formParamBuilder, keyStr, valueStr);
} else {
addEncodedFormField(formParamBuilder, keyStr, valueStr);
}
}
try {
encodeFormParams(template, (Map<String, Object>) object);
} catch (IOException e) {
throw new EncodeException("Failed to create request", e);
}
if (isMultiPart) {
formParamBuilder.append(LINE_FEED);
formParamBuilder.append("--").append(BOUNDARY).append("--").append(LINE_FEED);
}
String contentType = isMultiPart ? "multipart/form-data; boundary=" + BOUNDARY : "application/x-www-form-urlencoded";
template.header("Content-type");
template.header("Content-type", contentType);
template.header("MIME-Version", "1.0");
template.body(formParamBuilder.toString());
} else {
delegate.encode(object, bodyType, template);
}
}
private void encodeFormParams(RequestTemplate template, Map<String, Object> formParams) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
boolean isMultiPart = isMultiPart(formParams);
boolean isFirstField = true;
for (Map.Entry<String, Object> param : formParams.entrySet()) {
String keyStr = param.getKey();
if (param.getValue() instanceof File) {
addFilePart(baos, keyStr, (File) param.getValue());
} else {
String valueStr = parameterToString(param.getValue());
if (isMultiPart) {
addMultiPartFormField(baos, keyStr, valueStr);
} else {
addEncodedFormField(baos, keyStr, valueStr, isFirstField);
isFirstField = false;
}
}
}
if (isMultiPart) {
baos.write(lineFeedBytes);
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(twoDashBytes);
baos.write(lineFeedBytes);
}
String contentType = isMultiPart ? "multipart/form-data; boundary=" + BOUNDARY : "application/x-www-form-urlencoded";
template.header("Content-type");
template.header("Content-type", contentType);
template.header("MIME-Version", "1.0");
template.body(baos.toByteArray(), Charset.forName(UTF_8));
}
/*
* Currently only supports text files
*/
private void addFilePart(StringBuilder formParamBuilder, String fieldName, File uploadFile) {
try {
String fileName = uploadFile.getName();
formParamBuilder.append("--").append(BOUNDARY).append(LINE_FEED);
formParamBuilder.append(
"Content-Disposition: form-data; name=\"" + fieldName
+ "\"; filename=\"" + fileName + "\"")
.append(LINE_FEED);
formParamBuilder.append(
"Content-Type: "
+ URLConnection.guessContentTypeFromName(fileName))
.append(LINE_FEED);
formParamBuilder.append(LINE_FEED);
private void addFilePart(ByteArrayOutputStream baos, String fieldName, File uploadFile) throws IOException {
String fileName = uploadFile.getName();
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(lineFeedBytes);
BufferedReader reader = new BufferedReader(new FileReader(uploadFile));
String line = "";
while ((line = reader.readLine()) != null) {
formParamBuilder.append(line).append(LINE_FEED);
}
String contentDisposition = "Content-Disposition: form-data; name=\"" + fieldName
+ "\"; filename=\"" + fileName + "\"";
baos.write(contentDisposition.getBytes(UTF_8));
baos.write(lineFeedBytes);
String contentType = "Content-Type: " + URLConnection.guessContentTypeFromName(fileName);
baos.write(contentType.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(lineFeedBytes);
formParamBuilder.append(LINE_FEED);
} catch (IOException e) {
e.printStackTrace();
BufferedReader reader = new BufferedReader(new FileReader(uploadFile));
InputStream input = new FileInputStream(uploadFile);
byte[] bytes = new byte[4096];
int len = bytes.length;
while ((len = input.read(bytes)) != -1) {
baos.write(bytes, 0, len);
baos.write(lineFeedBytes);
}
baos.write(lineFeedBytes);
}
private void addEncodedFormField(StringBuilder formParamBuilder, String name, String value) {
if (formParamBuilder.length() > 0) {
formParamBuilder.append("&");
private void addEncodedFormField(ByteArrayOutputStream baos, String name, String value, boolean isFirstField) throws IOException {
if (!isFirstField) {
baos.write(atBytes);
}
try {
formParamBuilder.append(URLEncoder.encode(name, "utf8"))
.append("=")
.append(URLEncoder.encode(value, "utf8"));
} catch (UnsupportedEncodingException e) {
// move on to next
}
String encodedName = URLEncoder.encode(name, UTF_8);
String encodedValue = URLEncoder.encode(value, UTF_8);
baos.write(encodedName.getBytes(UTF_8));
baos.write("=".getBytes(UTF_8));
baos.write(encodedValue.getBytes(UTF_8));
}
private void addMultiPartFormField(StringBuilder formParamBuilder, String name, String value) {
formParamBuilder.append("--").append(BOUNDARY).append(LINE_FEED);
formParamBuilder.append("Content-Disposition: form-data; name=\"" + name + "\"")
.append(LINE_FEED);
formParamBuilder.append("Content-Type: text/plain; charset=utf-8").append(
LINE_FEED);
formParamBuilder.append(LINE_FEED);
formParamBuilder.append(value).append(LINE_FEED);
private void addMultiPartFormField(ByteArrayOutputStream baos, String name, String value) throws IOException {
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(lineFeedBytes);
String contentDisposition = "Content-Disposition: form-data; name=\"" + name + "\"";
String contentType = "Content-Type: text/plain; charset=utf-8";
baos.write(contentDisposition.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(contentType.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(lineFeedBytes);
baos.write(value.getBytes(UTF_8));
baos.write(lineFeedBytes);
}
private boolean isMultiPart(Map<String, Object> formParams) {

View File

@ -1,6 +1,6 @@
package io.swagger.client;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-01T16:10:23.565+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class StringUtil {
/**
* Check if the given array contains the given value (with case-insensitive comparison).

View File

@ -1,20 +1,18 @@
package io.swagger.client.api;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.Pet;
import java.io.File;
import io.swagger.client.model.ApiResponse;
import java.util.*;
import feign.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
public interface PetApi extends io.swagger.client.ApiClient.Api {
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public interface PetApi extends ApiClient.Api {
/**
@ -28,7 +26,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void updatePet(Pet body) throws ApiException;
void updatePet(Pet body);
/**
* Add a new pet to the store
@ -41,7 +39,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void addPet(Pet body) throws ApiException;
void addPet(Pet body);
/**
* Finds Pets by status
@ -54,7 +52,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
List<Pet> findPetsByStatus(@Param("status") List<String> status) throws ApiException;
List<Pet> findPetsByStatus(@Param("status") List<String> status);
/**
* Finds Pets by tags
@ -67,7 +65,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
List<Pet> findPetsByTags(@Param("tags") List<String> tags) throws ApiException;
List<Pet> findPetsByTags(@Param("tags") List<String> tags);
/**
* Find pet by ID
@ -80,7 +78,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
Pet getPetById(@Param("petId") Long petId) throws ApiException;
Pet getPetById(@Param("petId") Long petId);
/**
* Updates a pet in the store with form data
@ -95,7 +93,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/x-www-form-urlencoded",
"Accepts: application/json",
})
void updatePetWithForm(@Param("petId") Long petId, @Param("name") String name, @Param("status") String status) throws ApiException;
void updatePetWithForm(@Param("petId") Long petId, @Param("name") String name, @Param("status") String status);
/**
* Deletes a pet
@ -110,7 +108,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Accepts: application/json",
"apiKey: {apiKey}"
})
void deletePet(@Param("petId") Long petId, @Param("apiKey") String apiKey) throws ApiException;
void deletePet(@Param("petId") Long petId, @Param("apiKey") String apiKey);
/**
* uploads an image
@ -125,7 +123,7 @@ public interface PetApi extends io.swagger.client.ApiClient.Api {
"Content-type: multipart/form-data",
"Accepts: application/json",
})
ApiResponse uploadFile(@Param("petId") Long petId, @Param("additionalMetadata") String additionalMetadata, @Param("file") File file) throws ApiException;
ApiResponse uploadFile(@Param("petId") Long petId, @Param("additionalMetadata") String additionalMetadata, @Param("file") File file);
}

View File

@ -1,10 +1,6 @@
package io.swagger.client.api;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import java.util.Map;
import io.swagger.client.model.Order;
@ -14,8 +10,8 @@ import java.util.*;
import feign.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
public interface StoreApi extends io.swagger.client.ApiClient.Api {
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public interface StoreApi extends ApiClient.Api {
/**
@ -28,7 +24,7 @@ public interface StoreApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
Map<String, Integer> getInventory() throws ApiException;
Map<String, Integer> getInventory();
/**
* Place an order for a pet
@ -41,7 +37,7 @@ public interface StoreApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
Order placeOrder(Order body) throws ApiException;
Order placeOrder(Order body);
/**
* Find purchase order by ID
@ -54,7 +50,7 @@ public interface StoreApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
Order getOrderById(@Param("orderId") Long orderId) throws ApiException;
Order getOrderById(@Param("orderId") Long orderId);
/**
* Delete purchase order by ID
@ -67,7 +63,7 @@ public interface StoreApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void deleteOrder(@Param("orderId") String orderId) throws ApiException;
void deleteOrder(@Param("orderId") String orderId);
}

View File

@ -1,10 +1,6 @@
package io.swagger.client.api;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.TypeRef;
import io.swagger.client.model.User;
import java.util.*;
@ -14,8 +10,8 @@ import java.util.*;
import feign.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
public interface UserApi extends io.swagger.client.ApiClient.Api {
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public interface UserApi extends ApiClient.Api {
/**
@ -29,7 +25,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void createUser(User body) throws ApiException;
void createUser(User body);
/**
* Creates list of users with given input array
@ -42,7 +38,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void createUsersWithArrayInput(List<User> body) throws ApiException;
void createUsersWithArrayInput(List<User> body);
/**
* Creates list of users with given input array
@ -55,7 +51,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void createUsersWithListInput(List<User> body) throws ApiException;
void createUsersWithListInput(List<User> body);
/**
* Logs user into the system
@ -69,7 +65,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
String loginUser(@Param("username") String username, @Param("password") String password) throws ApiException;
String loginUser(@Param("username") String username, @Param("password") String password);
/**
* Logs out current logged in user session
@ -81,7 +77,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void logoutUser() throws ApiException;
void logoutUser();
/**
* Get user by user name
@ -94,7 +90,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
User getUserByName(@Param("username") String username) throws ApiException;
User getUserByName(@Param("username") String username);
/**
* Updated user
@ -108,7 +104,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void updateUser(@Param("username") String username, User body) throws ApiException;
void updateUser(@Param("username") String username, User body);
/**
* Delete user
@ -121,7 +117,7 @@ public interface UserApi extends io.swagger.client.ApiClient.Api {
"Content-type: application/json",
"Accepts: application/json",
})
void deleteUser(@Param("username") String username) throws ApiException;
void deleteUser(@Param("username") String username);
}

View File

@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class ApiResponse {
private Integer code = null;

View File

@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class Category {
private Long id = null;

View File

@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class Order {
private Long id = null;

View File

@ -15,7 +15,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class Pet {
private Long id = null;

View File

@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class Tag {
private Long id = null;

View File

@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T01:11:21.159-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T22:27:06.680-05:00")
public class User {
private Long id = null;

View File

@ -1,7 +1,5 @@
package io.swagger.petstore.test;
import io.swagger.client.ApiException;
import io.swagger.client.*;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
@ -48,12 +46,8 @@ public class StoreApiTest {
api.deleteOrder(String.valueOf(order.getId()));
try {
api.getOrderById(order.getId());
// fail("expected an error");
} catch (ApiException e) {
// ok
}
api.getOrderById(order.getId());
// fail("expected an error");
}
private Order createOrder() {