Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions modules/swagger-codegen/src/main/resources/Java/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.util.*;
{{/imports}}

import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;

import javax.ws.rs.core.MediaType;

Expand Down Expand Up @@ -77,7 +78,8 @@ public class {{classname}} {
mp.field("{{baseName}}", ApiInvoker.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
{{/notFile}}{{#isFile}}
hasFields = true;
mp.field("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE);
mp.field("{{baseName}}", file.getName());
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
{{/isFile}}{{/formParams}}
if(hasFields)
postBody = mp;
Expand All @@ -96,12 +98,7 @@ public class {{classname}} {
return {{#returnType}}null{{/returnType}};
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return {{#returnType}} null{{/returnType}};
}
else {
throw ex;
}
throw ex;
}
}
{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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.Map;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -83,11 +84,19 @@ public class ApiInvoker {
return "";
} else if (param instanceof Date) {
return formatDateTime((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);
}
}

public void enableDebug() {
isDebug = true;
}
Expand Down Expand Up @@ -217,7 +226,7 @@ public class ApiInvoker {
}
else if ("DELETE".equals(method)) {
if(body == null)
response = builder.delete(ClientResponse.class, serialize(body));
response = builder.delete(ClientResponse.class);
else
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
}
Expand All @@ -228,12 +237,26 @@ public class ApiInvoker {
return null;
}
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
return (String) response.getEntity(String.class);
if(response.hasEntity()) {
return (String) response.getEntity(String.class);
}
else {
return "";
}
}
else {
String message = "error";
if(response.hasEntity()) {
try{
message = String.valueOf(response.getEntity(String.class));
}
catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getClientResponseStatus().getStatusCode(),
response.getEntity(String.class));
message);
}
}

Expand Down
7 changes: 3 additions & 4 deletions modules/swagger-codegen/src/main/resources/Java/pom.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@
</dependency>
</dependencies>
<properties>
<swagger-annotations-version>1.5.0-M1</swagger-annotations-version>
<jersey-version>1.7</jersey-version>
<jackson-version>2.1.4</jackson-version>
<swagger-annotations-version>1.5.3-M1</swagger-annotations-version>
<jersey-version>1.18</jersey-version>
<jackson-version>2.4.2</jackson-version>
<jodatime-version>2.3</jodatime-version>
<junit-version>4.8.1</junit-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions modules/swagger-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
<goal>start</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
Expand Down Expand Up @@ -226,7 +226,7 @@
<maven-plugin-version>1.0.0</maven-plugin-version>
<servlet-api-version>2.5</servlet-api-version>
<zip-version>1.3.2</zip-version>
<jetty-version>9.0.7.v20131107</jetty-version>
<jetty-version>9.2.9.v20150224</jetty-version>
<jersey2-version>2.4.1</jersey2-version>
</properties>
</project>
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
</activation>
<modules>
<module>samples/client/petstore/objc</module>
<module>samples/client/petstore/java</module>
</modules>
</profile>
</profiles>
Expand Down Expand Up @@ -363,7 +364,7 @@
<swagger-parser-version>1.0.3</swagger-parser-version>
<scala-version>2.11.1</scala-version>
<felix-version>2.3.4</felix-version>
<swagger-core-version>1.5.3-M1-SNAPSHOT</swagger-core-version>
<swagger-core-version>1.5.3-M1</swagger-core-version>
<scala-test-version>2.1.4</scala-test-version>
<commons-io-version>2.3</commons-io-version>
<commons-cli-version>1.2</commons-cli-version>
Expand Down
7 changes: 3 additions & 4 deletions samples/client/petstore/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@
</dependency>
</dependencies>
<properties>
<swagger-annotations-version>1.5.0-M1</swagger-annotations-version>
<jersey-version>1.7</jersey-version>
<jackson-version>2.1.4</jackson-version>
<swagger-annotations-version>1.5.3-M1</swagger-annotations-version>
<jersey-version>1.18</jersey-version>
<jackson-version>2.4.2</jackson-version>
<jodatime-version>2.3</jodatime-version>
<junit-version>4.8.1</junit-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.MediaType;

import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -83,11 +84,19 @@ public static String parameterToString(Object param) {
return "";
} else if (param instanceof Date) {
return formatDateTime((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);
}
}

public void enableDebug() {
isDebug = true;
}
Expand Down Expand Up @@ -217,7 +226,7 @@ else if ("PUT".equals(method)) {
}
else if ("DELETE".equals(method)) {
if(body == null)
response = builder.delete(ClientResponse.class, serialize(body));
response = builder.delete(ClientResponse.class);
else
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
}
Expand All @@ -228,12 +237,26 @@ else if ("DELETE".equals(method)) {
return null;
}
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
return (String) response.getEntity(String.class);
if(response.hasEntity()) {
return (String) response.getEntity(String.class);
}
else {
return "";
}
}
else {
String message = "error";
if(response.hasEntity()) {
try{
message = String.valueOf(response.getEntity(String.class));
}
catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getClientResponseStatus().getStatusCode(),
response.getEntity(String.class));
message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.File;

import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;

import javax.ws.rs.core.MediaType;

Expand Down Expand Up @@ -76,12 +77,7 @@ public void updatePet (Pet body) throws ApiException {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down Expand Up @@ -126,12 +122,7 @@ public void addPet (Pet body) throws ApiException {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down Expand Up @@ -178,12 +169,7 @@ public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down Expand Up @@ -230,12 +216,7 @@ public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down Expand Up @@ -281,12 +262,7 @@ public Pet getPetById (Long petId) throws ApiException {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down Expand Up @@ -340,12 +316,7 @@ public void updatePetWithForm (String petId, String name, String status) throws
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down Expand Up @@ -392,12 +363,7 @@ public void deletePet (String apiKey, Long petId) throws ApiException {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down Expand Up @@ -431,7 +397,8 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throws
mp.field("additionalMetadata", ApiInvoker.parameterToString(additionalMetadata), MediaType.MULTIPART_FORM_DATA_TYPE);

hasFields = true;
mp.field("file", file, MediaType.MULTIPART_FORM_DATA_TYPE);
mp.field("file", file.getName());
mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE));

if(hasFields)
postBody = mp;
Expand All @@ -451,12 +418,7 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throws
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

Expand Down
Loading