added consumes, produces

This commit is contained in:
Tony Tam 2015-02-03 23:54:37 -08:00
parent 949b321e13
commit bad6798433
4 changed files with 18 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import com.wordnik.swagger.models.*;
import java.util.*;
public class CodegenOperation {
public Boolean hasParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation;
public Boolean hasConsumes, hasProduces, hasParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation;
public String path, operationId, returnType, httpMethod, returnBaseType,
returnContainer, summary, notes, baseName, defaultResponse;

View File

@ -562,6 +562,7 @@ public class DefaultCodegen {
c.add(mediaType);
}
op.consumes = c;
op.hasConsumes = true;
}
if(operation.getProduces() != null && operation.getProduces().size() > 0) {
@ -576,6 +577,7 @@ public class DefaultCodegen {
c.add(mediaType);
}
op.produces = c;
op.hasProduces = true;
}
if(operation.getResponses() != null) {

View File

@ -3,6 +3,7 @@ package {{package}};
import {{modelPackage}}.*;
import com.wordnik.swagger.annotations.*;
import com.sun.jersey.multipart.FormDataParam;
{{#imports}}import {{import}};
{{/imports}}
@ -15,18 +16,19 @@ import javax.ws.rs.*;
@Path("/{{baseName}}")
@Api(value = "/{{baseName}}", description = "the {{baseName}} API")
@Produces({"application/json"})
{{#operations}}
public class {{classname}} {
{{#operation}}
@{{httpMethod}}
{{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}}
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
@ApiResponses(value = { {{#responses}}
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},
{{/hasMore}}{{/responses}} })
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{#hasMore}},
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
{{/hasMore}}{{/allParams}})
throws NotFoundException {
// do some magic!

View File

@ -71,9 +71,8 @@
<dependencies>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs</artifactId>
<artifactId>swagger-jersey-jaxrs</artifactId>
<version>${swagger-core-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@ -95,6 +94,16 @@
<artifactId>jersey-servlet</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.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>