This commit is contained in:
Tony Tam 2014-08-08 16:38:38 -04:00
parent c7da910e68
commit 454ec4b438
8 changed files with 456 additions and 196 deletions

View File

@ -160,6 +160,12 @@
<version>${jersey-version}</version> <version>${jersey-version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>

View File

@ -11,6 +11,7 @@ import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.api.client.WebResource.Builder; import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -117,7 +118,10 @@ public class ApiInvoker {
} }
else if ("POST".equals(method)) { else if ("POST".equals(method)) {
if(body == null) if(body == null)
response = builder.post(ClientResponse.class, serialize(body)); response = builder.post(ClientResponse.class, null);
else if(body instanceof FormDataMultiPart) {
response = builder.type(contentType).post(ClientResponse.class, body);
}
else else
response = builder.type(contentType).post(ClientResponse.class, serialize(body)); response = builder.type(contentType).post(ClientResponse.class, serialize(body));
} }

View File

@ -4,6 +4,10 @@ import com.wordnik.client.ApiException;
import com.wordnik.client.ApiInvoker; import com.wordnik.client.ApiInvoker;
import com.wordnik.petstore.model.Pet; import com.wordnik.petstore.model.Pet;
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.MediaType;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@ -26,6 +30,7 @@ public class PetApi {
//error info- code: 400 reason: "Invalid ID supplied" model: <none> //error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Pet not found" model: <none> //error info- code: 404 reason: "Pet not found" model: <none>
public Pet getPetById (Long petId) throws ApiException { public Pet getPetById (Long petId) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(petId == null ) { if(petId == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -43,8 +48,17 @@ public class PetApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return (Pet) ApiInvoker.deserialize(response, "", Pet.class); return (Pet) ApiInvoker.deserialize(response, "", Pet.class);
} }
@ -62,6 +76,7 @@ public class PetApi {
} }
//error info- code: 400 reason: "Invalid pet value" model: <none> //error info- code: 400 reason: "Invalid pet value" model: <none>
public void deletePet (String petId) throws ApiException { public void deletePet (String petId) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(petId == null ) { if(petId == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -79,8 +94,17 @@ public class PetApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }
@ -98,6 +122,7 @@ public class PetApi {
} }
//error info- code: 400 reason: "Invalid tag value" model: <none> //error info- code: 400 reason: "Invalid tag value" model: <none>
public List<Pet> partialUpdate (String petId, Pet body) throws ApiException { public List<Pet> partialUpdate (String petId, Pet body) throws ApiException {
Object postBody = body;
// verify required params are set // verify required params are set
if(petId == null || body == null ) { if(petId == null || body == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -115,10 +140,19 @@ public class PetApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "PATCH", queryParams, body, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "PATCH", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class); return (List<Pet>) ApiInvoker.deserialize(response, "List", Pet.class);
} }
else { else {
return null; return null;
@ -134,6 +168,7 @@ public class PetApi {
} }
//error info- code: 405 reason: "Invalid input" model: <none> //error info- code: 405 reason: "Invalid input" model: <none>
public void updatePetWithForm (String petId, String name, String status) throws ApiException { public void updatePetWithForm (String petId, String name, String status) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(petId == null ) { if(petId == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -146,47 +181,26 @@ public class PetApi {
Map<String, String> headerParams = new HashMap<String, String>(); Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>(); Map<String, String> formParams = new HashMap<String, String>();
formParams.put("name", name);
formParams.put("status", status);
String[] contentTypes = { String[] contentTypes = {
"application/x-www-form-urlencoded"}; "application/x-www-form-urlencoded"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try { if(contentType.startsWith("multipart/form-data")) {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, null, headerParams, formParams, contentType); boolean hasFields = false;
if(response != null){ FormDataMultiPart mp = new FormDataMultiPart();
return ; hasFields = true;
} mp.field("name", "name", MediaType.MULTIPART_FORM_DATA_TYPE);
else { hasFields = true;
return ; mp.field("status", "status", MediaType.MULTIPART_FORM_DATA_TYPE);
} if(hasFields)
} catch (ApiException ex) { postBody = mp;
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
} }
} else {
public void uploadFile (String additionalMetadata, File body) throws ApiException { formParams.put("name", name);formParams.put("status", status);}
// create path and map variables
String path = "/pet/uploadImage".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>();
formParams.put("additionalMetadata", additionalMetadata);
String[] contentTypes = {
"multipart/form-data"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }
@ -204,6 +218,7 @@ public class PetApi {
} }
//error info- code: 405 reason: "Invalid input" model: <none> //error info- code: 405 reason: "Invalid input" model: <none>
public void addPet (Pet body) throws ApiException { public void addPet (Pet body) throws ApiException {
Object postBody = body;
// verify required params are set // verify required params are set
if(body == null ) { if(body == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -221,8 +236,17 @@ public class PetApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }
@ -242,6 +266,7 @@ public class PetApi {
//error info- code: 404 reason: "Pet not found" model: <none> //error info- code: 404 reason: "Pet not found" model: <none>
//error info- code: 405 reason: "Validation exception" model: <none> //error info- code: 405 reason: "Validation exception" model: <none>
public void updatePet (Pet body) throws ApiException { public void updatePet (Pet body) throws ApiException {
Object postBody = body;
// verify required params are set // verify required params are set
if(body == null ) { if(body == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -259,8 +284,17 @@ public class PetApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, body, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }
@ -278,6 +312,7 @@ public class PetApi {
} }
//error info- code: 400 reason: "Invalid status value" model: <none> //error info- code: 400 reason: "Invalid status value" model: <none>
public List<Pet> findPetsByStatus (String status) throws ApiException { public List<Pet> findPetsByStatus (String status) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(status == null ) { if(status == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -297,10 +332,19 @@ public class PetApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class); return (List<Pet>) ApiInvoker.deserialize(response, "List", Pet.class);
} }
else { else {
return null; return null;
@ -316,6 +360,7 @@ public class PetApi {
} }
//error info- code: 400 reason: "Invalid tag value" model: <none> //error info- code: 400 reason: "Invalid tag value" model: <none>
public List<Pet> findPetsByTags (String tags) throws ApiException { public List<Pet> findPetsByTags (String tags) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(tags == null ) { if(tags == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -335,10 +380,19 @@ public class PetApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class); return (List<Pet>) ApiInvoker.deserialize(response, "List", Pet.class);
} }
else { else {
return null; return null;
@ -352,5 +406,50 @@ public class PetApi {
} }
} }
} }
public void uploadFile (String additionalMetadata, File file) throws ApiException {
Object postBody = null;
// create path and map variables
String path = "/pet/uploadImage".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>();
String[] contentTypes = {
"multipart/form-data"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
hasFields = true;
mp.field("additionalMetadata", "additionalMetadata", MediaType.MULTIPART_FORM_DATA_TYPE);
hasFields = true;
mp.field("file", file, MediaType.MULTIPART_FORM_DATA_TYPE);
if(hasFields)
postBody = mp;
}
else {
formParams.put("additionalMetadata", additionalMetadata);}
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
}
}
} }

View File

@ -4,6 +4,10 @@ import com.wordnik.client.ApiException;
import com.wordnik.client.ApiInvoker; import com.wordnik.client.ApiInvoker;
import com.wordnik.petstore.model.Order; import com.wordnik.petstore.model.Order;
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.MediaType;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@ -23,46 +27,10 @@ public class StoreApi {
return basePath; return basePath;
} }
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Order not found" model: <none>
public Order getOrderById (String orderId) throws ApiException {
// verify required params are set
if(orderId == null ) {
throw new ApiException(400, "missing required params");
}
// create path and map variables
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (Order) ApiInvoker.deserialize(response, "", Order.class);
}
else {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
}
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none> //error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Order not found" model: <none> //error info- code: 404 reason: "Order not found" model: <none>
public void deleteOrder (String orderId) throws ApiException { public void deleteOrder (String orderId) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(orderId == null ) { if(orderId == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -80,8 +48,17 @@ public class StoreApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }
@ -97,8 +74,56 @@ public class StoreApi {
} }
} }
} }
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Order not found" model: <none>
public Order getOrderById (String orderId) throws ApiException {
Object postBody = null;
// verify required params are set
if(orderId == null ) {
throw new ApiException(400, "missing required params");
}
// create path and map variables
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){
return (Order) ApiInvoker.deserialize(response, "", Order.class);
}
else {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
}
}
//error info- code: 400 reason: "Invalid order" model: <none> //error info- code: 400 reason: "Invalid order" model: <none>
public void placeOrder (Order body) throws ApiException { public void placeOrder (Order body) throws ApiException {
Object postBody = body;
// verify required params are set // verify required params are set
if(body == null ) { if(body == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -116,8 +141,17 @@ public class StoreApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }

View File

@ -4,6 +4,10 @@ import com.wordnik.client.ApiException;
import com.wordnik.client.ApiInvoker; import com.wordnik.client.ApiInvoker;
import com.wordnik.petstore.model.User; import com.wordnik.petstore.model.User;
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.MediaType;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@ -23,9 +27,145 @@ public class UserApi {
return basePath; return basePath;
} }
public void createUsersWithArrayInput (List<User> body) throws ApiException {
Object postBody = body;
// verify required params are set
if(body == null ) {
throw new ApiException(400, "missing required params");
}
// 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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
}
}
public void createUsersWithListInput (List<User> body) throws ApiException {
Object postBody = body;
// verify required params are set
if(body == null ) {
throw new ApiException(400, "missing required params");
}
// 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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
}
}
public void createUser (User body) throws ApiException {
Object postBody = body;
// verify required params are set
if(body == null ) {
throw new ApiException(400, "missing required params");
}
// 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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
}
}
//error info- code: 400 reason: "Invalid username supplied" model: <none> //error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none> //error info- code: 404 reason: "User not found" model: <none>
public void updateUser (String username, User body) throws ApiException { public void updateUser (String username, User body) throws ApiException {
Object postBody = body;
// verify required params are set // verify required params are set
if(username == null || body == null ) { if(username == null || body == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -43,8 +183,17 @@ public class UserApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, body, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }
@ -63,6 +212,7 @@ public class UserApi {
//error info- code: 400 reason: "Invalid username supplied" model: <none> //error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none> //error info- code: 404 reason: "User not found" model: <none>
public void deleteUser (String username) throws ApiException { public void deleteUser (String username) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(username == null ) { if(username == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -80,8 +230,17 @@ public class UserApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }
@ -100,6 +259,7 @@ public class UserApi {
//error info- code: 400 reason: "Invalid username supplied" model: <none> //error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none> //error info- code: 404 reason: "User not found" model: <none>
public User getUserByName (String username) throws ApiException { public User getUserByName (String username) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(username == null ) { if(username == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -117,8 +277,17 @@ public class UserApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return (User) ApiInvoker.deserialize(response, "", User.class); return (User) ApiInvoker.deserialize(response, "", User.class);
} }
@ -136,6 +305,7 @@ public class UserApi {
} }
//error info- code: 400 reason: "Invalid username and password combination" model: <none> //error info- code: 400 reason: "Invalid username and password combination" model: <none>
public String loginUser (String username, String password) throws ApiException { public String loginUser (String username, String password) throws ApiException {
Object postBody = null;
// verify required params are set // verify required params are set
if(username == null || password == null ) { if(username == null || password == null ) {
throw new ApiException(400, "missing required params"); throw new ApiException(400, "missing required params");
@ -157,8 +327,17 @@ public class UserApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
if(hasFields)
postBody = mp;
}
else {
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return (String) ApiInvoker.deserialize(response, "", String.class); return (String) ApiInvoker.deserialize(response, "", String.class);
} }
@ -175,6 +354,7 @@ public class UserApi {
} }
} }
public void logoutUser () throws ApiException { public void logoutUser () throws ApiException {
Object postBody = null;
// create path and map variables // create path and map variables
String path = "/user/logout".replaceAll("\\{format\\}","json"); String path = "/user/logout".replaceAll("\\{format\\}","json");
@ -188,113 +368,17 @@ public class UserApi {
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try { if(contentType.startsWith("multipart/form-data")) {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType); boolean hasFields = false;
if(response != null){ FormDataMultiPart mp = new FormDataMultiPart();
return ; if(hasFields)
} postBody = mp;
else {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
} }
} else {
public void createUser (User body) throws ApiException { }
// verify required params are set
if(body == null ) {
throw new ApiException(400, "missing required params");
}
// 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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
}
}
public void createUsersWithArrayInput (List<User> body) throws ApiException {
// verify required params are set
if(body == null ) {
throw new ApiException(400, "missing required params");
}
// 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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType);
if(response != null){
return ;
}
else {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
}
}
public void createUsersWithListInput (List<User> body) throws ApiException {
// verify required params are set
if(body == null ) {
throw new ApiException(400, "missing required params");
}
// 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>();
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return ; return ;
} }

View File

@ -6,6 +6,10 @@ import {{invokerPackage}}.ApiInvoker;
{{#imports}}import {{import}}; {{#imports}}import {{import}};
{{/imports}} {{/imports}}
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.MediaType;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@ -32,6 +36,7 @@ public class {{classname}} {
{{/responseModel}} {{/responseModel}}
{{/errorList}} {{/errorList}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
Object postBody = {{#bodyParam}}{{bodyParam}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#requiredParamCount}} {{#requiredParamCount}}
// verify required params are set // verify required params are set
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) { if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
@ -54,17 +59,35 @@ public class {{classname}} {
{{#headerParams}}headerParams.put("{{baseName}}", {{paramName}}); {{#headerParams}}headerParams.put("{{baseName}}", {{paramName}});
{{/headerParams}} {{/headerParams}}
{{#formParams}}formParams.put("{{baseName}}", {{paramName}});
{{/formParams}}
String[] contentTypes = { String[] contentTypes = {
{{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}} {{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}}
}; };
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
if(contentType.startsWith("multipart/form-data")) {
boolean hasFields = false;
FormDataMultiPart mp = new FormDataMultiPart();
{{#formParams}}
{{#notFile}}
hasFields = true;
mp.field("{{baseName}}", "{{paramName}}", MediaType.MULTIPART_FORM_DATA_TYPE);
{{/notFile}}
{{#isFile}}
hasFields = true;
mp.field("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE);
{{/isFile}}
{{/formParams}}
if(hasFields)
postBody = mp;
}
else {
{{#formParams}}{{#notFile}}formParams.put("{{baseName}}", {{paramName}});{{/notFile}}
{{/formParams}}
}
try { try {
String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, {{#bodyParam}}{{bodyParam}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}, headerParams, formParams, contentType); String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, contentType);
if(response != null){ if(response != null){
return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}}; return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
} }

View File

@ -11,6 +11,7 @@ import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.api.client.WebResource.Builder; import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -117,7 +118,10 @@ public class ApiInvoker {
} }
else if ("POST".equals(method)) { else if ("POST".equals(method)) {
if(body == null) if(body == null)
response = builder.post(ClientResponse.class, serialize(body)); response = builder.post(ClientResponse.class, null);
else if(body instanceof FormDataMultiPart) {
response = builder.type(contentType).post(ClientResponse.class, body);
}
else else
response = builder.type(contentType).post(ClientResponse.class, serialize(body)); response = builder.type(contentType).post(ClientResponse.class, serialize(body));
} }

View File

@ -160,6 +160,12 @@
<version>${jersey-version}</version> <version>${jersey-version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>