diff --git a/src/main/java/com/wordnik/swagger/codegen/Codegen.java b/src/main/java/com/wordnik/swagger/codegen/Codegen.java index fbbf55f80dd..17ab9118062 100644 --- a/src/main/java/com/wordnik/swagger/codegen/Codegen.java +++ b/src/main/java/com/wordnik/swagger/codegen/Codegen.java @@ -53,6 +53,8 @@ public class Codegen extends DefaultGenerator { return new ObjcClientCodegen(); else if("java".equals(name)) return new JavaClientCodegen(); + else if("jaxrs".equals(name)) + return new JaxRSServerCodegen(); else throw new RuntimeException("unsupported client type"); } diff --git a/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java b/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java index 43a5f2902ab..808b893913a 100644 --- a/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java +++ b/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java @@ -40,4 +40,7 @@ public interface CodegenConfig { String toModelFilename(String name); String toModelImport(String name); String toApiImport(String name); + void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations); + Map postProcessModels(Map objs); + Map postProcessOperations(Map objs); } diff --git a/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java b/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java index 51dc2e19ad5..01e3898c5c1 100644 --- a/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java +++ b/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java @@ -9,7 +9,7 @@ import java.util.*; public class CodegenOperation { public Boolean hasParams, returnTypeIsPrimitive, returnSimpleType; public String path, operationId, returnType, httpMethod, returnBaseType, - returnContainer, summary, notes; + returnContainer, summary, notes, baseName; public List> consumes, produces; public List allParams = new ArrayList(); @@ -18,6 +18,8 @@ public class CodegenOperation { public List queryParams = new ArrayList(); public List headerParams = new ArrayList(); public List formParams = new ArrayList(); + public List tags; + public List responses = new ArrayList(); public Set imports = new HashSet(); diff --git a/src/main/java/com/wordnik/swagger/codegen/CodegenParameter.java b/src/main/java/com/wordnik/swagger/codegen/CodegenParameter.java index 70e0f59f7d5..1b502442530 100644 --- a/src/main/java/com/wordnik/swagger/codegen/CodegenParameter.java +++ b/src/main/java/com/wordnik/swagger/codegen/CodegenParameter.java @@ -2,5 +2,5 @@ package com.wordnik.swagger.codegen; public class CodegenParameter { public Boolean hasMore = null, isContainer = null, secondaryParam = null; - public String baseName, paramName, dataType, collectionFormat; + public String baseName, paramName, dataType, collectionFormat, description; } \ No newline at end of file diff --git a/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java b/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java index 278e91fd86f..91baf03a257 100644 --- a/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java +++ b/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java @@ -22,6 +22,16 @@ public class DefaultCodegen { protected Map additionalProperties = new HashMap(); protected List supportingFiles = new ArrayList(); + // override with any special post-processing + public Map postProcessModels(Map objs) { + return objs; + } + + // override with any special post-processing + public Map postProcessOperations(Map objs) { + return objs; + } + public Set defaultIncludes() { return defaultIncludes; } @@ -381,8 +391,6 @@ public class DefaultCodegen { if(languageSpecificPrimitives().contains(type)) property.isPrimitiveType = true; } - if("id".equals(property.name)) - Json.prettyPrint(property); return property; } @@ -397,6 +405,7 @@ public class DefaultCodegen { op.operationId = operationId; op.summary = operation.getSummary(); op.notes = operation.getDescription(); + op.tags = operation.getTags(); Response methodResponse = null; @@ -438,6 +447,23 @@ public class DefaultCodegen { if(methodResponse == null && operation.getResponses().keySet().contains("default")) { methodResponse = operation.getResponses().get("default"); } + for(String responseCode: operation.getResponses().keySet()) { + Response response = operation.getResponses().get(responseCode); + if(response != methodResponse) { + CodegenResponse r = new CodegenResponse(); + if("default".equals(responseCode)) + r.code = "0"; + else + r.code = responseCode; + r.message = response.getDescription(); + r.schema = response.getSchema(); + op.responses.add(r); + } + for(int i = 0; i < op.responses.size() - 1; i++) { + CodegenResponse r = op.responses.get(i); + r.hasMore = new Boolean(true); + } + } } if(methodResponse != null && methodResponse.getSchema() != null) { @@ -490,6 +516,7 @@ public class DefaultCodegen { for(Parameter param : parameters) { CodegenParameter p = new CodegenParameter(); p.baseName = param.getName(); + p.description = param.getDescription(); if(param instanceof SerializableParameter) { SerializableParameter qp = (SerializableParameter) param; @@ -610,4 +637,15 @@ public class DefaultCodegen { } return objs; } + + + public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { + List opList = operations.get(tag); + if(opList == null) { + opList = new ArrayList(); + operations.put(tag, opList); + } + opList.add(co); + co.baseName = tag; + } } \ No newline at end of file diff --git a/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java b/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java index 28fab4d90a8..1e6c9c75200 100644 --- a/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java +++ b/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java @@ -43,12 +43,17 @@ public class DefaultGenerator implements Generator { modelMap.put(name, model); models = processModels(config, modelMap); models.putAll(config.additionalProperties()); - for(String templateName: config.modelTemplateFiles().keySet()) { + for(String templateName : config.modelTemplateFiles().keySet()) { String suffix = config.modelTemplateFiles().get(templateName); String filename = config.modelFileFolder() + File.separator + config.toModelFilename(name) + suffix; String template = readTemplate(config.templateDir() + File.separator + templateName); Template tmpl = Mustache.compiler() + .withLoader(new Mustache.TemplateLoader() { + public Reader getTemplate (String name) { + return getTemplateReader(config.templateDir() + File.separator + name + ".mustache"); + }; + }) .defaultValue("") .compile(template); @@ -56,13 +61,14 @@ public class DefaultGenerator implements Generator { } } // apis - Map> paths = groupPaths(swagger.getPaths()); - for(String tag: paths.keySet()) { + Map> paths = processPaths(swagger.getPaths()); + for(String tag : paths.keySet()) { List ops = paths.get(tag); operations = processOperations(config, tag, ops); operations.putAll(config.additionalProperties()); - for(String templateName: config.apiTemplateFiles().keySet()) { + operations.put("baseName", tag); + for(String templateName : config.apiTemplateFiles().keySet()) { String suffix = config.apiTemplateFiles().get(templateName); String filename = config.apiFileFolder() + File.separator + @@ -71,6 +77,12 @@ public class DefaultGenerator implements Generator { String template = readTemplate(config.templateDir() + File.separator + templateName); Template tmpl = Mustache.compiler() + .withLoader(new Mustache.TemplateLoader() { + public Reader getTemplate (String name) { + System.out.println("loading template " + name); + return getTemplateReader(config.templateDir() + File.separator + name + ".mustache"); + }; + }) .defaultValue("") .compile(template); @@ -81,7 +93,8 @@ public class DefaultGenerator implements Generator { // supporting files Map bundle = new HashMap(); bundle.putAll(config.additionalProperties()); - for(SupportingFile support: config.supportingFiles()) { + bundle.put("apiPackage", config.apiPackage()); + for(SupportingFile support : config.supportingFiles()) { String outputFolder = config.outputFolder(); if(support.folder != null && !"".equals(support.folder)) outputFolder += File.separator + support.folder; @@ -93,6 +106,11 @@ public class DefaultGenerator implements Generator { if(support.templateFile.endsWith("mustache")) { String template = readTemplate(config.templateDir() + File.separator + support.templateFile); Template tmpl = Mustache.compiler() + .withLoader(new Mustache.TemplateLoader() { + public Reader getTemplate (String name) { + return getTemplateReader(config.templateDir() + File.separator + name + ".mustache"); + }; + }) .defaultValue("") .compile(template); @@ -110,12 +128,12 @@ public class DefaultGenerator implements Generator { } } - public Map> groupPaths(Map paths) { + public Map> processPaths(Map paths) { // group by tag, create a Default grouping if none Map> ops = new HashMap>(); List tags = null; - for(String resourcePath: paths.keySet()) { + for(String resourcePath : paths.keySet()) { Path path = paths.get(resourcePath); processOperation(resourcePath, "get", path.getGet(), ops); processOperation(resourcePath, "put", path.getPut(), ops); @@ -135,14 +153,12 @@ public class DefaultGenerator implements Generator { tags.add("default"); } - for(String tag: tags) { - List opList = operations.get(tag); - if(opList == null) { - opList = new ArrayList(); - operations.put(tag, opList); - } + for(String tag : tags) { CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation); - opList.add(co); + co.tags = new ArrayList(); + co.tags.add(tag); + + config.addOperationToGroup(tag, resourcePath, operation, co, operations); } } } @@ -164,14 +180,27 @@ public class DefaultGenerator implements Generator { } public String readTemplate(String name) { + try{ + Reader reader = getTemplateReader(name); + if(reader == null) + throw new RuntimeException("no file found"); + java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } + catch(Exception e) { + e.printStackTrace(); + } + throw new RuntimeException("can't load template " + name); + } + + public Reader getTemplateReader(String name) { try{ InputStream is = this.getClass().getClassLoader().getResourceAsStream(name); if(is == null) is = new FileInputStream(new File(name)); if(is == null) throw new RuntimeException("no file found"); - java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; + return new InputStreamReader(is); } catch(Exception e) { e.printStackTrace(); @@ -205,7 +234,7 @@ public class DefaultGenerator implements Generator { } operations.put("imports", imports); - + config.postProcessOperations(operations); return operations; } @@ -240,6 +269,8 @@ public class DefaultGenerator implements Generator { } objs.put("imports", imports); + config.postProcessModels(objs); + return objs; } } \ No newline at end of file diff --git a/src/main/java/com/wordnik/swagger/codegen/languages/JaxRSServerCodegen.java b/src/main/java/com/wordnik/swagger/codegen/languages/JaxRSServerCodegen.java new file mode 100644 index 00000000000..4bde8918afb --- /dev/null +++ b/src/main/java/com/wordnik/swagger/codegen/languages/JaxRSServerCodegen.java @@ -0,0 +1,123 @@ +package com.wordnik.swagger.codegen.languages; + +import com.wordnik.swagger.models.Operation; +import com.wordnik.swagger.models.Path; +import com.wordnik.swagger.util.Json; +import com.wordnik.swagger.codegen.*; +import com.wordnik.swagger.models.properties.*; + +import java.util.*; +import java.io.File; + +public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig { + protected String invokerPackage = "com.wordnik.api"; + protected String groupId = "com.wordnik"; + protected String artifactId = "swagger-server"; + protected String artifactVersion = "1.0.0"; + protected String sourceFolder = "src/main/java"; + protected String title = "Swagger Server"; + + public JaxRSServerCodegen() { + super(); + outputFolder = "generated-code/javaJaxRS"; + modelTemplateFiles.put("model.mustache", ".java"); + apiTemplateFiles.put("api.mustache", ".java"); + templateDir = "src/main/resources/JavaJaxRS"; + apiPackage = "com.wordnik.api"; + modelPackage = "com.wordnik.model"; + + additionalProperties.put("invokerPackage", invokerPackage); + additionalProperties.put("groupId", groupId); + additionalProperties.put("artifactId", artifactId); + additionalProperties.put("artifactVersion", artifactVersion); + additionalProperties.put("title", title); + + supportingFiles.clear(); + supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); + supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); + supportingFiles.add(new SupportingFile("ApiException.mustache", + (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java")); + supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache", + (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiOriginFilter.java")); + supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache", + (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiResponseMessage.java")); + supportingFiles.add(new SupportingFile("NotFoundException.mustache", + (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java")); + supportingFiles.add(new SupportingFile("web.mustache", + ("src/main/webapp/WEB-INF"), "web.xml")); + + languageSpecificPrimitives = new HashSet( + Arrays.asList( + "String", + "boolean", + "Boolean", + "Double", + "Integer", + "Long", + "Float") + ); + } + + @Override + public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { + String basePath = resourcePath; + if(basePath.startsWith("/")) + basePath = basePath.substring(1); + int pos = basePath.indexOf("/"); + if(pos > 0) + basePath = basePath.substring(0, pos); + + if(basePath == "") + basePath = "default"; + else { + if(co.path.startsWith("/" + basePath)) + co.path = co.path.substring(("/" + basePath).length()); + } + List opList = operations.get(basePath); + if(opList == null) { + opList = new ArrayList(); + operations.put(basePath, opList); + } + opList.add(co); + co.baseName = basePath; + } + + public Map postProcessOperations(Map objs) { + Map operations = (Map)objs.get("operations"); + if(operations != null) { + List ops = (List) operations.get("operation"); + for(CodegenOperation operation : ops) { + if(operation.returnType == null) + operation.returnType = "Void"; + else if(operation.returnType.startsWith("List")) { + String rt = operation.returnType; + int end = rt.lastIndexOf(">"); + if(end > 0) { + operation.returnType = rt.substring("List<".length(), end); + operation.returnContainer = "List"; + } + } + else if(operation.returnType.startsWith("Map")) { + String rt = operation.returnType; + int end = rt.lastIndexOf(">"); + if(end > 0) { + operation.returnType = rt.substring("Map<".length(), end); + operation.returnContainer = "Map"; + } + } + else if(operation.returnType.startsWith("Set")) { + String rt = operation.returnType; + int end = rt.lastIndexOf(">"); + if(end > 0) { + operation.returnType = rt.substring("Set<".length(), end); + operation.returnContainer = "Set"; + } + } + // Json.prettyPrint(operation); + // if(return) + } + } + // Json.prettyPrint(objs); + return objs; + } +} \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/ApiException.mustache b/src/main/resources/JavaJaxRS/ApiException.mustache new file mode 100644 index 00000000000..ffab3b1088e --- /dev/null +++ b/src/main/resources/JavaJaxRS/ApiException.mustache @@ -0,0 +1,9 @@ +package {{apiPackage}}; + +public class ApiException extends Exception{ + private int code; + public ApiException (int code, String msg) { + super(msg); + this.code = code; + } +} diff --git a/src/main/resources/JavaJaxRS/ApiOriginFilter.mustache b/src/main/resources/JavaJaxRS/ApiOriginFilter.mustache new file mode 100644 index 00000000000..68675432c64 --- /dev/null +++ b/src/main/resources/JavaJaxRS/ApiOriginFilter.mustache @@ -0,0 +1,26 @@ +package {{apiPackage}}; + +import java.io.IOException; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; + +public class ApiOriginFilter implements javax.servlet.Filter { + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + @Override + public void destroy() { + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } +} \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/ApiResponseMessage.mustache b/src/main/resources/JavaJaxRS/ApiResponseMessage.mustache new file mode 100644 index 00000000000..94711b26efb --- /dev/null +++ b/src/main/resources/JavaJaxRS/ApiResponseMessage.mustache @@ -0,0 +1,68 @@ +package {{apiPackage}}; + +import javax.xml.bind.annotation.XmlTransient; + +@javax.xml.bind.annotation.XmlRootElement +public class ApiResponseMessage { + public static final int ERROR = 1; + public static final int WARNING = 2; + public static final int INFO = 3; + public static final int OK = 4; + public static final int TOO_BUSY = 5; + + int code; + String type; + String message; + + public ApiResponseMessage(){} + + public ApiResponseMessage(int code, String message){ + this.code = code; + switch(code){ + case ERROR: + setType("error"); + break; + case WARNING: + setType("warning"); + break; + case INFO: + setType("info"); + break; + case OK: + setType("ok"); + break; + case TOO_BUSY: + setType("too busy"); + break; + default: + setType("unknown"); + break; + } + this.message = message; + } + + @XmlTransient + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/resources/JavaJaxRS/NotFoundException.mustache b/src/main/resources/JavaJaxRS/NotFoundException.mustache new file mode 100644 index 00000000000..8ab2c99e4f8 --- /dev/null +++ b/src/main/resources/JavaJaxRS/NotFoundException.mustache @@ -0,0 +1,9 @@ +package {{apiPackage}}; + +public class NotFoundException extends ApiException { + private int code; + public NotFoundException (int code, String msg) { + super(code, msg); + this.code = code; + } +} diff --git a/src/main/resources/JavaJaxRS/README.mustache b/src/main/resources/JavaJaxRS/README.mustache new file mode 100644 index 00000000000..f8a560b776f --- /dev/null +++ b/src/main/resources/JavaJaxRS/README.mustache @@ -0,0 +1,10 @@ +# Swagger generated server + +## Overview +This server was generated by the [swagger-codegen](https://github.com/wordnik/swagger-codegen) project. By using the +[swagger-spec](https://github.com/wordnik/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +is an example of building a swagger-enabled scalatra server. + +This example uses the [scalatra](http://scalatra.org/) framework. To see how to make this your own, look here: + +[README](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/scalatra) \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/api.mustache b/src/main/resources/JavaJaxRS/api.mustache new file mode 100644 index 00000000000..766af3a8a4f --- /dev/null +++ b/src/main/resources/JavaJaxRS/api.mustache @@ -0,0 +1,36 @@ +package {{package}}; + +import com.wordnik.swagger.annotations.*; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import {{package}}.NotFoundException; + +import javax.ws.rs.core.Response; +import javax.ws.rs.*; + +@Path("/{{baseName}}") +@Api(value = "/{{baseName}}", description = "the {{baseName}} API") +@Produces({"application/json"}) +{{#operations}} +public class {{classname}} { + {{#operation}} + @{{httpMethod}} + @Path("{{path}}") + @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}},{{/hasMore}}{{/allParams}}) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/JavaJaxRS/bodyParams.mustache b/src/main/resources/JavaJaxRS/bodyParams.mustache new file mode 100644 index 00000000000..109e3bf26fc --- /dev/null +++ b/src/main/resources/JavaJaxRS/bodyParams.mustache @@ -0,0 +1 @@ +{{#bodyParams}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{newline}}{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{newline}}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{newline}}{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/bodyParams}} \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/headerParams.mustache b/src/main/resources/JavaJaxRS/headerParams.mustache new file mode 100644 index 00000000000..0054c4c6dee --- /dev/null +++ b/src/main/resources/JavaJaxRS/headerParams.mustache @@ -0,0 +1 @@ +{{#headerParams}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{newline}}{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{newline}}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{newline}}{{/defaultValue}})@HeaderParam("{{paramName}}"){{newline}} {{{dataType}}} {{paramName}}{{/headerParams}} \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/model.mustache b/src/main/resources/JavaJaxRS/model.mustache new file mode 100644 index 00000000000..938daf4d5f6 --- /dev/null +++ b/src/main/resources/JavaJaxRS/model.mustache @@ -0,0 +1,42 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +{{#models}} + +{{#model}}{{#description}} +/** + * {{description}} + **/{{/description}} +public class {{classname}} { {{#vars}} + /**{{#description}} + * {{{description}}}{{/description}} + * required: {{required}}{{#minimum}} + * minimum: {{minimum}}{{/minimum}}{{#maximum}} + * maximum: {{maximum}}{{/maximum}} + **/ + private {{{datatype}}} {{name}} = {{{defaultValue}}};{{#allowableValues}} + + //{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} }; + {{/min}}{{/allowableValues}}{{/vars}} + + {{#vars}}public {{{datatype}}} {{getter}}() { + return {{name}}; + } + public void {{setter}}({{{datatype}}} {{name}}) { + this.{{name}} = {{name}}; + } + + {{/vars}} + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class {{classname}} {\n"); + {{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n"); + {{/vars}}sb.append("}\n"); + return sb.toString(); + } +} +{{/model}} +{{/models}} \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/pathParams.mustache b/src/main/resources/JavaJaxRS/pathParams.mustache new file mode 100644 index 00000000000..7d3fcce56ad --- /dev/null +++ b/src/main/resources/JavaJaxRS/pathParams.mustache @@ -0,0 +1 @@ +{{#pathParams}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{newline}}{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{newline}}{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{newline}}{{/defaultValue}})@PathParam("{{paramName}}"){{newline}} {{{dataType}}} {{paramName}}{{/pathParams}} \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/pom.mustache b/src/main/resources/JavaJaxRS/pom.mustache new file mode 100644 index 00000000000..55f69368ac9 --- /dev/null +++ b/src/main/resources/JavaJaxRS/pom.mustache @@ -0,0 +1,126 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{artifactVersion}} + + src/main/java + + + org.apache.maven.plugins + maven-war-plugin + 2.1.1 + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + org.mortbay.jetty + jetty-maven-plugin + ${jetty-version} + + + / + + target/${project.artifactId}-${project.version} + ${project.basedir}/conf/jetty/webdefault.xml + 8079 + stopit + + + 8002 + 60000 + 8443 + + + + + + start-jetty + pre-integration-test + + run + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + + + + com.wordnik + swagger-jaxrs + ${swagger-core-version} + compile + + + org.slf4j + slf4j-log4j12 + ${slf4j-version} + + + com.sun.jersey + jersey-core + ${jersey-version} + + + com.sun.jersey + jersey-json + ${jersey-version} + + + com.sun.jersey + jersey-servlet + ${jersey-version} + + + + org.scalatest + scalatest_2.9.1 + ${scala-test-version} + test + + + junit + junit + ${junit-version} + test + + + javax.servlet + servlet-api + ${servlet-api-version} + + + + 1.5.0-SNAPSHOT + 8.1.11.v20130520 + 1.13 + 1.6.3 + 1.6.1 + 4.8.1 + 2.5 + + \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/project/build.properties b/src/main/resources/JavaJaxRS/project/build.properties new file mode 100644 index 00000000000..a8c2f849be3 --- /dev/null +++ b/src/main/resources/JavaJaxRS/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.12.0 diff --git a/src/main/resources/JavaJaxRS/project/plugins.sbt b/src/main/resources/JavaJaxRS/project/plugins.sbt new file mode 100644 index 00000000000..713b7f3e993 --- /dev/null +++ b/src/main/resources/JavaJaxRS/project/plugins.sbt @@ -0,0 +1,9 @@ +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.4") + +libraryDependencies <+= sbtVersion(v => v match { + case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8" + case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10" + case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11" + case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1" + case x if (x.startsWith("0.12")) => "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1" +}) \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/queryParams.mustache b/src/main/resources/JavaJaxRS/queryParams.mustache new file mode 100644 index 00000000000..7724ba420a8 --- /dev/null +++ b/src/main/resources/JavaJaxRS/queryParams.mustache @@ -0,0 +1 @@ +{{#queryParams}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{newline}}{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{newline}}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{newline}}{{/defaultValue}})@QueryParam("{{paramName}}"){{newline}} {{{dataType}}} {{paramName}}{{/queryParams}} \ No newline at end of file diff --git a/src/main/resources/JavaJaxRS/web.mustache b/src/main/resources/JavaJaxRS/web.mustache new file mode 100644 index 00000000000..b9cd00b71ce --- /dev/null +++ b/src/main/resources/JavaJaxRS/web.mustache @@ -0,0 +1,54 @@ + + + + + jersey + com.sun.jersey.spi.container.servlet.ServletContainer + + com.sun.jersey.config.property.packages + com.wordnik.swagger.jaxrs.json;com.wordnik.swagger.jaxrs.listing;{{apiPackage}} + + + com.sun.jersey.spi.container.ContainerRequestFilters + com.sun.jersey.api.container.filter.PostReplaceFilter + + + com.sun.jersey.api.json.POJOMappingFeature + true + + 1 + + + + DefaultJaxrsConfig + com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig + + api.version + 1.0.0 + + + swagger.api.title + {{{title}}} + + + swagger.api.basepath + http://localhost:8002 + + 2 + + + + jersey + /* + + + ApiOriginFilter + com.wordnik.api.ApiOriginFilter + + + ApiOriginFilter + /* + +