From 20c8f9a8316fffed3744b36143d1b3c9aaf26d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20C=C3=B4t=C3=A9?= Date: Fri, 10 Mar 2017 09:10:49 -0500 Subject: [PATCH] Java Play Framework Server Generator (#4943) * First commit of the Java Play Framework server generator. It is highly based on Spring so there might me a couple of things that don't make sense (like options or parameters) for the Play Framework. * Fix suggestions in the PR discussion + add .bat and .sh file as requested. * Updated Readme.md file * Remove unused mustache file + fix baseName vs paramName in all the mustache files. * Fix the compilation error when we have a body which is a list or map. Doesn't fix the problem with the annotation itself. * Fix the problem with the Http.MultipartFormData.FilePart --- README.md | 3 + bin/java-play-framework-petstore-server.sh | 31 ++ .../java-play-framework-petstore-server.bat | 10 + .../io/swagger/codegen/CodegenParameter.java | 4 + .../languages/JavaPlayFrameworkCodegen.java | 248 ++++++++++++ .../JavaPlayFramework/LICENSE.mustache | 8 + .../JavaPlayFramework/README.mustache | 4 + .../apiDocController.mustache | 15 + .../JavaPlayFramework/application.mustache | 361 ++++++++++++++++++ .../JavaPlayFramework/beanValidation.mustache | 53 +++ .../beanValidationPathParams.mustache | 1 + .../beanValidationQueryParams.mustache | 1 + .../bodyParamsNoDoc.mustache | 1 + .../JavaPlayFramework/build.mustache | 17 + .../buildproperties.mustache | 1 + .../conversionBegin.mustache | 1 + .../JavaPlayFramework/conversionEnd.mustache | 1 + .../JavaPlayFramework/enumClass.mustache | 44 +++ .../JavaPlayFramework/enumOuterClass.mustache | 42 ++ .../formParamsNoDoc.mustache | 1 + .../generatedAnnotation.mustache | 3 + .../headerParamsNoDoc.mustache | 1 + .../JavaPlayFramework/logback.mustache | 41 ++ .../JavaPlayFramework/model.mustache | 22 ++ .../JavaPlayFramework/newApi.mustache | 24 ++ .../newApiController.mustache | 162 ++++++++ .../notFoundException.mustache | 10 + .../paramDefaultValue.mustache | 1 + .../JavaPlayFramework/paramType.mustache | 1 + .../JavaPlayFramework/pathParams.mustache | 1 + .../pathParamsNoDoc.mustache | 1 + .../JavaPlayFramework/plugins.mustache | 2 + .../resources/JavaPlayFramework/pojo.mustache | 118 ++++++ .../project/build.properties | 1 + .../JavaPlayFramework/project/plugins.sbt | 9 + .../queryParamsNoDoc.mustache | 1 + .../JavaPlayFramework/returnTypes.mustache | 1 + .../returnTypesNoVoid.mustache | 1 + .../returnTypesNoVoidNoAbstract.mustache | 1 + .../JavaPlayFramework/routes.mustache | 27 ++ .../JavaPlayFramework/swaggerUtils.mustache | 108 ++++++ .../typeInfoAnnotation.mustache | 7 + .../services/io.swagger.codegen.CodegenConfig | 1 + .../JavaPlayFrameworkOptionsTest.java | 68 ++++ .../JavaPlayFrameworkOptionsProvider.java | 42 ++ 45 files changed, 1501 insertions(+) create mode 100644 bin/java-play-framework-petstore-server.sh create mode 100644 bin/windows/java-play-framework-petstore-server.bat create mode 100644 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/LICENSE.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/README.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidation.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParamsNoDoc.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/buildproperties.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionEnd.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumClass.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumOuterClass.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParamsNoDoc.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/generatedAnnotation.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParamsNoDoc.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/logback.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/model.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/notFoundException.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramType.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParamsNoDoc.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/plugins.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/build.properties create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/plugins.sbt create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParamsNoDoc.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypes.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoid.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoidNoAbstract.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache create mode 100644 modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java create mode 100644 modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java diff --git a/README.md b/README.md index 7aad69a2981f..8e99b9cd7b20 100644 --- a/README.md +++ b/README.md @@ -909,6 +909,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you - [snapCX](https://snapcx.io) - [SPINEN](http://www.spinen.com) - [SRC](https://www.src.si/) +- [Stingray](http://www.stingray.com) - [StyleRecipe](http://stylerecipe.co.jp) - [Svenska Spel AB](https://www.svenskaspel.se/) - [TaskData](http://www.taskdata.com/) @@ -961,6 +962,7 @@ Swagger Codegen core team members are contributors who have been making signific | Java Spring Boot | @cbornet (2016/07/19) | | Java Spring MVC | @kolyjjj (2016/05/01) @cbornet (2016/07/19) | | Java JAX-RS | | +| Java Play Framework | | | NancyFX | | | NodeJS | @kolyjjj (2016/05/01) | | PHP Lumen | @abcsum (2016/05/01) | @@ -1008,6 +1010,7 @@ Here is a list of template creators: * Java MSF4J: @sanjeewa-malalgoda * Java Spring Boot: @diyfr * Java Undertow: @stevehu + * Java Play Framework: @JFCote * JAX-RS RestEasy: @chameleon82 * JAX-RS CXF: @hiveship * JAX-RS CXF (CDI): @nickcmaynard diff --git a/bin/java-play-framework-petstore-server.sh b/bin/java-play-framework-petstore-server.sh new file mode 100644 index 000000000000..ff8103e22046 --- /dev/null +++ b/bin/java-play-framework-petstore-server.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaPlayFramework -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l java-play-framework -o samples/server/petstore/java-play-framework -DhideGenerationTimestamp=true" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/java-play-framework-petstore-server.bat b/bin/windows/java-play-framework-petstore-server.bat new file mode 100644 index 000000000000..b2d2604f59c4 --- /dev/null +++ b/bin/windows/java-play-framework-petstore-server.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l java-play-framework -o samples\server\petstore\java-play-framework + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java index e30159f95538..db0464ba7bd8 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java @@ -11,6 +11,10 @@ public class CodegenParameter { secondaryParam, isCollectionFormatMulti, isPrimitiveType; public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName; + + //This was added for javaPlayFramework specifically to get around a bug in swagger-play. See generator for more info on the bug. + public String dataTypeForImplicitParam; + public String example; // example value (x-example) public String jsonSchema; public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java new file mode 100644 index 000000000000..ef87ed93b05f --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java @@ -0,0 +1,248 @@ +package io.swagger.codegen.languages; + +import io.swagger.codegen.*; +import io.swagger.codegen.languages.features.BeanValidationFeatures; + +import java.io.File; +import java.util.List; +import java.util.Map; + +public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements BeanValidationFeatures { + + public static final String TITLE = "title"; + public static final String CONFIG_PACKAGE = "configPackage"; + public static final String BASE_PACKAGE = "basePackage"; + public static final String CONTROLLER_ONLY = "controllerOnly"; + public static final String SINGLE_CONTENT_TYPES = "singleContentTypes"; + public static final String RESPONSE_WRAPPER = "responseWrapper"; + public static final String USE_TAGS = "useTags"; + + protected String title = "swagger-petstore"; + protected String configPackage = "io.swagger.configuration"; + protected String basePackage = "io.swagger"; + protected boolean controllerOnly = false; + protected boolean singleContentTypes = false; + protected String responseWrapper = ""; + protected boolean useTags = false; + protected boolean useBeanValidation = true; + + public JavaPlayFrameworkCodegen() { + super(); + outputFolder = "generated-code/javaPlayFramework"; + apiTestTemplateFiles.clear(); + embeddedTemplateDir = templateDir = "JavaPlayFramework"; + apiPackage = "controllers"; + modelPackage = "apimodels"; + invokerPackage = "io.swagger.api"; + artifactId = "swagger-java-playframework"; + + projectFolder = ""; + sourceFolder = projectFolder + File.separator + "app"; + projectTestFolder = projectFolder + File.separator + "test"; + testFolder = projectTestFolder; + + additionalProperties.put(CONFIG_PACKAGE, configPackage); + additionalProperties.put(BASE_PACKAGE, basePackage); + + additionalProperties.put("jackson", "true"); + + cliOptions.add(new CliOption(TITLE, "server title name or client service name")); + cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code")); + cliOptions.add(new CliOption(BASE_PACKAGE, "base package for generated code")); + cliOptions.add(CliOption.newBoolean(CONTROLLER_ONLY, "Whether to generate only API interface stubs without the server files.")); + cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.")); + cliOptions.add(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)")); + cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames")); + cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations")); + } + + @Override + public CodegenType getTag() { + return CodegenType.SERVER; + } + + @Override + public String getName() { + return "java-play-framework"; + } + + @Override + public String getHelp() { + return "Generates a Java Play Framework Server application."; + } + + @Override + public void processOpts() { + super.processOpts(); + + // clear model and api doc template as this codegen + // does not support auto-generated markdown doc at the moment + //TODO: add doc templates + modelDocTemplateFiles.remove("model_doc.mustache"); + apiDocTemplateFiles.remove("api_doc.mustache"); + + if (additionalProperties.containsKey(TITLE)) { + this.setTitle((String) additionalProperties.get(TITLE)); + } + + if (additionalProperties.containsKey(CONFIG_PACKAGE)) { + this.setConfigPackage((String) additionalProperties.get(CONFIG_PACKAGE)); + } + + if (additionalProperties.containsKey(BASE_PACKAGE)) { + this.setBasePackage((String) additionalProperties.get(BASE_PACKAGE)); + } + + if (additionalProperties.containsKey(CONTROLLER_ONLY)) { + this.setControllerOnly(Boolean.valueOf(additionalProperties.get(CONTROLLER_ONLY).toString())); + } + + if (additionalProperties.containsKey(SINGLE_CONTENT_TYPES)) { + this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString())); + } + + if (additionalProperties.containsKey(RESPONSE_WRAPPER)) { + this.setResponseWrapper((String) additionalProperties.get(RESPONSE_WRAPPER)); + } + + if (additionalProperties.containsKey(USE_TAGS)) { + this.setUseTags(Boolean.valueOf(additionalProperties.get(USE_TAGS).toString())); + } + + if (additionalProperties.containsKey(USE_BEANVALIDATION)) { + this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); + } + + if (useBeanValidation) { + writePropertyBack(USE_BEANVALIDATION, useBeanValidation); + } + + //Root folder + supportingFiles.add(new SupportingFile("README.mustache", "", "README")); + supportingFiles.add(new SupportingFile("LICENSE.mustache", "", "LICENSE")); + supportingFiles.add(new SupportingFile("build.mustache", "", "build.sbt")); + + //Project folder + supportingFiles.add(new SupportingFile("buildproperties.mustache", "project", "build.properties")); + supportingFiles.add(new SupportingFile("plugins.mustache", "project", "plugins.sbt")); + + //Conf folder + supportingFiles.add(new SupportingFile("logback.mustache", "conf", "logback.xml")); + supportingFiles.add(new SupportingFile("application.mustache", "conf", "application.conf")); + supportingFiles.add(new SupportingFile("routes.mustache", "conf", "routes")); + + //App/Utils folder + supportingFiles.add(new SupportingFile("swaggerUtils.mustache", "app/swagger", "SwaggerUtils.java")); + + //App/Controllers + supportingFiles.add(new SupportingFile("apiDocController.mustache", "app/controllers", "ApiDocController.java")); + + //We remove the default api.mustache that is used + apiTemplateFiles.remove("api.mustache"); + apiTemplateFiles.put("newApiController.mustache", "Controller.java"); + if (!this.controllerOnly) { + apiTemplateFiles.put("newApi.mustache", "ControllerImp.java"); + } + + additionalProperties.put("javaVersion", "1.8"); + additionalProperties.put("jdk8", "true"); + typeMapping.put("date", "LocalDate"); + typeMapping.put("DateTime", "OffsetDateTime"); + importMapping.put("LocalDate", "java.time.LocalDate"); + importMapping.put("OffsetDateTime", "java.time.OffsetDateTime"); + + // Some well-known Spring or Spring-Cloud response wrappers + switch (this.responseWrapper) { + case "Future": + case "Callable": + case "CompletableFuture": + additionalProperties.put(RESPONSE_WRAPPER, "java.util.concurrent" + this.responseWrapper); + break; + default: + break; + } + } + + public void setTitle(String title) { + this.title = title; + } + + public void setConfigPackage(String configPackage) { + this.configPackage = configPackage; + } + + public void setBasePackage(String configPackage) { + this.basePackage = configPackage; + } + + public void setControllerOnly(boolean controllerOnly) { this.controllerOnly = controllerOnly; } + + public void setSingleContentTypes(boolean singleContentTypes) { + this.singleContentTypes = singleContentTypes; + } + + public void setResponseWrapper(String responseWrapper) { this.responseWrapper = responseWrapper; } + + public void setUseTags(boolean useTags) { + this.useTags = useTags; + } + + @Override + public Map postProcessOperations(Map objs) { + Map operations = (Map) objs.get("operations"); + if (operations != null) { + List ops = (List) operations.get("operation"); + for (CodegenOperation operation : ops) { + + //This is to fix this bug in the swagger-play project: https://github.com/swagger-api/swagger-play/issues/131 + //We need to explicitly add the model package name in front of the dataType because if we don't, the + //implicitParam is not valid and show error when loading the documentation + //This can be removed safely after the bug has been fixed + for (CodegenParameter param : operation.allParams) { + if (!param.isPathParam ) { + if (!param.isPrimitiveType && !param.isListContainer && !param.isMapContainer) { + param.dataTypeForImplicitParam = String.format("%s.%s", modelPackage, param.dataType); + } else { + param.dataTypeForImplicitParam = param.dataType; + } + } + } + + if (operation.path.contains("{")) { + operation.path = operation.path.replace("{", ":").replace("}", ""); + } + + if (operation.returnType != null) { + if (operation.returnType.startsWith("List")) { + String rt = operation.returnType; + int end = rt.lastIndexOf(">"); + if (end > 0) { + operation.returnType = rt.substring("List<".length(), end).trim(); + 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).split(",")[1].trim(); + 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).trim(); + operation.returnContainer = "Set"; + } + } + } + } + } + + return objs; + } + + public void setUseBeanValidation(boolean useBeanValidation) { + this.useBeanValidation = useBeanValidation; + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/LICENSE.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/LICENSE.mustache new file mode 100644 index 000000000000..4baedcb95f3d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/LICENSE.mustache @@ -0,0 +1,8 @@ +This software is licensed under the Apache 2 license, quoted below. + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with +the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific +language governing permissions and limitations under the License. \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/README.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/README.mustache new file mode 100644 index 000000000000..2fce02950d27 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/README.mustache @@ -0,0 +1,4 @@ +This is your new Play application +================================= + +This file will be packaged with your application when using `activator dist`. \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache new file mode 100644 index 000000000000..60534355ae3a --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache @@ -0,0 +1,15 @@ +package controllers; + +import javax.inject.*; +import play.mvc.*; + +public class ApiDocController extends Controller { + + @Inject + private ApiDocController() { + } + + public Result api() { + return redirect(String.format("/assets/lib/swagger-ui/index.html?/url=%s/api-docs", "")); + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache new file mode 100644 index 000000000000..d6d9e9fa92bf --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache @@ -0,0 +1,361 @@ +springfox.documentation.swagger.v2.path=/api-docs +server.contextPath={{^useAnnotatedBasePath}}/{{/useAnnotatedBasePath}}{{#useAnnotatedBasePath}}{{contextPath}}{{/useAnnotatedBasePath}} +server.port={{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}9000{{/serverPort}} +spring.jackson.date-format={{basePackage}}.RFC3339DateFormat +spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false + +# This is the main configuration file for the application. +# https://www.playframework.com/documentation/latest/ConfigFile +# ~~~~~ +# Play uses HOCON as its configuration file format. HOCON has a number +# of advantages over other config formats, but there are two things that +# can be used when modifying settings. +# +# You can include other configuration files in this main application.conf file: +#include "extra-config.conf" +# +# You can declare variables and substitute for them: +#mykey = ${some.value} +# +# And if an environment variable exists when there is no other subsitution, then +# HOCON will fall back to substituting environment variable: +#mykey = ${JAVA_HOME} + +## Akka +# https://www.playframework.com/documentation/latest/ScalaAkka#Configuration +# https://www.playframework.com/documentation/latest/JavaAkka#Configuration +# ~~~~~ +# Play uses Akka internally and exposes Akka Streams and actors in Websockets and +# other streaming HTTP responses. +akka { +# "akka.log-config-on-start" is extraordinarly useful because it log the complete +# configuration at INFO level, including defaults and overrides, so it s worth +# putting at the very top. +# +# Put the following in your conf/logback.xml file: +# +# +# +# And then uncomment this line to debug the configuration. +# +#log-config-on-start = true +} + +api.version="1.0" + +## Secret key +# http://www.playframework.com/documentation/latest/ApplicationSecret +# ~~~~~ +# The secret key is used to sign Play's session cookie. +# This must be changed for production, but we don't recommend you change it in this file. +play.crypto.secret = "changeme" + +## Modules +# https://www.playframework.com/documentation/latest/Modules +# ~~~~~ +# Control which modules are loaded when Play starts. Note that modules are +# the replacement for "GlobalSettings", which are deprecated in 2.5.x. +# Please see https://www.playframework.com/documentation/latest/GlobalSettings +# for more information. +# +# You can also extend Play functionality by using one of the publically available +# Play modules: https://playframework.com/documentation/latest/ModuleDirectory +play.modules { +# By default, Play will load any class called Module that is defined +# in the root package (the "app" directory), or you can define them +# explicitly below. +# If there are any built-in modules that you want to disable, you can list them here. +enabled += "play.modules.swagger.SwaggerModule" + +# If there are any built-in modules that you want to disable, you can list them here. +#disabled += "" +} + +## IDE +# https://www.playframework.com/documentation/latest/IDE +# ~~~~~ +# Depending on your IDE, you can add a hyperlink for errors that will jump you +# directly to the code location in the IDE in dev mode. The following line makes +# use of the IntelliJ IDEA REST interface: +#play.editor="http://localhost:63342/api/file/?file=%s&line=%s" + +## Internationalisation +# https://www.playframework.com/documentation/latest/JavaI18N +# https://www.playframework.com/documentation/latest/ScalaI18N +# ~~~~~ +# Play comes with its own i18n settings, which allow the user's preferred language +# to map through to internal messages, or allow the language to be stored in a cookie. +play.i18n { +# The application languages +langs = [ "en" ] + +# Whether the language cookie should be secure or not +#langCookieSecure = true + +# Whether the HTTP only attribute of the cookie should be set to true +#langCookieHttpOnly = true +} + +## Play HTTP settings +# ~~~~~ +play.http { +## Router +# https://www.playframework.com/documentation/latest/JavaRouting +# https://www.playframework.com/documentation/latest/ScalaRouting +# ~~~~~ +# Define the Router object to use for this application. +# This router will be looked up first when the application is starting up, +# so make sure this is the entry point. +# Furthermore, it's assumed your route file is named properly. +# So for an application router like `my.application.Router`, +# you may need to define a router file `conf/my.application.routes`. +# Default to Routes in the root package (aka "apps" folder) (and conf/routes) +#router = my.application.Router + +## Action Creator +# https://www.playframework.com/documentation/latest/JavaActionCreator +# ~~~~~ +#actionCreator = null + +## ErrorHandler +# https://www.playframework.com/documentation/latest/JavaRouting +# https://www.playframework.com/documentation/latest/ScalaRouting +# ~~~~~ +# If null, will attempt to load a class called ErrorHandler in the root package, +#errorHandler = null + +## Filters +# https://www.playframework.com/documentation/latest/ScalaHttpFilters +# https://www.playframework.com/documentation/latest/JavaHttpFilters +# ~~~~~ +# Filters run code on every request. They can be used to perform +# common logic for all your actions, e.g. adding common headers. +# Defaults to "Filters" in the root package (aka "apps" folder) +# Alternatively you can explicitly register a class here. +#filters = my.application.Filters + +## Session & Flash +# https://www.playframework.com/documentation/latest/JavaSessionFlash +# https://www.playframework.com/documentation/latest/ScalaSessionFlash +# ~~~~~ +session { +# Sets the cookie to be sent only over HTTPS. +#secure = true + +# Sets the cookie to be accessed only by the server. +#httpOnly = true + +# Sets the max-age field of the cookie to 5 minutes. +# NOTE: this only sets when the browser will discard the cookie. Play will consider any +# cookie value with a valid signature to be a valid session forever. To implement a server side session timeout, +# you need to put a timestamp in the session and check it at regular intervals to possibly expire it. +#maxAge = 300 + +# Sets the domain on the session cookie. +#domain = "example.com" +} + +flash { +# Sets the cookie to be sent only over HTTPS. +#secure = true + +# Sets the cookie to be accessed only by the server. +#httpOnly = true +} +} + +## Netty Provider +# https://www.playframework.com/documentation/latest/SettingsNetty +# ~~~~~ +play.server.netty { +# Whether the Netty wire should be logged +#log.wire = true + +# If you run Play on Linux, you can use Netty's native socket transport +# for higher performance with less garbage. +#transport = "native" +} + +## WS (HTTP Client) +# https://www.playframework.com/documentation/latest/ScalaWS#Configuring-WS +# ~~~~~ +# The HTTP client primarily used for REST APIs. The default client can be +# configured directly, but you can also create different client instances +# with customized settings. You must enable this by adding to build.sbt: +# +# libraryDependencies += ws // or javaWs if using java +# +play.ws { +# Sets HTTP requests not to follow 302 requests +#followRedirects = false + +# Sets the maximum number of open HTTP connections for the client. +#ahc.maxConnectionsTotal = 50 + +## WS SSL +# https://www.playframework.com/documentation/latest/WsSSL +# ~~~~~ +ssl { +# Configuring HTTPS with Play WS does not require programming. You can +# set up both trustManager and keyManager for mutual authentication, and +# turn on JSSE debugging in development with a reload. +#debug.handshake = true +#trustManager = { +# stores = [ +# { type = "JKS", path = "exampletrust.jks" } +# ] +#} +} +} + +## Cache +# https://www.playframework.com/documentation/latest/JavaCache +# https://www.playframework.com/documentation/latest/ScalaCache +# ~~~~~ +# Play comes with an integrated cache API that can reduce the operational +# overhead of repeated requests. You must enable this by adding to build.sbt: +# +# libraryDependencies += cache +# +play.cache { +# If you want to bind several caches, you can bind the individually +#bindCaches = ["db-cache", "user-cache", "session-cache"] +} + +## Filters +# https://www.playframework.com/documentation/latest/Filters +# ~~~~~ +# There are a number of built-in filters that can be enabled and configured +# to give Play greater security. You must enable this by adding to build.sbt: +# +# libraryDependencies += filters +# +play.filters { +## CORS filter configuration +# https://www.playframework.com/documentation/latest/CorsFilter +# ~~~~~ +# CORS is a protocol that allows web applications to make requests from the browser +# across different domains. +# NOTE: You MUST apply the CORS configuration before the CSRF filter, as CSRF has +# dependencies on CORS settings. +cors { +# Filter paths by a whitelist of path prefixes +#pathPrefixes = ["/some/path", ...] + +# The allowed origins. If null, all origins are allowed. +#allowedOrigins = ["http://www.example.com"] + +# The allowed HTTP methods. If null, all methods are allowed +#allowedHttpMethods = ["GET", "POST"] +} + +## CSRF Filter +# https://www.playframework.com/documentation/latest/ScalaCsrf#Applying-a-global-CSRF-filter +# https://www.playframework.com/documentation/latest/JavaCsrf#Applying-a-global-CSRF-filter +# ~~~~~ +# Play supports multiple methods for verifying that a request is not a CSRF request. +# The primary mechanism is a CSRF token. This token gets placed either in the query string +# or body of every form submitted, and also gets placed in the users session. +# Play then verifies that both tokens are present and match. +csrf { +# Sets the cookie to be sent only over HTTPS +#cookie.secure = true + +# Defaults to CSRFErrorHandler in the root package. +#errorHandler = MyCSRFErrorHandler +} + +## Security headers filter configuration +# https://www.playframework.com/documentation/latest/SecurityHeaders +# ~~~~~ +# Defines security headers that prevent XSS attacks. +# If enabled, then all options are set to the below configuration by default: +headers { +# The X-Frame-Options header. If null, the header is not set. +#frameOptions = "DENY" + +# The X-XSS-Protection header. If null, the header is not set. +#xssProtection = "1; mode=block" + +# The X-Content-Type-Options header. If null, the header is not set. +#contentTypeOptions = "nosniff" + +# The X-Permitted-Cross-Domain-Policies header. If null, the header is not set. +#permittedCrossDomainPolicies = "master-only" + +# The Content-Security-Policy header. If null, the header is not set. +#contentSecurityPolicy = "default-src 'self'" +} + +## Allowed hosts filter configuration +# https://www.playframework.com/documentation/latest/AllowedHostsFilter +# ~~~~~ +# Play provides a filter that lets you configure which hosts can access your application. +# This is useful to prevent cache poisoning attacks. +hosts { +# Allow requests to example.com, its subdomains, and localhost:9000. +#allowed = [".example.com", "localhost:9000"] +} +} + +## Evolutions +# https://www.playframework.com/documentation/latest/Evolutions +# ~~~~~ +# Evolutions allows database scripts to be automatically run on startup in dev mode +# for database migrations. You must enable this by adding to build.sbt: +# +# libraryDependencies += evolutions +# +play.evolutions { +# You can disable evolutions for a specific datasource if necessary +#db.default.enabled = false +} + +## Database Connection Pool +# https://www.playframework.com/documentation/latest/SettingsJDBC +# ~~~~~ +# Play doesn't require a JDBC database to run, but you can easily enable one. +# +# libraryDependencies += jdbc +# +play.db { +# The combination of these two settings results in "db.default" as the +# default JDBC pool: +#config = "db" +#default = "default" + +# Play uses HikariCP as the default connection pool. You can override +# settings by changing the prototype: +prototype { +# Sets a fixed JDBC connection pool size of 50 +#hikaricp.minimumIdle = 50 +#hikaricp.maximumPoolSize = 50 +} +} + +## JDBC Datasource +# https://www.playframework.com/documentation/latest/JavaDatabase +# https://www.playframework.com/documentation/latest/ScalaDatabase +# ~~~~~ +# Once JDBC datasource is set up, you can work with several different +# database options: +# +# Slick (Scala preferred option): https://www.playframework.com/documentation/latest/PlaySlick +# JPA (Java preferred option): https://playframework.com/documentation/latest/JavaJPA +# EBean: https://playframework.com/documentation/latest/JavaEbean +# Anorm: https://www.playframework.com/documentation/latest/ScalaAnorm +# +db { +# You can declare as many datasources as you want. +# By convention, the default datasource is named `default` + +# https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database +#default.driver = org.h2.Driver +#default.url = "jdbc:h2:mem:play" +#default.username = sa +#default.password = "" + +# You can turn on SQL logging for any datasource +# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements +#default.logSql=true +} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidation.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidation.mustache new file mode 100644 index 000000000000..079eab89d1af --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidation.mustache @@ -0,0 +1,53 @@ +{{#required}} + @NotNull +{{/required}} +{{#pattern}} + @Pattern(regexp="{{pattern}}") +{{/pattern}} +{{#minLength}} +{{#maxLength}} + @Size(min={{minLength}},max={{maxLength}}) +{{/maxLength}} +{{/minLength}} +{{#minLength}} +{{^maxLength}} + @Size(min={{minLength}}) +{{/maxLength}} +{{/minLength}} +{{^minLength}} +{{#maxLength}} + @Size(max={{maxLength}}) + {{/maxLength}} + {{/minLength}} +{{#minItems}} +{{#maxItems}} + @Size(min={{minItems}},max={{maxItems}}) +{{/maxItems}} +{{/minItems}} +{{#minItems}} +{{^maxItems}} + @Size(min={{minItems}}) +{{/maxItems}} +{{/minItems}} +{{^minItems}} +{{#maxItems}} + @Size(max={{maxItems}}) +{{/maxItems}} +{{/minItems}} +{{! check for integer / number=decimal type}} +{{#isInteger}} +{{#minimum}} + @Min({{minimum}}) +{{/minimum}} +{{#maximum}} + @Max({{maximum}}) +{{/maximum}} +{{/isInteger}} +{{^isInteger}} +{{#minimum}} + @DecimalMin("{{minimum}}") +{{/minimum}} +{{#maximum}} + @DecimalMax("{{maximum}}") +{{/maximum}} +{{/isInteger}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache new file mode 100644 index 000000000000..e3060fa6c6ac --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache @@ -0,0 +1 @@ +{{! PathParam is always required, no @NotNull necessary }}{{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache new file mode 100644 index 000000000000..52440b122185 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParamsNoDoc.mustache new file mode 100644 index 000000000000..c7d1abfe527e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParamsNoDoc.mustache @@ -0,0 +1 @@ +{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache new file mode 100644 index 000000000000..3c7ba4b08eaf --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache @@ -0,0 +1,17 @@ +name := """{{artifactId}}""" + +version := "1.0-SNAPSHOT" + +lazy val root = (project in file(".")).enablePlugins(PlayJava) + +scalaVersion := "2.11.7" + +libraryDependencies ++= Seq( +javaJdbc, +cache, +javaWs, +"io.swagger" %% "swagger-play2" % "1.5.3", +"org.webjars" % "swagger-ui" % "2.2.8"{{#useBeanValidation}}, +"javax.validation" % "validation-api" % "1.1.0.Final" +{{/useBeanValidation}} +) diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/buildproperties.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/buildproperties.mustache new file mode 100644 index 000000000000..59e7c05b62f2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/buildproperties.mustache @@ -0,0 +1 @@ +sbt.version=0.13.11 \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache new file mode 100644 index 000000000000..21631412a2b1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache @@ -0,0 +1 @@ +{{#isInteger}}Integer.parseInt({{/isInteger}}{{#isDouble}}Double.parseDouble({{/isDouble}}{{#isLong}}Long.parseLong({{/isLong}}{{#isFloat}}Float.parseFloat({{/isFloat}}{{#isString}}(String){{/isString}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionEnd.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionEnd.mustache new file mode 100644 index 000000000000..2a36cdff8aba --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionEnd.mustache @@ -0,0 +1 @@ +{{#isInteger}}){{/isInteger}}{{#isDouble}}){{/isDouble}}{{#isLong}}){{/isLong}}{{#isFloat}}){{/isFloat}}{{#isString}}{{/isString}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumClass.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumClass.mustache new file mode 100644 index 000000000000..c5c3143cb94f --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumClass.mustache @@ -0,0 +1,44 @@ + /** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} + */ + public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { + {{#gson}} + {{#allowableValues}} + {{#enumVars}} + @SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) + {{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}} + {{/enumVars}} + {{/allowableValues}} + {{/gson}} + {{^gson}} + {{#allowableValues}} + {{#enumVars}} + {{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}} + {{/enumVars}} + {{/allowableValues}} + {{/gson}} + + private {{{datatype}}} value; + + {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{datatype}}} value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) { + for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } + } diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumOuterClass.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumOuterClass.mustache new file mode 100644 index 000000000000..76c2cbf5a76d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/enumOuterClass.mustache @@ -0,0 +1,42 @@ +{{#jackson}} +import com.fasterxml.jackson.annotation.JsonCreator; +{{/jackson}} + +/** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} + */ +public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { + {{#gson}} + {{#allowableValues}}{{#enumVars}} + @SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) + {{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} + {{/gson}} + {{^gson}} + {{#allowableValues}}{{#enumVars}} + {{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} + {{/gson}} + + private {{{dataType}}} value; + + {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) { + for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParamsNoDoc.mustache new file mode 100644 index 000000000000..866a5e96df52 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParamsNoDoc.mustache @@ -0,0 +1 @@ +{{#isFormParam}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}Http.MultipartFormData.FilePart {{paramName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/generatedAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/generatedAnnotation.mustache new file mode 100644 index 000000000000..ad17a426e969 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/generatedAnnotation.mustache @@ -0,0 +1,3 @@ +{{^hideGenerationTimestamp}} +@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}") +{{/hideGenerationTimestamp}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParamsNoDoc.mustache new file mode 100644 index 000000000000..bd03573d196e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParamsNoDoc.mustache @@ -0,0 +1 @@ +{{#isHeaderParam}}{{{dataType}}} {{paramName}}{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/logback.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/logback.mustache new file mode 100644 index 000000000000..01f301ab73a9 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/logback.mustache @@ -0,0 +1,41 @@ + + + + + + + ${application.home:-.}/logs/application.log + + %date [%level] from %logger in %thread - %message%n%xException + + + + + + %coloredLevel %logger{15} - %message%n%xException{10} + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/model.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/model.mustache new file mode 100644 index 000000000000..4b37d4c35d7d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/model.mustache @@ -0,0 +1,22 @@ +package {{package}}; + +import java.util.Objects; +{{#imports}}import {{import}}; +{{/imports}} +{{#serializableModel}} +import java.io.Serializable; +{{/serializableModel}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +import com.fasterxml.jackson.annotation.*; +{{/useBeanValidation}} +{{#models}} +{{#model}} +{{#isEnum}} +{{>enumOuterClass}} +{{/isEnum}} +{{^isEnum}} +{{>pojo}} +{{/isEnum}} +{{/model}} +{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache new file mode 100644 index 000000000000..e19bbf893cb1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache @@ -0,0 +1,24 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} + +import play.mvc.Http; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}}ControllerImp { +{{#operation}} + {{>returnTypes}} {{operationId}}({{#allParams}}{{>pathParamsNoDoc}}{{>queryParamsNoDoc}}{{>bodyParamsNoDoc}}{{>formParamsNoDoc}}{{>headerParamsNoDoc}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { + //Do your magic!!! + {{#returnType}}return new {{>returnTypesNoVoidNoAbstract}}();{{/returnType}} + } + +{{/operation}} +} +{{/operations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache new file mode 100644 index 000000000000..bd76a507cae8 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache @@ -0,0 +1,162 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} + +import io.swagger.annotations.*; +import play.mvc.Controller; +import play.mvc.Result; +import play.mvc.Http; +import java.util.List; +import java.util.ArrayList; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.JsonNode; +import com.google.inject.Inject; +import java.io.IOException; +import swagger.SwaggerUtils; +import javafx.util.Pair; +import com.fasterxml.jackson.core.type.TypeReference; + +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} + +{{>generatedAnnotation}} +@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API") +{{#operations}} +public class {{classname}}Controller extends Controller { + + private {{classname}}ControllerImp imp; + private ObjectMapper mapper; + + @Inject + private {{classname}}Controller({{classname}}ControllerImp imp) { + this.imp = imp; + mapper = new ObjectMapper(); + } + +{{#operation}} + + @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}"{{#returnType}}, response = {{{returnType}}}.class{{/returnType}}{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/isOAuth}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#returnType}}, response = {{{returnType}}}.class{{/returnType}}){{#hasMore}}, {{/hasMore}}{{/responses}} }) + {{#hasParams}} + @ApiImplicitParams({ + {{#allParams}}{{^isPathParam}}@ApiImplicitParam(name = "{{baseName}}", value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#defaultValue}}, defaultValue = "{{{defaultValue}}}"{{/defaultValue}}, dataType = "{{{dataTypeForImplicitParam}}}", paramType = "{{>paramType}}"){{#hasMore}}, + {{/hasMore}}{{/isPathParam}}{{/allParams}} + }) + {{/hasParams}} + public Result {{operationId}}({{#pathParams}}{{>pathParams}}{{#hasMore}},{{/hasMore}}{{/pathParams}}) {{#bodyParams}}throws IOException{{/bodyParams}} { + {{#bodyParams}} + {{#collectionFormat}} + //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 + //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? + {{/collectionFormat}} + {{^collectionFormat}} + JsonNode node{{paramName}} = request().body().asJson(); + {{{dataType}}} {{paramName}}; + {{^required}} + if (node{{paramName}} != null) { + {{paramName}} = mapper.readValue(node{{paramName}}.toString(), {{#isMapContainer}}new TypeReference>(){}{{/isMapContainer}}{{#isListContainer}}new TypeReference>(){}{{/isListContainer}}{{^isListContainer}}{{^isMapContainer}}{{{dataType}}}.class{{/isMapContainer}}{{/isListContainer}});{{/required}} + {{#required}}{{paramName}} = mapper.readValue(node{{paramName}}.toString(), {{{dataType}}}.class);{{/required}} + {{^required}} + } else { + {{paramName}} = null; + }{{/required}} + {{/collectionFormat}} + {{/bodyParams}} + {{#queryParams}} + {{#collectionFormat}} + //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 + //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? + //WIP when both bugs will be fixed + //List {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getQueryString("{{baseName}}")); + {{{dataType}}} {{paramName}} = new Array{{{dataType}}}(); + //for (Pair pair : {{paramName}}Pair) { + // {{paramName}}.add({{>conversionBegin}}pair.getValue(){{>conversionEnd}}); + //} + {{/collectionFormat}} + {{^collectionFormat}} + String value{{paramName}} = request().getQueryString("{{paramName}}"); + {{{dataType}}} {{paramName}}; + {{^required}} + if (value{{paramName}} != null) { + {{paramName}} = {{>conversionBegin}}value{{paramName}}{{>conversionEnd}};{{/required}} + {{#required}}{{paramName}} = {{>conversionBegin}}value{{paramName}}{{>conversionEnd}};{{/required}} + {{^required}} + } else { + {{paramName}} = {{>paramDefaultValue}}; + }{{/required}} + {{/collectionFormat}} + {{/queryParams}} + {{#formParams}} + {{^notFile}} + Http.MultipartFormData.FilePart {{paramName}} = request().body().asMultipartFormData().getFile("{{baseName}}"); + {{#required}}if (({{paramName}} == null || ((File) {{paramName}}.getFile()).length() == 0)) { + throw new RuntimeException("File cannot be empty"); + } + {{/required}} + {{/notFile}} + {{#notFile}} + {{#collectionFormat}} + //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 + //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? + //WIP when both bugs will be fixed + //List {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0]); + {{{dataType}}} {{paramName}} = new Array{{{dataType}}}(); + //for (Pair pair : {{paramName}}Pair) { + // {{paramName}}.add({{>conversionBegin}}pair.getValue(){{>conversionEnd}}); + //} + {{/collectionFormat}} + {{^collectionFormat}} + String value{{paramName}} = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0]; + {{{dataType}}} {{paramName}}; + {{^required}} + if (value{{paramName}} != null) { + {{paramName}} = {{>conversionBegin}}value{{paramName}}{{>conversionEnd}};{{/required}} + {{#required}}{{paramName}} = {{>conversionBegin}}value{{paramName}}{{>conversionEnd}};{{/required}} + {{^required}} + } else { + {{paramName}} = {{>paramDefaultValue}}; + }{{/required}} + {{/collectionFormat}} + {{/notFile}} + {{/formParams}} + {{#headerParams}} + {{#collectionFormat}} + //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 + //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? + //WIP when both bugs will be fixed + //List {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getHeader("{{baseName}}")); + //{{{dataType}}} {{paramName}} = new Array{{{dataType}}}(); + //for (Pair pair : {{paramName}}Pair) { + // {{paramName}}.add({{>conversionBegin}}pair.getValue(){{>conversionEnd}}); + //} + {{/collectionFormat}} + {{^collectionFormat}} + String value{{paramName}} = request().getHeader("{{baseName}}"); + {{{dataType}}} {{paramName}}; + {{^required}} + if (value{{paramName}} != null) { + {{paramName}} = {{>conversionBegin}}value{{paramName}}{{>conversionEnd}};{{/required}} + {{#required}}{{paramName}} = {{>conversionBegin}}value{{paramName}}{{>conversionEnd}};{{/required}} + {{^required}} + } else { + {{paramName}} = {{>paramDefaultValue}}; + }{{/required}} + {{/collectionFormat}} + {{/headerParams}} + {{#returnType}}{{>returnTypesNoVoid}} obj = {{/returnType}}imp.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{#returnType}}JsonNode result = mapper.valueToTree(obj); + return ok(result);{{/returnType}} + {{^returnType}}return ok();{{/returnType}} + } +{{/operation}} +} +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/notFoundException.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/notFoundException.mustache new file mode 100644 index 000000000000..1bd5e207d7be --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/notFoundException.mustache @@ -0,0 +1,10 @@ +package {{apiPackage}}; + +{{>generatedAnnotation}} +public class NotFoundException extends ApiException { + private int code; + public NotFoundException (int code, String msg) { + super(code, msg); + this.code = code; + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache new file mode 100644 index 000000000000..a24853098c0b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache @@ -0,0 +1 @@ +{{#isInteger}}0{{/isInteger}}{{#isDouble}}0.0{{/isDouble}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0{{/isFloat}}{{#isString}}""{{/isString}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramType.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramType.mustache new file mode 100644 index 000000000000..4871bc3ada28 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramType.mustache @@ -0,0 +1 @@ +{{#isPathParam}}path{{/isPathParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isFormParam}}form{{/isFormParam}}{{#isBodyParam}}body{{/isBodyParam}}{{#isHeaderParam}}header{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache new file mode 100644 index 000000000000..190ebbb3fe20 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache @@ -0,0 +1 @@ +{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParamsNoDoc.mustache new file mode 100644 index 000000000000..4dce26e1cea5 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParamsNoDoc.mustache @@ -0,0 +1 @@ +{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/plugins.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/plugins.mustache new file mode 100644 index 000000000000..ca73a99c7217 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/plugins.mustache @@ -0,0 +1,2 @@ +// The Play plugin +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10") diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache new file mode 100644 index 000000000000..d1422e2b1fc1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache @@ -0,0 +1,118 @@ +/** + * {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}} + */{{#description}} +@ApiModel(description = "{{{description}}}"){{/description}} +{{>generatedAnnotation}} +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { + {{#vars}} + {{#isEnum}} + {{^isContainer}} +{{>enumClass}} + {{/isContainer}} + {{/isEnum}} + {{#items.isEnum}} + {{#items}} + {{^isContainer}} +{{>enumClass}} + {{/isContainer}} + {{/items}} + {{/items.isEnum}} + {{#jackson}} + @JsonProperty("{{baseName}}") + {{/jackson}} + {{#gson}} + @SerializedName("{{baseName}}") + {{/gson}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}}; + + {{/vars}} + {{#vars}} + public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + return this; + } + {{#isListContainer}} + + public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { + this.{{name}}.add({{name}}Item); + return this; + } + {{/isListContainer}} + {{#isMapContainer}} + + public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { + this.{{name}}.put(key, {{name}}Item); + return this; + } + {{/isMapContainer}} + + /** + {{#description}} + * {{{description}}} + {{/description}} + {{^description}} + * Get {{name}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + * @return {{name}} + **/ + {{#vendorExtensions.extraAnnotation}} + {{{vendorExtensions.extraAnnotation}}} + {{/vendorExtensions.extraAnnotation}} + @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() { + return {{name}}; + } + + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + } + + {{/vars}} + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + }{{#hasVars}} + {{classname}} {{classVarName}} = ({{classname}}) o; + return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} && + {{/hasMore}}{{/vars}}{{#parent}} && + super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}} + return true;{{/hasVars}} + } + + @Override + public int hashCode() { + return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class {{classname}} {\n"); + {{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}} + {{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n"); + {{/vars}}sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/build.properties b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/build.properties new file mode 100644 index 000000000000..a8c2f849be3c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.12.0 diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/plugins.sbt b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/plugins.sbt new file mode 100644 index 000000000000..713b7f3e9935 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/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/modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParamsNoDoc.mustache new file mode 100644 index 000000000000..e3fd6c6ce76a --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParamsNoDoc.mustache @@ -0,0 +1 @@ +{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/isQueryParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypes.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypes.mustache new file mode 100644 index 000000000000..dbc2e613707d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypes.mustache @@ -0,0 +1 @@ +{{#returnType}}{{#returnContainer}}{{#isMapContainer}}Map{{/isMapContainer}}{{#isListContainer}}List<{{{returnType}}}>{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}{{^returnType}}void{{/returnType}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoid.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoid.mustache new file mode 100644 index 000000000000..aba24782e7e2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoid.mustache @@ -0,0 +1 @@ +{{#returnType}}{{#returnContainer}}{{#isMapContainer}}Map{{/isMapContainer}}{{#isListContainer}}List<{{{returnType}}}>{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoidNoAbstract.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoidNoAbstract.mustache new file mode 100644 index 000000000000..39f2c32c4d10 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/returnTypesNoVoidNoAbstract.mustache @@ -0,0 +1 @@ +{{#returnType}}{{#returnContainer}}{{#isMapContainer}}HashMap{{/isMapContainer}}{{#isListContainer}}ArrayList<{{{returnType}}}>{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache new file mode 100644 index 000000000000..2ed34dbcd1d6 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache @@ -0,0 +1,27 @@ +# Routes +# This file defines all application routes (Higher priority routes first) +# ~~~~ + +GET /api controllers.ApiDocController.api + +{{#apiInfo}} +{{#apis}} + +#Functions for {{{baseName}}} API +{{#operations}} +{{#operation}} +{{httpMethod}} {{path}} controllers.{{classname}}Controller.{{operationId}}({{#pathParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/pathParams}}) +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} + +# Map static resources from the /public folder to the /assets URL path +GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset) + +GET /api-docs controllers.ApiHelpController.getResources +{{#apiInfo}} +{{#apis}} +GET /api-docs.json/{{{baseName}}} controllers.ApiHelpController.getResource(path = "/{{{baseName}}}") +{{/apis}} +{{/apiInfo}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache new file mode 100644 index 000000000000..99f8d84b7398 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache @@ -0,0 +1,108 @@ +package swagger; + +import javafx.util.Pair; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +public class SwaggerUtils { + + /** + * Format to {@code Pair} objects. + * + * @param collectionFormat collection format (e.g. csv, tsv) + * @param name Name + * @param value Value + * @return A list of Pair objects + */ + public static List parameterToPairs(String collectionFormat, String name, Object value){ + List params = new ArrayList(); + + // preconditions + if (name == null || name.isEmpty() || value == null) return params; + + Collection valueCollection = null; + if (value instanceof Collection) { + valueCollection = (Collection) value; + } else { + params.add(new Pair(name, parameterToString(value))); + return params; + } + + if (valueCollection.isEmpty()){ + return params; + } + + // get the collection format + collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + + // create the params based on the collection format + if (collectionFormat.equals("multi")) { + for (Object item : valueCollection) { + params.add(new Pair(name, parameterToString(item))); + } + + return params; + } + + String delimiter = ","; + + if (collectionFormat.equals("csv")) { + delimiter = ","; + } else if (collectionFormat.equals("ssv")) { + delimiter = " "; + } else if (collectionFormat.equals("tsv")) { + delimiter = "\t"; + } else if (collectionFormat.equals("pipes")) { + delimiter = "|"; + } + + StringBuilder sb = new StringBuilder() ; + for (Object item : valueCollection) { + sb.append(delimiter); + sb.append(parameterToString(item)); + } + + params.add(new Pair(name, sb.substring(1))); + + return params; + } + + /** + * Format the given parameter object into string. + * + * @param param Parameter + * @return String representation of the parameter + */ + public static String parameterToString(Object param) { + if (param == null) { + 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); + } + } + + /** + * Format the given Date object into string (Datetime format). + * + * @param date Date object + * @return Formatted datetime in string representation + */ + public static String formatDatetime(Date date) { + return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date); + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache new file mode 100644 index 000000000000..b3083e788d90 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/typeInfoAnnotation.mustache @@ -0,0 +1,7 @@ +{{#jackson}} +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true ) +@JsonSubTypes({ + {{#children}} + @JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), + {{/children}} +}){{/jackson}} diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index 2586fac929e6..91d363e09653 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -41,6 +41,7 @@ io.swagger.codegen.languages.SinatraServerCodegen io.swagger.codegen.languages.Rails5ServerCodegen io.swagger.codegen.languages.SlimFrameworkServerCodegen io.swagger.codegen.languages.SpringCodegen +io.swagger.codegen.languages.JavaPlayFrameworkCodegen io.swagger.codegen.languages.StaticDocCodegen io.swagger.codegen.languages.StaticHtmlGenerator io.swagger.codegen.languages.StaticHtml2Generator diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java new file mode 100644 index 000000000000..a6873db28add --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java @@ -0,0 +1,68 @@ +package io.swagger.codegen.javaPlayFramework; + +import io.swagger.codegen.CodegenConfig; +import io.swagger.codegen.java.JavaClientOptionsTest; +import io.swagger.codegen.languages.JavaPlayFrameworkCodegen; +import io.swagger.codegen.options.JavaPlayFrameworkOptionsProvider; +import mockit.Expectations; +import mockit.Tested; + +public class JavaPlayFrameworkOptionsTest extends JavaClientOptionsTest { + + @Tested + private JavaPlayFrameworkCodegen clientCodegen; + + public JavaPlayFrameworkOptionsTest() { + super(new JavaPlayFrameworkOptionsProvider()); + } + + @Override + protected CodegenConfig getCodegenConfig() { + return clientCodegen; + } + + @SuppressWarnings("unused") + @Override + protected void setExpectations() { + new Expectations(clientCodegen) {{ + clientCodegen.setModelPackage(JavaPlayFrameworkOptionsProvider.MODEL_PACKAGE_VALUE); + times = 1; + clientCodegen.setApiPackage(JavaPlayFrameworkOptionsProvider.API_PACKAGE_VALUE); + times = 1; + clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.SORT_PARAMS_VALUE)); + times = 1; + clientCodegen.setInvokerPackage(JavaPlayFrameworkOptionsProvider.INVOKER_PACKAGE_VALUE); + times = 1; + clientCodegen.setGroupId(JavaPlayFrameworkOptionsProvider.GROUP_ID_VALUE); + times = 1; + clientCodegen.setArtifactId(JavaPlayFrameworkOptionsProvider.ARTIFACT_ID_VALUE); + times = 1; + clientCodegen.setArtifactVersion(JavaPlayFrameworkOptionsProvider.ARTIFACT_VERSION_VALUE); + times = 1; + clientCodegen.setSourceFolder(JavaPlayFrameworkOptionsProvider.SOURCE_FOLDER_VALUE); + times = 1; + clientCodegen.setLocalVariablePrefix(JavaPlayFrameworkOptionsProvider.LOCAL_PREFIX_VALUE); + times = 1; + clientCodegen.setSerializableModel(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.SERIALIZABLE_MODEL_VALUE)); + times = 1; + clientCodegen.setFullJavaUtil(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.FULL_JAVA_UTIL_VALUE)); + times = 1; + clientCodegen.setTitle(JavaPlayFrameworkOptionsProvider.TITLE); + times = 1; + clientCodegen.setConfigPackage(JavaPlayFrameworkOptionsProvider.CONFIG_PACKAGE_VALUE); + times = 1; + clientCodegen.setBasePackage(JavaPlayFrameworkOptionsProvider.BASE_PACKAGE_VALUE); + times = 1; + clientCodegen.setControllerOnly(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.CONTROLLER_ONLY)); + times = 1; + clientCodegen.setSingleContentTypes(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.SINGLE_CONTENT_TYPES)); + times = 1; + clientCodegen.setResponseWrapper(JavaPlayFrameworkOptionsProvider.RESPONSE_WRAPPER); + times = 1; + clientCodegen.setUseTags(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.USE_TAGS)); + times = 1; + clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.USE_BEANVALIDATION)); + times = 1; + }}; + } +} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java new file mode 100644 index 000000000000..b0971b2e4750 --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java @@ -0,0 +1,42 @@ +package io.swagger.codegen.options; + +import io.swagger.codegen.languages.JavaPlayFrameworkCodegen; + +import java.util.HashMap; +import java.util.Map; + +public class JavaPlayFrameworkOptionsProvider extends JavaOptionsProvider { + public static final String TITLE = "swagger"; + public static final String CONFIG_PACKAGE_VALUE = "configPackage"; + public static final String BASE_PACKAGE_VALUE = "basePackage"; + public static final String CONTROLLER_ONLY = "true"; + public static final String SINGLE_CONTENT_TYPES = "true"; + public static final String RESPONSE_WRAPPER = "Callable"; + public static final String USE_TAGS = "useTags"; + public static final String USE_BEANVALIDATION = "true"; + + @Override + public String getLanguage() { + return "javaPlayFramework"; + } + + @Override + public Map createOptions() { + Map options = new HashMap(super.createOptions()); + options.put(JavaPlayFrameworkCodegen.TITLE, TITLE); + options.put(JavaPlayFrameworkCodegen.CONFIG_PACKAGE, CONFIG_PACKAGE_VALUE); + options.put(JavaPlayFrameworkCodegen.BASE_PACKAGE, BASE_PACKAGE_VALUE); + options.put(JavaPlayFrameworkCodegen.CONTROLLER_ONLY, CONTROLLER_ONLY); + options.put(JavaPlayFrameworkCodegen.SINGLE_CONTENT_TYPES, SINGLE_CONTENT_TYPES); + options.put(JavaPlayFrameworkCodegen.RESPONSE_WRAPPER, RESPONSE_WRAPPER); + options.put(JavaPlayFrameworkCodegen.USE_TAGS, USE_TAGS); + options.put(JavaPlayFrameworkCodegen.USE_BEANVALIDATION, USE_BEANVALIDATION); + + return options; + } + + @Override + public boolean isServer() { + return true; + } +}