diff --git a/src/main/java/io/swagger/codegen/languages/java/AbstractJavaJAXRSServerCodegen.java b/src/main/java/io/swagger/codegen/languages/java/AbstractJavaJAXRSServerCodegen.java new file mode 100644 index 0000000000..b6c511f110 --- /dev/null +++ b/src/main/java/io/swagger/codegen/languages/java/AbstractJavaJAXRSServerCodegen.java @@ -0,0 +1,241 @@ +package io.swagger.codegen.languages.java; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenConstants; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenParameter; +import io.swagger.codegen.CodegenResponse; +import io.swagger.codegen.CodegenType; +import io.swagger.codegen.languages.features.BeanValidationFeatures; +import io.swagger.codegen.utils.ModelUtils; +import io.swagger.codegen.utils.URLPathUtil; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.PathItem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue; + +public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen implements BeanValidationFeatures { + /** + * Name of the sub-directory in "src/main/resource" where to find the + * Mustache template for the JAX-RS Codegen. + */ + protected static final String JAXRS_TEMPLATE_DIRECTORY_NAME = "JavaJaxRS"; + protected String implFolder = "src/main/java"; + protected String testResourcesFolder = "src/test/resources"; + protected String title = "Swagger Server"; + + protected boolean useBeanValidation = true; + + static Logger LOGGER = LoggerFactory.getLogger(AbstractJavaJAXRSServerCodegen.class); + + public AbstractJavaJAXRSServerCodegen() { + super(); + + sourceFolder = "src/gen/java"; + invokerPackage = "io.swagger.api"; + artifactId = "swagger-jaxrs-server"; + dateLibrary = "legacy"; //TODO: add joda support to all jax-rs + + apiPackage = "io.swagger.api"; + modelPackage = "io.swagger.model"; + + additionalProperties.put("title", title); + // java inflector uses the jackson lib + additionalProperties.put("jackson", "true"); + + cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC)); + cliOptions.add(new CliOption("title", "a title describing the application")); + + cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations")); + cliOptions.add(new CliOption("serverPort", "The port on which the server should be started")); + } + + + // =============== + // COMMONS METHODS + // =============== + + @Override + public CodegenType getTag() { + return CodegenType.SERVER; + } + + @Override + public void processOpts() { + super.processOpts(); + + if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) { + implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER); + } + + if (additionalProperties.containsKey(USE_BEANVALIDATION)) { + this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); + } + + if (useBeanValidation) { + writePropertyBack(USE_BEANVALIDATION, useBeanValidation); + } + + } + + @Override + public void preprocessOpenAPI(OpenAPI openAPI) { + if (!this.additionalProperties.containsKey("serverPort")) { + final URL urlInfo = URLPathUtil.getServerURL(openAPI); + String port = "8080"; // Default value for a JEE Server + if ( urlInfo != null && urlInfo.getPort() != 0) { + port = String.valueOf(urlInfo.getPort()); + } + this.additionalProperties.put("serverPort", port); + } + + if (openAPI.getPaths() != null) { + for (String pathname : openAPI.getPaths().keySet()) { + PathItem pathItem = openAPI.getPaths().get(pathname); + final Operation[] operations = ModelUtils.createOperationArray(pathItem); + for (Operation operation : operations) { + if (operation != null && operation.getTags() != null) { + List> tags = new ArrayList>(); + for (String tag : operation.getTags()) { + Map value = new HashMap(); + value.put("tag", tag); + value.put("hasMore", "true"); + tags.add(value); + } + if (tags.size() > 0) { + tags.get(tags.size() - 1).remove("hasMore"); + } + if (operation.getTags().size() > 0) { + String tag = operation.getTags().get(0); + operation.setTags(Arrays.asList(tag)); + } + operation.addExtension("x-tags", tags); + } + } + } + } + } + + @Override + public Map postProcessOperations(Map objs) { + @SuppressWarnings("unchecked") + Map operations = (Map) objs.get("operations"); + if ( operations != null ) { + @SuppressWarnings("unchecked") + List ops = (List) operations.get("operation"); + for ( CodegenOperation operation : ops ) { + boolean hasConsumes = getBooleanValue(operation, CodegenConstants.HAS_CONSUMES_EXT_NAME); + if (hasConsumes) { + Map firstType = operation.consumes.get(0); + if (firstType != null) { + if ("multipart/form-data".equals(firstType.get("mediaType"))) { + operation.getVendorExtensions().put(CodegenConstants.IS_MULTIPART_EXT_NAME, Boolean.TRUE); + } + } + } + + boolean isMultipartPost = false; + List> consumes = operation.consumes; + if(consumes != null) { + for(Map consume : consumes) { + String mt = consume.get("mediaType"); + if(mt != null) { + if(mt.startsWith("multipart/form-data")) { + isMultipartPost = true; + } + } + } + } + + for(CodegenParameter parameter : operation.allParams) { + if(isMultipartPost) { + parameter.vendorExtensions.put("x-multipart", "true"); + } + } + + List responses = operation.responses; + if ( responses != null ) { + for ( CodegenResponse resp : responses ) { + if ( "0".equals(resp.code) ) { + resp.code = "200"; + } + + if (resp.baseType == null) { + resp.dataType = "void"; + resp.baseType = "Void"; + // set vendorExtensions.x-java-is-response-void to true as baseType is set to "Void" + resp.vendorExtensions.put("x-java-is-response-void", true); + } + + if ("array".equals(resp.containerType)) { + resp.containerType = "List"; + } else if ("map".equals(resp.containerType)) { + resp.containerType = "Map"; + } + } + } + + if ( operation.returnBaseType == null ) { + operation.returnType = "void"; + operation.returnBaseType = "Void"; + // set vendorExtensions.x-java-is-response-void to true as returnBaseType is set to "Void" + operation.vendorExtensions.put("x-java-is-response-void", true); + } + + if ("array".equals(operation.returnContainer)) { + operation.returnContainer = "List"; + } else if ("map".equals(operation.returnContainer)) { + operation.returnContainer = "Map"; + } + } + } + return objs; + } + + @Override + public String toApiName(final String name) { + String computed = name; + if ( computed.length() == 0 ) { + return "DefaultApi"; + } + computed = sanitizeName(computed); + return camelize(computed) + "Api"; + } + + @Override + public String apiFilename(String templateName, String tag) { + String result = super.apiFilename(templateName, tag); + + if ( templateName.endsWith("Impl.mustache") ) { + int ix = result.lastIndexOf('/'); + result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java"; + result = result.replace(apiFileFolder(), implFileFolder(implFolder)); + } else if ( templateName.endsWith("Factory.mustache") ) { + int ix = result.lastIndexOf('/'); + result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java"; + result = result.replace(apiFileFolder(), implFileFolder(implFolder)); + } else if ( templateName.endsWith("Service.mustache") ) { + int ix = result.lastIndexOf('.'); + result = result.substring(0, ix) + "Service.java"; + } + return result; + } + + private String implFileFolder(String output) { + return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/'); + } + + public void setUseBeanValidation(boolean useBeanValidation) { + this.useBeanValidation = useBeanValidation; + } + + +} diff --git a/src/main/java/io/swagger/codegen/languages/java/JavaCXFServerCodegen.java b/src/main/java/io/swagger/codegen/languages/java/JavaCXFServerCodegen.java new file mode 100644 index 0000000000..3dd18e9b90 --- /dev/null +++ b/src/main/java/io/swagger/codegen/languages/java/JavaCXFServerCodegen.java @@ -0,0 +1,298 @@ +package io.swagger.codegen.languages.java; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.SupportingFile; +import io.swagger.codegen.languages.features.CXFServerFeatures; +import io.swagger.codegen.languages.features.GzipTestFeatures; +import io.swagger.codegen.languages.features.LoggingTestFeatures; +import io.swagger.codegen.languages.features.UseGenericResponseFeatures; +import io.swagger.v3.oas.models.Operation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.List; +import java.util.Map; + +public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen implements CXFServerFeatures, GzipTestFeatures, LoggingTestFeatures, UseGenericResponseFeatures { + private static final Logger LOGGER = LoggerFactory.getLogger(JavaCXFServerCodegen.class); + + protected boolean addConsumesProducesJson = true; + + protected boolean generateSpringApplication = false; + + protected boolean useSpringAnnotationConfig = false; + + protected boolean useSwaggerFeature = false; + + protected boolean useSwaggerUI = false; + + protected boolean useWadlFeature = false; + + protected boolean useMultipartFeature = false; + + protected boolean useBeanValidationFeature = false; + + protected boolean generateSpringBootApplication = false; + + protected boolean generateJbossDeploymentDescriptor = false; + + protected boolean useGzipFeature = false; + + protected boolean useGzipFeatureForTests = false; + + protected boolean useLoggingFeature = false; + + protected boolean useLoggingFeatureForTests = false; + + protected boolean useAnnotatedBasePath = false; + + protected boolean generateNonSpringApplication = false; + + protected boolean useGenericResponse = false; + + public JavaCXFServerCodegen() { + super(); + + supportsInheritance = true; + + artifactId = "swagger-cxf-server"; + + outputFolder = "generated-code/JavaJaxRS-CXF"; + + typeMapping.put("date", "LocalDate"); + + importMapping.put("LocalDate", "org.joda.time.LocalDate"); + + cliOptions.add(CliOption.newBoolean(GENERATE_SPRING_APPLICATION, "Generate Spring application")); + cliOptions.add(CliOption.newBoolean(USE_SPRING_ANNOTATION_CONFIG, "Use Spring Annotation Config")); + + cliOptions.add(CliOption.newBoolean(USE_SWAGGER_FEATURE, "Use Swagger Feature")); + cliOptions.add(CliOption.newBoolean(USE_SWAGGER_UI, "Use Swagger UI")); + + cliOptions.add(CliOption.newBoolean(USE_WADL_FEATURE, "Use WADL Feature")); + cliOptions.add(CliOption.newBoolean(USE_MULTIPART_FEATURE, "Use Multipart Feature")); + + cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Use Gzip Feature")); + cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE_FOR_TESTS, "Use Gzip Feature for tests")); + + cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION_FEATURE, "Use BeanValidation Feature")); + cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE, "Use Logging Feature")); + cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE_FOR_TESTS, "Use Logging Feature for tests")); + + cliOptions.add(CliOption.newBoolean(GENERATE_SPRING_BOOT_APPLICATION, "Generate Spring Boot application")); + cliOptions.add(CliOption.newBoolean(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, "Generate Jboss Deployment Descriptor")); + + cliOptions.add(CliOption.newBoolean(ADD_CONSUMES_PRODUCES_JSON, "Add @Consumes/@Produces Json to API interface")); + + cliOptions.add(CliOption.newBoolean(USE_ANNOTATED_BASE_PATH, "Use @Path annotations for basePath")); + + cliOptions.add(CliOption.newBoolean(GENERATE_NON_SPRING_APPLICATION, "Generate non-Spring application")); + cliOptions.add(CliOption.newBoolean(USE_GENERIC_RESPONSE, "Use generic response")); + + } + + @Override + public void processOpts() { + super.processOpts(); + + if (StringUtils.isNotBlank(templateVersion)) { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", templateVersion); + } + else { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", DEFAULT_TEMPLATE_VERSION); + } + + apiTemplateFiles.put("apiServiceImpl.mustache", ".java"); + + // 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(ADD_CONSUMES_PRODUCES_JSON)) { + this.setAddConsumesProducesJson(convertPropertyToBooleanAndWriteBack(ADD_CONSUMES_PRODUCES_JSON)); + } + + if (additionalProperties.containsKey(USE_GENERIC_RESPONSE)) { + this.setUseGenericResponse(convertPropertyToBoolean(USE_GENERIC_RESPONSE)); + } + + if (useGenericResponse) { + writePropertyBack(USE_GENERIC_RESPONSE, useGenericResponse); + } + + if (additionalProperties.containsKey(GENERATE_SPRING_APPLICATION)) { + this.setGenerateSpringApplication(convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_APPLICATION)); + + this.setUseSwaggerFeature(convertPropertyToBooleanAndWriteBack(USE_SWAGGER_FEATURE)); + this.setUseSwaggerUI(convertPropertyToBooleanAndWriteBack(USE_SWAGGER_UI)); + + this.setUseWadlFeature(convertPropertyToBooleanAndWriteBack(USE_WADL_FEATURE)); + this.setUseMultipartFeature(convertPropertyToBooleanAndWriteBack(USE_MULTIPART_FEATURE)); + this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE)); + this.setUseGzipFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS)); + this.setUseLoggingFeature(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE)); + this.setUseLoggingFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS)); + this.setUseSpringAnnotationConfig(convertPropertyToBooleanAndWriteBack(USE_SPRING_ANNOTATION_CONFIG)); + + boolean useBeanValidationFeature = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION_FEATURE); + this.setUseBeanValidationFeature(useBeanValidationFeature); + if (useBeanValidationFeature) { + LOGGER.info("make sure your target server supports Bean Validation 1.1"); + } + + this.setGenerateSpringBootApplication(convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_BOOT_APPLICATION)); + } + + if (additionalProperties.containsKey(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR)) { + boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR); + this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp); + } + + if (additionalProperties.containsKey(USE_ANNOTATED_BASE_PATH)) { + boolean useAnnotatedBasePathProp = convertPropertyToBooleanAndWriteBack(USE_ANNOTATED_BASE_PATH); + this.setUseAnnotatedBasePath(useAnnotatedBasePathProp); + } + + if (additionalProperties.containsKey(GENERATE_NON_SPRING_APPLICATION)) { + boolean generateNonSpringApplication = convertPropertyToBooleanAndWriteBack(GENERATE_NON_SPRING_APPLICATION); + this.setGenerateNonSpringApplication(generateNonSpringApplication); + } + + supportingFiles.clear(); // Don't need extra files provided by + // AbstractJAX-RS & Java Codegen + + writeOptional(outputFolder, new SupportingFile("server/pom.mustache", "", "pom.xml")); + + writeOptional(outputFolder, new SupportingFile("server/swagger-codegen-ignore.mustache", "", ".swagger-codegen-ignore")); + + if (this.generateSpringApplication) { + writeOptional(outputFolder, new SupportingFile("server/readme.md", "", "readme.md")); + + writeOptional(outputFolder, new SupportingFile("server/ApplicationContext.xml.mustache", ("src/main/resources"), "ApplicationContext.xml")); + writeOptional(outputFolder, new SupportingFile("server/web.mustache", ("src/main/webapp/WEB-INF"), "web.xml")); + writeOptional(outputFolder, new SupportingFile("server/context.xml.mustache", ("src/main/webapp/WEB-INF"), "context.xml")); + + // Jboss + if (generateJbossDeploymentDescriptor) { + writeOptional(outputFolder, new SupportingFile("server/jboss-web.xml.mustache", ("src/main/webapp/WEB-INF"), "jboss-web.xml")); + + } + + // Spring Boot + if (this.generateSpringBootApplication) { + writeOptional(outputFolder, new SupportingFile("server/SpringBootApplication.mustache", (testFolder + '/' + apiPackage).replace(".", "/"), "SpringBootApplication.java")); + writeOptional(outputFolder, new SupportingFile("server/application.properties.mustache", (testResourcesFolder + '/'), "application.properties")); + + } + } + + if (this.generateNonSpringApplication) { + writeOptional(outputFolder, new SupportingFile("server/nonspring-web.mustache", ("src/main/webapp/WEB-INF"), "web.xml")); + } + } + + @Override + public String getArgumentsLocation() { + return ""; + } + + @Override + public String getName() { + return "jaxrs-cxf"; + } + + @Override + public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { + super.addOperationToGroup(tag, resourcePath, operation, co, operations); + co.subresourceOperation = !co.path.isEmpty(); + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + super.postProcessModelProperty(model, property); + model.imports.remove("ApiModelProperty"); + model.imports.remove("ApiModel"); + model.imports.remove("JsonSerialize"); + model.imports.remove("ToStringSerializer"); + } + + @Override + public String getHelp() { + return "[WORK IN PROGRESS: generated code depends from Swagger v2 libraries] " + + "Generates a Java JAXRS Server application based on Apache CXF framework."; + } + + public void setGenerateSpringApplication(boolean generateSpringApplication) { + this.generateSpringApplication = generateSpringApplication; + } + + public void setUseSpringAnnotationConfig(boolean useSpringAnnotationConfig) { + this.useSpringAnnotationConfig = useSpringAnnotationConfig; + } + + public void setUseSwaggerFeature(boolean useSwaggerFeature) { + this.useSwaggerFeature = useSwaggerFeature; + } + + public void setUseWadlFeature(boolean useWadlFeature) { + this.useWadlFeature = useWadlFeature; + } + + public void setUseMultipartFeature(boolean useMultipartFeature) { + this.useMultipartFeature = useMultipartFeature; + } + + public void setUseGzipFeature(boolean useGzipFeature) { + this.useGzipFeature = useGzipFeature; + } + + public void setUseLoggingFeature(boolean useLoggingFeature) { + this.useLoggingFeature = useLoggingFeature; + } + + public void setUseBeanValidationFeature(boolean useBeanValidationFeature) { + this.useBeanValidationFeature = useBeanValidationFeature; + } + + public void setGenerateSpringBootApplication(boolean generateSpringBootApplication) { + this.generateSpringBootApplication = generateSpringBootApplication; + } + + public void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor) { + this.generateJbossDeploymentDescriptor = generateJbossDeploymentDescriptor; + } + + public void setUseGzipFeatureForTests(boolean useGzipFeatureForTests) { + this.useGzipFeatureForTests = useGzipFeatureForTests; + } + + public void setUseLoggingFeatureForTests(boolean useLoggingFeatureForTests) { + this.useLoggingFeatureForTests = useLoggingFeatureForTests; + } + + public void setUseSwaggerUI(boolean useSwaggerUI) { + this.useSwaggerUI = useSwaggerUI; + } + + public void setAddConsumesProducesJson(boolean addConsumesProducesJson) { + this.addConsumesProducesJson = addConsumesProducesJson; + } + + public void setUseAnnotatedBasePath(boolean useAnnotatedBasePath) { + this.useAnnotatedBasePath = useAnnotatedBasePath; + } + + public void setGenerateNonSpringApplication(boolean generateNonSpringApplication) { + this.generateNonSpringApplication = generateNonSpringApplication; + } + + public void setUseGenericResponse(boolean useGenericResponse) { + this.useGenericResponse = useGenericResponse; + } + +} diff --git a/src/main/java/io/swagger/codegen/languages/java/JavaJAXRSCXFCDIServerCodegen.java b/src/main/java/io/swagger/codegen/languages/java/JavaJAXRSCXFCDIServerCodegen.java new file mode 100644 index 0000000000..02df028eec --- /dev/null +++ b/src/main/java/io/swagger/codegen/languages/java/JavaJAXRSCXFCDIServerCodegen.java @@ -0,0 +1,98 @@ +package io.swagger.codegen.languages.java; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.SupportingFile; +import io.swagger.codegen.languages.features.BeanValidationFeatures; +import org.apache.commons.lang3.StringUtils; +import java.io.File; + +/** + * Generates a Java JAXRS Server according to JAXRS 2.0 specification, assuming + * an Apache CXF runtime and a Java EE runtime with CDI enabled. Similar to the + * original JAXRS generator, this creates API and Service classes in + * /src/gen/java and a sample ServiceImpl in /src/main/java. The API uses CDI to + * get an instance of ServiceImpl that implements the Service interface. + */ +public class JavaJAXRSCXFCDIServerCodegen extends JavaJAXRSSpecServerCodegen implements BeanValidationFeatures { + + protected boolean useBeanValidation = true; + + /** + * Default constructor + */ + public JavaJAXRSCXFCDIServerCodegen() { + outputFolder = "generated-code/JavaJaxRS-CXF-CDI"; + artifactId = "swagger-jaxrs-cxf-cdi-server"; + sourceFolder = "src" + File.separator + "gen" + File.separator + "java"; + + // Use standard types + typeMapping.put("DateTime", "java.util.Date"); + + cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations")); + } + + @Override + public String getName() { + return "jaxrs-cxf-cdi"; + } + + @Override + public void processOpts() { + super.processOpts(); + + if (StringUtils.isNotBlank(templateVersion)) { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf-cdi", templateVersion); + } + else { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf-cdi", DEFAULT_TEMPLATE_VERSION); + } + + // Three API templates to support CDI injection + apiTemplateFiles.put("apiService.mustache", ".java"); + apiTemplateFiles.put("apiServiceImpl.mustache", ".java"); + + if (additionalProperties.containsKey(USE_BEANVALIDATION)) { + this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); + } + + if (useBeanValidation) { + writePropertyBack(USE_BEANVALIDATION, useBeanValidation); + } + + supportingFiles.clear(); // Don't need extra files provided by + // AbstractJAX-RS & Java Codegen + + // writeOptional means these files are only written if they don't + // already exist + + // POM + writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + + // RestApplication into src/main/java + writeOptional(outputFolder, new SupportingFile("RestApplication.mustache", (implFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java")); + + // Make CDI work in containers with implicit archive scanning disabled + writeOptional(outputFolder, new SupportingFile("beans.mustache", "src/main/webapp/WEB-INF", "beans.xml")); + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + super.postProcessModelProperty(model, property); + + // Reinstate JsonProperty + model.imports.add("JsonProperty"); + } + + @Override + public String getHelp() { + return "[WORK IN PROGRESS: generated code depends from Swagger v2 libraries] " + + "Generates a Java JAXRS Server according to JAXRS 2.0 specification, assuming an " + + "Apache CXF runtime and a Java EE runtime with CDI enabled."; + } + + public void setUseBeanValidation(boolean useBeanValidation) { + this.useBeanValidation = useBeanValidation; + } +} diff --git a/src/main/java/io/swagger/codegen/languages/java/JavaJAXRSSpecServerCodegen.java b/src/main/java/io/swagger/codegen/languages/java/JavaJAXRSSpecServerCodegen.java new file mode 100644 index 0000000000..7f06bfd9f1 --- /dev/null +++ b/src/main/java/io/swagger/codegen/languages/java/JavaJAXRSSpecServerCodegen.java @@ -0,0 +1,177 @@ +package io.swagger.codegen.languages.java; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenConstants; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.SupportingFile; +import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen { + + public static final String INTERFACE_ONLY = "interfaceOnly"; + public static final String GENERATE_POM = "generatePom"; + + private boolean interfaceOnly = false; + private boolean generatePom = true; + + public JavaJAXRSSpecServerCodegen() { + super(); + invokerPackage = "io.swagger.api"; + artifactId = "swagger-jaxrs-server"; + outputFolder = "generated-code/JavaJaxRS-Spec"; + + additionalProperties.put("title", title); + + typeMapping.put("date", "LocalDate"); + + importMapping.put("LocalDate", "org.joda.time.LocalDate"); + + for (int i = 0; i < cliOptions.size(); i++) { + if (CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt())) { + cliOptions.remove(i); + break; + } + } + + CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use"); + library.setDefault(DEFAULT_LIBRARY); + + Map supportedLibraries = new LinkedHashMap(); + + supportedLibraries.put(DEFAULT_LIBRARY, "JAXRS"); + library.setEnum(supportedLibraries); + + cliOptions.add(library); + cliOptions.add(CliOption.newBoolean(GENERATE_POM, "Whether to generate pom.xml if the file does not already exist.").defaultValue(String.valueOf(generatePom))); + cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.").defaultValue(String.valueOf(interfaceOnly))); + } + + @Override + public void processOpts() { + if (additionalProperties.containsKey(GENERATE_POM)) { + generatePom = Boolean.valueOf(additionalProperties.get(GENERATE_POM).toString()); + } + if (additionalProperties.containsKey(INTERFACE_ONLY)) { + interfaceOnly = Boolean.valueOf(additionalProperties.get(INTERFACE_ONLY).toString()); + } + if (interfaceOnly) { + // Change default artifactId if genereating interfaces only, before + // command line options are applied in base class. + artifactId = "swagger-jaxrs-client"; + } + + super.processOpts(); + + if (StringUtils.isNotBlank(templateVersion)) { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/spec", templateVersion); + } + else { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/spec", DEFAULT_TEMPLATE_VERSION); + } + + modelTemplateFiles.put("model.mustache", ".java"); + apiTemplateFiles.put("api.mustache", ".java"); + apiPackage = "io.swagger.api"; + modelPackage = "io.swagger.model"; + + apiTestTemplateFiles.clear(); // TODO: add api test template + modelTestTemplateFiles.clear(); // TODO: add model test template + + // 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"); + + supportingFiles.clear(); // Don't need extra files provided by + // AbstractJAX-RS & Java Codegen + if (generatePom) { + writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + } + if (!interfaceOnly) { + writeOptional(outputFolder, new SupportingFile("RestApplication.mustache", (sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java")); + } + } + + @Override + public String getArgumentsLocation() { + return ""; + } + + @Override + public String getName() { + return "jaxrs-spec"; + } + + @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()); + } + co.subresourceOperation = !co.path.isEmpty(); + } + List opList = operations.get(basePath); + if (opList == null) { + opList = new ArrayList(); + operations.put(basePath, opList); + } + opList.add(co); + co.baseName = basePath; + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + super.postProcessModelProperty(model, property); + model.imports.remove("ApiModelProperty"); + model.imports.remove("ApiModel"); + model.imports.remove("JsonSerialize"); + model.imports.remove("ToStringSerializer"); + model.imports.remove("JsonValue"); + model.imports.remove("JsonProperty"); + } + + @Override + public void preprocessOpenAPI(OpenAPI openAPI) { + // copy input swagger to output folder + try { + String swaggerJson = Json.pretty(openAPI); + FileUtils.writeStringToFile(new File(outputFolder + File.separator + "swagger.json"), swaggerJson); + } + catch (IOException e) { + throw new RuntimeException(e.getMessage(), e.getCause()); + } + super.preprocessOpenAPI(openAPI); + + } + + @Override + public String getHelp() { + return "[WORK IN PROGRESS: generated code depends from Swagger v2 libraries] " + + "Generates a Java JAXRS Server according to JAXRS 2.0 specification."; + } +} diff --git a/src/main/java/io/swagger/codegen/languages/java/JavaJerseyServerCodegen.java b/src/main/java/io/swagger/codegen/languages/java/JavaJerseyServerCodegen.java new file mode 100644 index 0000000000..7be4ec884a --- /dev/null +++ b/src/main/java/io/swagger/codegen/languages/java/JavaJerseyServerCodegen.java @@ -0,0 +1,202 @@ +package io.swagger.codegen.languages.java; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenConstants; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.SupportingFile; +import io.swagger.v3.oas.models.Operation; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import static io.swagger.codegen.CodegenConstants.HAS_ENUMS_EXT_NAME; +import static io.swagger.codegen.CodegenConstants.IS_ENUM_EXT_NAME; +import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue; + +public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen { + + protected static final String LIBRARY_JERSEY1 = "jersey1"; + protected static final String LIBRARY_JERSEY2 = "jersey2"; + + /** + * Default library template to use. (Default:{@value #DEFAULT_LIBRARY}) + */ + public static final String DEFAULT_LIBRARY = LIBRARY_JERSEY2; + public static final String USE_TAGS = "useTags"; + + protected boolean useTags = false; + + public JavaJerseyServerCodegen() { + super(); + + outputFolder = "generated-code/JavaJaxRS-Jersey"; + + CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use"); + + supportedLibraries.put(LIBRARY_JERSEY1, "Jersey core 1.x"); + supportedLibraries.put(LIBRARY_JERSEY2, "Jersey core 2.x"); + library.setEnum(supportedLibraries); + library.setDefault(DEFAULT_LIBRARY); + + cliOptions.add(library); + cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1/2 library.")); + cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames")); + } + + @Override + public String getName() { + return "jaxrs-jersey"; + } + + @Override + public String getHelp() { + return "[WORK IN PROGRESS: generated code depends from Swagger v2 libraries] " + + "Generates a Java JAXRS Server application based on Jersey framework."; + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + super.postProcessModelProperty(model, property); + if ("null".equals(property.example)) { + property.example = null; + } + + // Add imports for Jackson + boolean isEnum = getBooleanValue(model, IS_ENUM_EXT_NAME); + if (!BooleanUtils.toBoolean(isEnum)) { + model.imports.add("JsonProperty"); + boolean hasEnums = getBooleanValue(model, HAS_ENUMS_EXT_NAME); + if (BooleanUtils.toBoolean(hasEnums)) { + model.imports.add("JsonValue"); + } + } + } + + @Override + public void processOpts() { + super.processOpts(); + + if (StringUtils.isNotBlank(templateVersion)) { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME, templateVersion); + } + else { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME, DEFAULT_TEMPLATE_VERSION); + } + + apiTemplateFiles.put("apiService.mustache", ".java"); + apiTemplateFiles.put("apiServiceImpl.mustache", ".java"); + apiTemplateFiles.put("apiServiceFactory.mustache", ".java"); + apiTestTemplateFiles.clear(); // TODO: add test template + + // 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"); + + // use default library if unset + if (StringUtils.isEmpty(library)) { + setLibrary(DEFAULT_LIBRARY); + } + + if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) { + implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER); + } + + if (additionalProperties.containsKey(USE_TAGS)) { + this.setUseTags(Boolean.valueOf(additionalProperties.get(USE_TAGS).toString())); + } + + if ("joda".equals(dateLibrary)) { + supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java")); + supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java")); + } + else if (dateLibrary.startsWith("java8")) { + supportingFiles.add(new SupportingFile("OffsetDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "OffsetDateTimeProvider.java")); + supportingFiles.add(new SupportingFile("LocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java")); + } + + writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md")); + supportingFiles.add(new SupportingFile("ApiException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java")); + supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiOriginFilter.java")); + supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java")); + supportingFiles.add(new SupportingFile("NotFoundException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java")); + supportingFiles.add(new SupportingFile("jacksonJsonProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JacksonJsonProvider.java")); + supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "RFC3339DateFormat.java")); + writeOptional(outputFolder, new SupportingFile("bootstrap.mustache", (implFolder + '/' + apiPackage).replace(".", "/"), "Bootstrap.java")); + writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml")); + supportingFiles.add(new SupportingFile("StringUtil.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "StringUtil.java")); + } + + @Override + public String getArgumentsLocation() { + return ""; + } + + @Override + public Map postProcessModelsEnum(Map objs) { + objs = super.postProcessModelsEnum(objs); + + // Add imports for Jackson + List> imports = (List>) objs.get("imports"); + List models = (List) objs.get("models"); + for (Object _mo : models) { + Map mo = (Map) _mo; + CodegenModel cm = (CodegenModel) mo.get("model"); + // for enum model + boolean isEnum = getBooleanValue(cm, IS_ENUM_EXT_NAME); + if (isEnum && cm.allowableValues != null) { + cm.imports.add(importMapping.get("JsonValue")); + Map item = new HashMap(); + item.put("import", importMapping.get("JsonValue")); + imports.add(item); + } + } + + return objs; + } + + @Override + public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { + if (useTags) { + super.addOperationToGroup(tag, resourcePath, operation, co, operations); + } + else { + 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()); + } + co.subresourceOperation = !co.path.isEmpty(); + } + List opList = operations.get(basePath); + if (opList == null) { + opList = new ArrayList(); + operations.put(basePath, opList); + } + opList.add(co); + co.baseName = basePath; + } + } + + public void setUseTags(boolean useTags) { + this.useTags = useTags; + } + +} diff --git a/src/main/java/io/swagger/codegen/languages/java/JavaResteasyEapServerCodegen.java b/src/main/java/io/swagger/codegen/languages/java/JavaResteasyEapServerCodegen.java new file mode 100644 index 0000000000..7b9f109b17 --- /dev/null +++ b/src/main/java/io/swagger/codegen/languages/java/JavaResteasyEapServerCodegen.java @@ -0,0 +1,199 @@ +package io.swagger.codegen.languages.java; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.SupportingFile; +import io.swagger.codegen.languages.features.BeanValidationFeatures; +import io.swagger.codegen.languages.features.JbossFeature; +import io.swagger.codegen.languages.features.SwaggerFeatures; +import io.swagger.v3.oas.models.Operation; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import static io.swagger.codegen.CodegenConstants.HAS_ENUMS_EXT_NAME; +import static io.swagger.codegen.CodegenConstants.IS_ENUM_EXT_NAME; +import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue; + +public class JavaResteasyEapServerCodegen extends AbstractJavaJAXRSServerCodegen implements JbossFeature, BeanValidationFeatures, SwaggerFeatures { + + protected boolean useBeanValidation = true; + protected boolean generateJbossDeploymentDescriptor = true; + protected boolean useSwaggerFeature = false; + + public JavaResteasyEapServerCodegen() { + + super(); + + artifactId = "swagger-jaxrs-resteasy-eap-server"; + + outputFolder = "generated-code/JavaJaxRS-Resteasy-eap"; + + dateLibrary = "legacy";// TODO: change to joda + + cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations")); + cliOptions.add(CliOption.newBoolean(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, "Generate Jboss Deployment Descriptor")); + cliOptions.add(CliOption.newBoolean(USE_SWAGGER_FEATURE, "Use dynamic Swagger generator")); + + } + + @Override + public String getName() { + return "jaxrs-resteasy-eap"; + } + + @Override + public String getHelp() { + return "[WORK IN PROGRESS: generated code depends from Swagger v2 libraries] " + + "Generates a Java JAXRS-Resteasy Server application."; + } + + @Override + public void processOpts() { + super.processOpts(); + + if (StringUtils.isNotBlank(templateVersion)) { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy/eap", templateVersion); + } + else { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy/eap", DEFAULT_TEMPLATE_VERSION); + } + + apiTemplateFiles.put("apiServiceImpl.mustache", ".java"); + apiTestTemplateFiles.clear(); // TODO: add test template + + // clear model and api doc template as AbstractJavaJAXRSServerCodegen + // 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(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR)) { + boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR); + this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp); + } + + if (additionalProperties.containsKey(USE_BEANVALIDATION)) { + this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); + } + + if (useBeanValidation) { + writePropertyBack(USE_BEANVALIDATION, useBeanValidation); + } + + if (additionalProperties.containsKey(USE_SWAGGER_FEATURE)) { + this.setUseSwaggerFeature(convertPropertyToBoolean(USE_SWAGGER_FEATURE)); + } + + if (useSwaggerFeature) { + writePropertyBack(USE_SWAGGER_FEATURE, useSwaggerFeature); + } + + writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + writeOptional(outputFolder, new SupportingFile("gradle.mustache", "", "build.gradle")); + writeOptional(outputFolder, new SupportingFile("settingsGradle.mustache", "", "settings.gradle")); + writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md")); + writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml")); + + supportingFiles.add(new SupportingFile("JacksonConfig.mustache", (projectFolder + File.separator + "java" + '/' + invokerPackage).replace(".", "/"), "JacksonConfig.java")); + + if (generateJbossDeploymentDescriptor) { + writeOptional(outputFolder, new SupportingFile("jboss-web.mustache", ("src/main/webapp/WEB-INF"), "jboss-web.xml")); + } + + writeOptional(outputFolder, new SupportingFile("RestApplication.mustache", (projectFolder + File.separator + "java" + '/' + invokerPackage).replace(".", "/"), "RestApplication.java")); + + } + + @Override + public String getArgumentsLocation() { + return ""; + } + + @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()); + } + co.subresourceOperation = !co.path.isEmpty(); + } + List opList = operations.get(basePath); + if (opList == null) { + opList = new ArrayList(); + operations.put(basePath, opList); + } + opList.add(co); + co.baseName = basePath; + } + + @Override + public Map postProcessOperations(Map objs) { + return super.postProcessOperations(objs); + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + boolean isEnum = getBooleanValue(model, IS_ENUM_EXT_NAME); + // Add imports for Jackson + if (!BooleanUtils.toBoolean(isEnum)) { + model.imports.add("JsonProperty"); + boolean hasEnums = getBooleanValue(model, HAS_ENUMS_EXT_NAME); + if (BooleanUtils.toBoolean(hasEnums)) { + model.imports.add("JsonValue"); + } + } + } + + @Override + public Map postProcessModelsEnum(Map objs) { + objs = super.postProcessModelsEnum(objs); + + // Add imports for Jackson + List> imports = (List>) objs.get("imports"); + List models = (List) objs.get("models"); + for (Object _mo : models) { + Map mo = (Map) _mo; + CodegenModel cm = (CodegenModel) mo.get("model"); + // for enum model + boolean isEnum = getBooleanValue(cm, IS_ENUM_EXT_NAME); + if (Boolean.TRUE.equals(isEnum) && cm.allowableValues != null) { + cm.imports.add(importMapping.get("JsonValue")); + Map item = new HashMap(); + item.put("import", importMapping.get("JsonValue")); + imports.add(item); + } + } + + return objs; + } + + public void setUseBeanValidation(boolean useBeanValidation) { + this.useBeanValidation = useBeanValidation; + } + + public void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor) { + this.generateJbossDeploymentDescriptor = generateJbossDeploymentDescriptor; + } + + public void setUseSwaggerFeature(boolean useSwaggerFeature) { + this.useSwaggerFeature = useSwaggerFeature; + } +} diff --git a/src/main/java/io/swagger/codegen/languages/java/JavaResteasyServerCodegen.java b/src/main/java/io/swagger/codegen/languages/java/JavaResteasyServerCodegen.java new file mode 100644 index 0000000000..a66d60210a --- /dev/null +++ b/src/main/java/io/swagger/codegen/languages/java/JavaResteasyServerCodegen.java @@ -0,0 +1,182 @@ +package io.swagger.codegen.languages.java; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.SupportingFile; +import io.swagger.codegen.languages.features.JbossFeature; +import io.swagger.v3.oas.models.Operation; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import static io.swagger.codegen.CodegenConstants.HAS_ENUMS_EXT_NAME; +import static io.swagger.codegen.CodegenConstants.IS_ENUM_EXT_NAME; +import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue; + +public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen implements JbossFeature { + + protected boolean generateJbossDeploymentDescriptor = true; + + public JavaResteasyServerCodegen() { + + super(); + + artifactId = "swagger-jaxrs-resteasy-server"; + + outputFolder = "generated-code/JavaJaxRS-Resteasy"; + + dateLibrary = "legacy";// TODO: change to joda + + cliOptions.add(CliOption.newBoolean(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, "Generate Jboss Deployment Descriptor")); + } + + @Override + public String getName() { + return "jaxrs-resteasy"; + } + + @Override + public String getHelp() { + return "[WORK IN PROGRESS: generated code depends from Swagger v2 libraries] " + + "Generates a Java JAXRS-Resteasy Server application."; + } + + @Override + public void processOpts() { + super.processOpts(); + + if (StringUtils.isNotBlank(templateVersion)) { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy", templateVersion); + } + else { + embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy", DEFAULT_TEMPLATE_VERSION); + } + + apiTemplateFiles.put("apiService.mustache", ".java"); + apiTemplateFiles.put("apiServiceImpl.mustache", ".java"); + apiTestTemplateFiles.clear(); // TODO: add test template + + // clear model and api doc template as AbstractJavaJAXRSServerCodegen + // 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(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR)) { + boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR); + this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp); + } + + writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + writeOptional(outputFolder, new SupportingFile("gradle.mustache", "", "build.gradle")); + writeOptional(outputFolder, new SupportingFile("settingsGradle.mustache", "", "settings.gradle")); + writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md")); + supportingFiles.add(new SupportingFile("ApiException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java")); + supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiOriginFilter.java")); + supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java")); + supportingFiles.add(new SupportingFile("NotFoundException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java")); + writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml")); + + if (generateJbossDeploymentDescriptor) { + writeOptional(outputFolder, new SupportingFile("jboss-web.mustache", ("src/main/webapp/WEB-INF"), "jboss-web.xml")); + } + + writeOptional(outputFolder, new SupportingFile("RestApplication.mustache", (sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java")); + supportingFiles.add(new SupportingFile("StringUtil.mustache", (sourceFolder + '/' + invokerPackage).replace(".", "/"), "StringUtil.java")); + supportingFiles.add(new SupportingFile("JacksonConfig.mustache", (sourceFolder + '/' + invokerPackage).replace(".", "/"), "JacksonConfig.java")); + supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", (sourceFolder + '/' + invokerPackage).replace(".", "/"), "RFC3339DateFormat.java")); + + if ("joda".equals(dateLibrary)) { + supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java")); + supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java")); + } + else if (dateLibrary.startsWith("java8")) { + supportingFiles.add(new SupportingFile("OffsetDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "OffsetDateTimeProvider.java")); + supportingFiles.add(new SupportingFile("LocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java")); + } + } + + + @Override + public String getArgumentsLocation() { + return ""; + } + + @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()); + } + co.subresourceOperation = !co.path.isEmpty(); + } + List opList = operations.get(basePath); + if (opList == null) { + opList = new ArrayList(); + operations.put(basePath, opList); + } + opList.add(co); + co.baseName = basePath; + } + + @Override + public Map postProcessOperations(Map objs) { + return super.postProcessOperations(objs); + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + boolean isEnum = getBooleanValue(model, IS_ENUM_EXT_NAME); + // Add imports for Jackson + if (!BooleanUtils.toBoolean(isEnum)) { + model.imports.add("JsonProperty"); + boolean hasEnums = getBooleanValue(model, HAS_ENUMS_EXT_NAME); + if (BooleanUtils.toBoolean(hasEnums)) { + model.imports.add("JsonValue"); + } + } + } + + @Override + public Map postProcessModelsEnum(Map objs) { + objs = super.postProcessModelsEnum(objs); + + // Add imports for Jackson + List> imports = (List>) objs.get("imports"); + List models = (List) objs.get("models"); + for (Object _mo : models) { + Map mo = (Map) _mo; + CodegenModel cm = (CodegenModel) mo.get("model"); + // for enum model + boolean isEnum = getBooleanValue(cm, IS_ENUM_EXT_NAME); + if (Boolean.TRUE.equals(isEnum) && cm.allowableValues != null) { + cm.imports.add(importMapping.get("JsonValue")); + Map item = new HashMap(); + item.put("import", importMapping.get("JsonValue")); + imports.add(item); + } + } + + return objs; + } + + public void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor) { + this.generateJbossDeploymentDescriptor = generateJbossDeploymentDescriptor; + } +} diff --git a/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index 281afd90b3..a0e6cfecf6 100644 --- a/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -1,2 +1,8 @@ io.swagger.codegen.languages.java.JavaClientCodegen -io.swagger.codegen.languages.java.JavaInflectorServerCodegen \ No newline at end of file +io.swagger.codegen.languages.java.JavaCXFServerCodegen +io.swagger.codegen.languages.java.JavaInflectorServerCodegen +io.swagger.codegen.languages.java.JavaJAXRSCXFCDIServerCodegen +io.swagger.codegen.languages.java.JavaJAXRSSpecServerCodegen +io.swagger.codegen.languages.java.JavaJerseyServerCodegen +io.swagger.codegen.languages.java.JavaResteasyEapServerCodegen +io.swagger.codegen.languages.java.JavaResteasyServerCodegen \ No newline at end of file diff --git a/src/main/resources/v2/Java/libraries/resttemplate/api.mustache b/src/main/resources/v2/Java/libraries/resttemplate/api.mustache index df579d8c3f..03b60bb67e 100644 --- a/src/main/resources/v2/Java/libraries/resttemplate/api.mustache +++ b/src/main/resources/v2/Java/libraries/resttemplate/api.mustache @@ -88,13 +88,13 @@ public class {{classname}} { {{localVariablePrefix}}formParams.add("{{baseName}}", {{#is this 'file'}}new FileSystemResource({{paramName}}){{/is}}{{#isNot this 'file'}}{{paramName}}{{/isNot}});{{#has this 'more'}} {{/has}}{{/formParams}}{{/hasFormParams}} - final String[] {{localVariablePrefix}}accepts = { {{#hasProduces}} + final String[] {{localVariablePrefix}}accepts = { {{#has this 'produces'}} {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} - {{/hasProduces}} }; + {{/has}} }; final List {{localVariablePrefix}}accept = {{localVariablePrefix}}apiClient.selectHeaderAccept({{localVariablePrefix}}accepts); - final String[] {{localVariablePrefix}}contentTypes = { {{#hasConsumes}} + final String[] {{localVariablePrefix}}contentTypes = { {{#has this 'consumes'}} {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} - {{/hasConsumes}} }; + {{/has}} }; final MediaType {{localVariablePrefix}}contentType = {{localVariablePrefix}}apiClient.selectHeaderContentType({{localVariablePrefix}}contentTypes); String[] {{localVariablePrefix}}authNames = new String[] { {{#authMethods}}"{{name}}"{{#has this 'more'}}, {{/has}}{{/authMethods}} }; diff --git a/src/main/resources/v2/JavaJaxRS/ApiException.mustache b/src/main/resources/v2/JavaJaxRS/ApiException.mustache new file mode 100644 index 0000000000..f616114770 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/ApiException.mustache @@ -0,0 +1,10 @@ +package {{apiPackage}}; + +{{>generatedAnnotation}} +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/v2/JavaJaxRS/ApiOriginFilter.mustache b/src/main/resources/v2/JavaJaxRS/ApiOriginFilter.mustache new file mode 100644 index 0000000000..b8af270a05 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/ApiOriginFilter.mustache @@ -0,0 +1,22 @@ +package {{apiPackage}}; + +import java.io.IOException; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; + +{{>generatedAnnotation}} +public class ApiOriginFilter implements javax.servlet.Filter { + 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); + } + + public void destroy() {} + + public void init(FilterConfig filterConfig) throws ServletException {} +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/ApiResponseMessage.mustache b/src/main/resources/v2/JavaJaxRS/ApiResponseMessage.mustache new file mode 100644 index 0000000000..c883e16b5e --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/ApiResponseMessage.mustache @@ -0,0 +1,69 @@ +package {{apiPackage}}; + +import javax.xml.bind.annotation.XmlTransient; + +@javax.xml.bind.annotation.XmlRootElement +{{>generatedAnnotation}} +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/v2/JavaJaxRS/JodaDateTimeProvider.mustache b/src/main/resources/v2/JavaJaxRS/JodaDateTimeProvider.mustache new file mode 100644 index 0000000000..f942179098 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/JodaDateTimeProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import org.joda.time.DateTime; +import java.util.List; + +@Provider +public class JodaDateTimeProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public JodaDateTimeProvider(@Context UriInfo uriInfo) { + super(DateTime.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public DateTime getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return DateTime.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/JodaLocalDateProvider.mustache b/src/main/resources/v2/JavaJaxRS/JodaLocalDateProvider.mustache new file mode 100644 index 0000000000..7bd4027e63 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/JodaLocalDateProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import org.joda.time.LocalDate; +import java.util.List; + +@Provider +public class JodaLocalDateProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public JodaLocalDateProvider(@Context UriInfo uriInfo) { + super(LocalDate.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public LocalDate getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return LocalDate.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/NotFoundException.mustache b/src/main/resources/v2/JavaJaxRS/NotFoundException.mustache new file mode 100644 index 0000000000..40c25c5ea5 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/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/src/main/resources/v2/JavaJaxRS/README.mustache b/src/main/resources/v2/JavaJaxRS/README.mustache new file mode 100644 index 0000000000..b8a8abc32a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/README.mustache @@ -0,0 +1,23 @@ +# Swagger Jersey generated server + +## Overview +This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the +[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +is an example of building a swagger-enabled JAX-RS server. + +This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework. + +To run the server, please execute the following: + +``` +mvn clean package jetty:run +``` + +You can then view the swagger listing here: + +``` +http://localhost:{{serverPort}}{{contextPath}}/swagger.json +``` + +Note that if you have configured the `host` to be something other than localhost, the calls through +swagger-ui will be directed to that host and not localhost! \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/RFC3339DateFormat.mustache b/src/main/resources/v2/JavaJaxRS/RFC3339DateFormat.mustache new file mode 100644 index 0000000000..061e000f5a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/RFC3339DateFormat.mustache @@ -0,0 +1,19 @@ +package {{apiPackage}}; + +import com.fasterxml.jackson.databind.util.ISO8601DateFormat; +import com.fasterxml.jackson.databind.util.ISO8601Utils; + +import java.text.FieldPosition; +import java.util.Date; + +public class RFC3339DateFormat extends ISO8601DateFormat { + + // Same as ISO8601DateFormat but serializing milliseconds. + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + String value = ISO8601Utils.format(date, true); + toAppendTo.append(value); + return toAppendTo; + } + +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/StringUtil.mustache b/src/main/resources/v2/JavaJaxRS/StringUtil.mustache new file mode 100644 index 0000000000..b1b47ccc7f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/StringUtil.mustache @@ -0,0 +1,42 @@ +package {{apiPackage}}; + +{{>generatedAnnotation}} +public class StringUtil { + /** + * Check if the given array contains the given value (with case-insensitive comparison). + * + * @param array The array + * @param value The value to search + * @return true if the array contains the value + */ + public static boolean containsIgnoreCase(String[] array, String value) { + for (String str : array) { + if (value == null && str == null) return true; + if (value != null && value.equalsIgnoreCase(str)) return true; + } + return false; + } + + /** + * Join an array of strings with the given separator. + *

+ * Note: This might be replaced by utility method from commons-lang or guava someday + * if one of those libraries is added as dependency. + *

+ * + * @param array The array of strings + * @param separator The separator + * @return the resulting string + */ + public static String join(String[] array, String separator) { + int len = array.length; + if (len == 0) return ""; + + StringBuilder out = new StringBuilder(); + out.append(array[0]); + for (int i = 1; i < len; i++) { + out.append(separator).append(array[i]); + } + return out.toString(); + } +} diff --git a/src/main/resources/v2/JavaJaxRS/allowableValues.mustache b/src/main/resources/v2/JavaJaxRS/allowableValues.mustache new file mode 100644 index 0000000000..d8b42439fa --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/allowableValues.mustache @@ -0,0 +1 @@ +{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^@last}}, {{/@last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/api.mustache b/src/main/resources/v2/JavaJaxRS/api.mustache new file mode 100644 index 0000000000..5b01010f4e --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/api.mustache @@ -0,0 +1,82 @@ +package {{package}}; + +import {{modelPackage}}.*; +import {{package}}.{{classname}}Service; +import {{package}}.factories.{{classname}}ServiceFactory; + +import io.swagger.annotations.ApiParam; +import io.swagger.jaxrs.*; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.Map; +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; + +import javax.servlet.ServletConfig; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.*; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} + +@Path("/{{{baseName}}}") +{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} +{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} +@io.swagger.annotations.Api(description = "the {{{baseName}}} API") +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}} { + private final {{classname}}Service delegate; + + public {{classname}}(@Context ServletConfig servletContext) { + {{classname}}Service delegate = null; + + if (servletContext != null) { + String implClass = servletContext.getInitParameter("{{classname}}.implementation"); + if (implClass != null && !"".equals(implClass.trim())) { + try { + delegate = ({{classname}}Service) Class.forName(implClass).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + if (delegate == null) { + delegate = {{classname}}ServiceFactory.get{{classname}}(); + } + + this.delegate = delegate; + } + +{{#operation}} + @{{httpMethod}} + {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} + {{#has this 'consumes'}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/has}} + {{#has this 'produces'}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/has}} + @io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#is this 'oauth'}}, scopes = { + {{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/is}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) + @io.swagger.annotations.ApiResponses(value = { {{#responses}} + @io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#has this 'more'}}, + {{/has}}{{/responses}} }) + public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}},{{/allParams}}@Context SecurityContext securityContext) + throws NotFoundException { + return delegate.{{nickname}}({{#allParams}}{{#is this 'file'}}{{paramName}}InputStream, {{paramName}}Detail{{/is}}{{#isNot this 'file'}}{{paramName}}{{/isNot}},{{/allParams}}securityContext); + } +{{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/apiService.mustache b/src/main/resources/v2/JavaJaxRS/apiService.mustache new file mode 100644 index 0000000000..eb8d9aaaa0 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/apiService.mustache @@ -0,0 +1,28 @@ +package {{package}}; + +import {{package}}.*; +import {{modelPackage}}.*; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{>generatedAnnotation}} +{{#operations}} +public abstract class {{classname}}Service { + {{#operation}} + public abstract Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}},{{/allParams}}SecurityContext securityContext) throws NotFoundException; + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/apiServiceFactory.mustache b/src/main/resources/v2/JavaJaxRS/apiServiceFactory.mustache new file mode 100644 index 0000000000..0f32103499 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/apiServiceFactory.mustache @@ -0,0 +1,13 @@ +package {{package}}.factories; + +import {{package}}.{{classname}}Service; +import {{package}}.impl.{{classname}}ServiceImpl; + +{{>generatedAnnotation}} +public class {{classname}}ServiceFactory { + private final static {{classname}}Service service = new {{classname}}ServiceImpl(); + + public static {{classname}}Service get{{classname}}() { + return service; + } +} diff --git a/src/main/resources/v2/JavaJaxRS/apiServiceImpl.mustache b/src/main/resources/v2/JavaJaxRS/apiServiceImpl.mustache new file mode 100644 index 0000000000..bc577e6f60 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/apiServiceImpl.mustache @@ -0,0 +1,32 @@ +package {{package}}.impl; + +import {{package}}.*; +import {{modelPackage}}.*; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}}ServiceImpl extends {{classname}}Service { + {{#operation}} + @Override + public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext) throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/beanValidation.mustache b/src/main/resources/v2/JavaJaxRS/beanValidation.mustache new file mode 100644 index 0000000000..c8c6946fef --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/beanValidation.mustache @@ -0,0 +1,4 @@ +{{#required}} + @NotNull +{{/required}} +{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/beanValidationCore.mustache b/src/main/resources/v2/JavaJaxRS/beanValidationCore.mustache new file mode 100644 index 0000000000..7c0e107796 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/beanValidationCore.mustache @@ -0,0 +1,20 @@ +{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#is this 'integer'}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/is}}{{! +isLong set +}}{{#is this 'long'}}{{#minimum}} @Min({{minimum}}L){{/minimum}}{{#maximum}} @Max({{maximum}}L){{/maximum}}{{/is}}{{! +Not Integer, not Long => we have a decimal value! +}}{{#isNot this 'integer'}}{{#isNot this 'long'}}{{#minimum}} @DecimalMin("{{minimum}}"){{/minimum}}{{#maximum}} @DecimalMax("{{maximum}}"){{/maximum}}{{/isNot}}{{/isNot}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/beanValidationPathParams.mustache b/src/main/resources/v2/JavaJaxRS/beanValidationPathParams.mustache new file mode 100644 index 0000000000..051bd53c0a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/beanValidationPathParams.mustache @@ -0,0 +1 @@ +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/beanValidationQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/beanValidationQueryParams.mustache new file mode 100644 index 0000000000..f8eef8f94c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/beanValidationQueryParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/bodyParams.mustache b/src/main/resources/v2/JavaJaxRS/bodyParams.mustache new file mode 100644 index 0000000000..ab6c2a25cc --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/bodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/bootstrap.mustache b/src/main/resources/v2/JavaJaxRS/bootstrap.mustache new file mode 100644 index 0000000000..f7e8efff41 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/bootstrap.mustache @@ -0,0 +1,31 @@ +package {{apiPackage}}; + +import io.swagger.jaxrs.config.SwaggerContextService; +import io.swagger.models.*; + +import io.swagger.models.auth.*; + +import javax.servlet.http.HttpServlet; +import javax.servlet.ServletContext; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; + +public class Bootstrap extends HttpServlet { + @Override + public void init(ServletConfig config) throws ServletException { + Info info = new Info() + .title("{{title}}") + .description("{{{appDescription}}}") + .termsOfService("{{termsOfService}}") + .contact(new Contact() + .email("{{infoEmail}}")) + .license(new License() + .name("{{licenseInfo}}") + .url("{{licenseUrl}}")); + + ServletContext context = config.getServletContext(); + Swagger swagger = new Swagger().info(info); + + new SwaggerContextService().withServletConfig(config).updateSwagger(swagger); + } +} diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/RestApplication.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/RestApplication.mustache new file mode 100644 index 0000000000..d3d8b238d7 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/RestApplication.mustache @@ -0,0 +1,9 @@ +package {{invokerPackage}}; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/") +public class RestApplication extends Application { + // Add implementation-specific details here +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/allowableValues.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/allowableValues.mustache new file mode 100644 index 0000000000..d8b42439fa --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/allowableValues.mustache @@ -0,0 +1 @@ +{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^@last}}, {{/@last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/api.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/api.mustache new file mode 100644 index 0000000000..93c76e5f6e --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/api.mustache @@ -0,0 +1,60 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +import {{package}}.{{classname}}Service; + +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +import io.swagger.annotations.*; +import java.io.InputStream; + +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; + +import java.util.Map; +import java.util.List; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +@Path("/{{{baseName}}}") +@RequestScoped + +@Api(description = "the {{{baseName}}} API") +{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} +{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} +{{>generatedAnnotation}} + +public class {{classname}} { + + @Context SecurityContext securityContext; + + @Inject {{classname}}Service delegate; + +{{#operations}} +{{#operation}} + + @{{httpMethod}} + {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} + {{#has this 'consumes'}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/has}} + {{#has this 'produces'}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/has}} + @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@Authorization(value = "{{name}}"{{#is this 'oauth'}}, scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/is}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#has this 'more'}},{{/has}}{{/responses}} }) + public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#has this 'more'}}, {{/has}}{{/allParams}}) { + return delegate.{{nickname}}({{#allParams}}{{#is this 'file'}}{{paramName}}InputStream, {{paramName}}Detail{{/is}}{{#isNot this 'file'}}{{paramName}}{{/isNot}}, {{/allParams}}securityContext); + } +{{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/apiService.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/apiService.mustache new file mode 100644 index 0000000000..4af44698b7 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/apiService.mustache @@ -0,0 +1,26 @@ +package {{package}}; + +import {{package}}.*; +import {{modelPackage}}.*; + +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +{{>generatedAnnotation}} +{{#operations}} +public interface {{classname}}Service { + {{#operation}} + public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext); + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/apiServiceImpl.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/apiServiceImpl.mustache new file mode 100644 index 0000000000..bce7fe5e93 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/apiServiceImpl.mustache @@ -0,0 +1,31 @@ +package {{package}}.impl; + +import {{package}}.*; +import {{modelPackage}}.*; + +import org.apache.cxf.jaxrs.ext.multipart.Attachment; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; + +import java.io.InputStream; + +import javax.enterprise.context.RequestScoped; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +@RequestScoped +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}}ServiceImpl implements {{classname}}Service { + {{#operation}} + @Override + public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext) { + // do some magic! + return Response.ok().entity("magic!").build(); + } + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidation.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidation.mustache new file mode 100644 index 0000000000..c8c6946fef --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidation.mustache @@ -0,0 +1,4 @@ +{{#required}} + @NotNull +{{/required}} +{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationCore.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationCore.mustache new file mode 100644 index 0000000000..7c0e107796 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationCore.mustache @@ -0,0 +1,20 @@ +{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#is this 'integer'}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/is}}{{! +isLong set +}}{{#is this 'long'}}{{#minimum}} @Min({{minimum}}L){{/minimum}}{{#maximum}} @Max({{maximum}}L){{/maximum}}{{/is}}{{! +Not Integer, not Long => we have a decimal value! +}}{{#isNot this 'integer'}}{{#isNot this 'long'}}{{#minimum}} @DecimalMin("{{minimum}}"){{/minimum}}{{#maximum}} @DecimalMax("{{maximum}}"){{/maximum}}{{/isNot}}{{/isNot}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationPathParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationPathParams.mustache new file mode 100644 index 0000000000..051bd53c0a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationPathParams.mustache @@ -0,0 +1 @@ +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationQueryParams.mustache new file mode 100644 index 0000000000..f8eef8f94c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beanValidationQueryParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/beans.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beans.mustache new file mode 100644 index 0000000000..cb6d500d43 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/beans.mustache @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/bodyParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/bodyParams.mustache new file mode 100644 index 0000000000..ab6c2a25cc --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/bodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/enumClass.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/enumClass.mustache new file mode 100644 index 0000000000..8468ae2cfe --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/enumClass.mustache @@ -0,0 +1,33 @@ +@XmlType(name="{{datatypeWithEnum}}") +@XmlEnum({{datatype}}.class) +public enum {{datatypeWithEnum}} { + + {{#allowableValues}} + {{#enumVars}}@XmlEnumValue({{{value}}}) {{name}}({{datatype}}.valueOf({{{value}}})){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}} + {{/allowableValues}} + + + private {{datatype}} value; + + {{datatypeWithEnum}} ({{datatype}} v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static {{datatypeWithEnum}} fromValue(String v) { + for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { + if (String.valueOf(b.value).equals(v)) { + return b; + } + } + return null; + } +} diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/formParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/formParams.mustache new file mode 100644 index 0000000000..0416b8f100 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/formParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}@Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}} @Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) InputStream {{paramName}}InputStream, @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/generatedAnnotation.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/generatedAnnotation.mustache new file mode 100644 index 0000000000..a47b6faa85 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/generatedAnnotation.mustache @@ -0,0 +1 @@ +{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/headerParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/headerParams.mustache new file mode 100644 index 0000000000..4af80acc1c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/headerParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/model.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/model.mustache new file mode 100644 index 0000000000..4f404cc293 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/model.mustache @@ -0,0 +1,16 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{#models}} +{{#model}}{{#description}} +/** + * {{description}} + **/{{/description}} +{{#is this 'enum'}}{{>enumClass}}{{/is}} +{{#isNot this 'enum'}}{{>pojo}}{{/isNot}} +{{/model}} +{{/models}} diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/pathParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/pathParams.mustache new file mode 100644 index 0000000000..06cb6ada6a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/pathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/pojo.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/pojo.mustache new file mode 100644 index 0000000000..4395a40a67 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/pojo.mustache @@ -0,0 +1,84 @@ +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; + +{{#description}}@ApiModel(description = "{{{description}}}"){{/description}} + +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { + {{#vars}}{{#is this 'enum'}} + +{{>enumClass}}{{/is}}{{#is items 'enum'}}{{#items}} + +{{>enumClass}}{{/items}}{{/is}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + {{#vars}} + /** + {{#description}} + * {{description}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + **/ + public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + return this; + } + + {{#vendorExtensions.extraAnnotation}}{{{vendorExtensions.extraAnnotation}}}{{/vendorExtensions.extraAnnotation}} + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + @JsonProperty("{{baseName}}") +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{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; + } + {{classname}} {{classVarName}} = ({{classname}}) o;{{#has this 'vars'}} + return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#has this 'more'}} && + {{/has}}{{#hasNot this 'more'}};{{/hasNot}}{{/vars}}{{/has}}{{#hasNot this 'vars'}} + return true;{{/hasNot}} + } + + @Override + public int hashCode() { + return Objects.hash({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}); + } + + @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/src/main/resources/v2/JavaJaxRS/cxf-cdi/pom.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/pom.mustache new file mode 100644 index 0000000000..99a7dea415 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/pom.mustache @@ -0,0 +1,92 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + war + {{artifactId}} + {{artifactVersion}} + + + + src/main/java + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + maven-war-plugin + 3.1.0 + + false + + + + + + + + + + javax + javaee-api + 7.0 + provided + + + + + org.apache.cxf + cxf-rt-frontend-jaxrs + + + 3.0.2 + provided + + + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + [2.8.3,3) + + + + + io.swagger + swagger-annotations + [1.5.3,1.5.16] + + +{{#useBeanValidation}} + + + javax.validation + validation-api + 1.1.0.Final + provided + +{{/useBeanValidation}} + + + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/queryParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/queryParams.mustache new file mode 100644 index 0000000000..20c8963601 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/queryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{#defaultValue}}@DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceBodyParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceBodyParams.mustache new file mode 100644 index 0000000000..c7433bffe8 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceBodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceFormParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceFormParams.mustache new file mode 100644 index 0000000000..da025ecf17 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceFormParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}}InputStream {{paramName}}InputStream, Attachment {{paramName}}Detail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceHeaderParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceHeaderParams.mustache new file mode 100644 index 0000000000..835635d68c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceHeaderParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/servicePathParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/servicePathParams.mustache new file mode 100644 index 0000000000..30eb348564 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/servicePathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceQueryParams.mustache new file mode 100644 index 0000000000..228fec8252 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf-cdi/serviceQueryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/CXF2InterfaceComparator.mustache b/src/main/resources/v2/JavaJaxRS/cxf/CXF2InterfaceComparator.mustache new file mode 100644 index 0000000000..d1fd0bf82c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/CXF2InterfaceComparator.mustache @@ -0,0 +1,120 @@ +package {{package}}; + + +import java.lang.reflect.Method; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.Path; + +import org.apache.cxf.jaxrs.ext.ResourceComparator; +import org.apache.cxf.jaxrs.model.ClassResourceInfo; +import org.apache.cxf.jaxrs.model.OperationResourceInfo; +import org.apache.cxf.message.Message; + +/** + * This class only help CXF to decide which resource interface is more suitable. It used Java reflexion to iterate over Java methods but it *DO NOT* select the target method. + */ +public class CXFInterfaceComparator implements ResourceComparator { + + private static final Logger LOGGER = LoggerFactory.getLogger(CXFInterfaceComparator.class); + + @Override + public int compare(ClassResourceInfo cri1, ClassResourceInfo cri2, Message message) { + String requestVerb = (String) message.get(Message.HTTP_REQUEST_METHOD); + String requestURI = (String) message.get(Message.REQUEST_URI); + String requestPath = requestURI.replace((String) message.get(Message.BASE_PATH), ""); + + // remove "/"at the end of requestPath if present + if (requestPath.endsWith("/")){ + requestPath = requestPath.substring(0, requestPath.length()-1); + } + + if (analyseInterface(cri1, requestPath, requestVerb)) { + return -1; // Indicate that 'cri1' interface should be preferred + } else if (analyseInterface(cri2, requestPath, requestVerb)) { + return 1; // Indicate that 'cri2' interface should be preferred + } else { + return 0; // Nothing match, leave CXF decision + } + } + + /** + * Analyse each methods provided to check if there is a match with the + * message request path and request HTTP verb. + * + * @param cri + * the interface to be analysed + * @param requestPath + * the path of the request. Do not contains the host and base + * path + * @return true if a method match the request, false otherwise + */ + private static boolean analyseInterface(ClassResourceInfo cri, String requestPath, String requestVerb) { + assert cri.getServiceClass() != null; + assert cri.getServiceClass().getInterfaces() != null; + assert cri.getServiceClass().getInterfaces()[0] != null; + assert cri.getServiceClass().getInterfaces()[0].getMethods().length > 0; + + Method[] methods = cri.getServiceClass().getInterfaces()[0].getMethods(); + // Java reflexion. Check all the methods of an interface. + for (Method method : methods) { + Path pathAnnotation = method.getAnnotation(javax.ws.rs.Path.class); + if (pathAnnotation != null && pathAnnotation.value() != null) { + String pathValue = pathAnnotation.value(); + String methodHttpVerb = getMethodHttpVerb(method); + + // Always authorize OPTIONS request if the path is matching a method declaration + if (requestVerb.equals(HttpMethod.OPTIONS) && match(pathValue,requestPath)) { + return true; + } + // Also check the HTTP verb since a single path can be match do multiple request, depending of the HTTP request verb. + if (requestVerb.equals(methodHttpVerb) && match(pathValue, requestPath)) { + return true; + } + } + } + return false; + } + + private static String getMethodHttpVerb(Method method) { + if (method.getAnnotation(javax.ws.rs.POST.class) != null) { + return HttpMethod.POST; + } else if (method.getAnnotation(javax.ws.rs.GET.class) != null) { + return HttpMethod.GET; + } else if (method.getAnnotation(javax.ws.rs.PUT.class) != null) { + return HttpMethod.PUT; + } else if (method.getAnnotation(javax.ws.rs.OPTIONS.class) != null) { + return HttpMethod.OPTIONS; + } else if (method.getAnnotation(javax.ws.rs.DELETE.class) != null) { + return HttpMethod.DELETE; + } else if (method.getAnnotation(javax.ws.rs.HEAD.class) != null) { + return HttpMethod.HEAD; + } + assert false; + return null; + } + + /** + * Check whether if the pathValue match with the requestPath parameter. + * Every path params are considered to be declared as '{param}'. The tokens to start and close path params declaration are '{' and '}'. + * + * @param valueFromAnnotation + * @param valueFromRequest + * @return true if there is a match, false otherwise + */ + private static boolean match(String valueFromAnnotation, String valueFromRequest) { + String patternFinal = valueFromAnnotation.replaceAll("\\{(.*?)\\}", "([^/]*)").replace("/", "\\/"); + Matcher matcher = Pattern.compile(patternFinal).matcher(valueFromRequest); + if (matcher.matches()) { + return true; + } + return false; + } + + @Override + public int compare(OperationResourceInfo ori1, OperationResourceInfo ori2, Message message) { + return 0; // Leave CXF decision + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/allowableValues.mustache b/src/main/resources/v2/JavaJaxRS/cxf/allowableValues.mustache new file mode 100644 index 0000000000..d8b42439fa --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/allowableValues.mustache @@ -0,0 +1 @@ +{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^@last}}, {{/@last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/api.mustache b/src/main/resources/v2/JavaJaxRS/cxf/api.mustache new file mode 100644 index 0000000000..acb31e003f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/api.mustache @@ -0,0 +1,70 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.MediaType; +import org.apache.cxf.jaxrs.ext.multipart.*; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.ApiResponse; +import io.swagger.jaxrs.PATCH; +{{#useBeanValidation}} +import javax.validation.constraints.*; +import javax.validation.Valid; +{{/useBeanValidation}} + +{{#appName}} +/** + * {{{appName}}} + * + {{#appDescription}} + *

{{{appDescription}}} + * + {{/appDescription}} + */ +{{/appName}} +@Path("{{^useAnnotatedBasePath}}/{{/useAnnotatedBasePath}}{{#useAnnotatedBasePath}}{{contextPath}}{{/useAnnotatedBasePath}}") +@Api(value = "/", description = "{{description}}") +{{#addConsumesProducesJson}} +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +{{/addConsumesProducesJson}} +public interface {{classname}} { +{{#operations}} +{{#operation}} + + {{#summary}} + /** + * {{summary}} + * + {{#notes}} + * {{notes}} + * + {{/notes}} + */ + {{/summary}} + @{{httpMethod}} + {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} +{{#has this 'consumes'}} + @Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }) +{{/has}} +{{#has this 'produces'}} + @Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }) +{{/has}} + @ApiOperation(value = "{{{summary}}}", tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{^vendorExtensions.x-java-is-response-void}}, response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}{{/vendorExtensions.x-java-is-response-void}}){{#has this 'more'}},{{/has}}{{/responses}} }) + public {{>returnTypes}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#has this 'more'}}, {{/has}}{{/allParams}}); +{{/operation}} +} +{{/operations}} + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/apiServiceImpl.mustache b/src/main/resources/v2/JavaJaxRS/cxf/apiServiceImpl.mustache new file mode 100644 index 0000000000..6fd8f006aa --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/apiServiceImpl.mustache @@ -0,0 +1,60 @@ +package {{package}}.impl; + +import {{package}}.*; +{{#imports}}import {{import}}; +{{/imports}} + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import org.apache.cxf.jaxrs.model.wadl.Description; +import org.apache.cxf.jaxrs.model.wadl.DocTarget; + +import org.apache.cxf.jaxrs.ext.multipart.*; + +import io.swagger.annotations.Api; +{{#useSpringAnnotationConfig}} +import org.springframework.stereotype.Service; +{{/useSpringAnnotationConfig}} + +{{#useSpringAnnotationConfig}} +@Service("{{classname}}") +{{/useSpringAnnotationConfig}} +{{#description}} +{{/description}} +{{#appName}} +/** + * {{{appName}}} + * + {{#appDescription}} + *

{{{appDescription}}} + {{/appDescription}} + * + */ +{{/appName}} +public class {{classname}}ServiceImpl implements {{classname}} { +{{#operations}} +{{#operation}} + {{#summary}} + /** + * {{summary}} + * + {{#notes}} + * {{notes}} + * + {{/notes}} + */ + {{/summary}} + public {{>returnTypes}} {{nickname}}({{#allParams}}{{>queryParamsImpl}}{{>pathParamsImpl}}{{>headerParamsImpl}}{{>bodyParamsImpl}}{{>formParamsImpl}}{{#has this 'more'}}, {{/has}}{{/allParams}}) { + // TODO: Implement... + + {{#useGenericResponse}}return Response.ok().entity("magic!").build();{{/useGenericResponse}}{{^useGenericResponse}}{{^vendorExtensions.x-java-is-response-void}}return null;{{/vendorExtensions.x-java-is-response-void}}{{/useGenericResponse}} + } + +{{/operation}} +} +{{/operations}} + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/api_test.mustache b/src/main/resources/v2/JavaJaxRS/cxf/api_test.mustache new file mode 100644 index 0000000000..074c20054c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/api_test.mustache @@ -0,0 +1,125 @@ +{{>licenseInfo}} + +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +import org.junit.Test; +import org.junit.Before; +import static org.junit.Assert.*; + +import javax.ws.rs.core.Response; +import org.apache.cxf.jaxrs.client.JAXRSClientFactory; +import org.apache.cxf.jaxrs.client.ClientConfiguration; +import org.apache.cxf.jaxrs.client.WebClient; +{{#useGzipFeature}} +import org.apache.cxf.transport.common.gzip.GZIPInInterceptor; +import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor; +{{/useGzipFeature}} + +{{#useLoggingFeature}} +import org.apache.cxf.interceptor.LoggingOutInterceptor; +{{/useLoggingFeature}} + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + +{{^fullJavaUtil}} +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +{{/fullJavaUtil}} + +{{#generateSpringBootApplication}} +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +{{/generateSpringBootApplication}} + + + +/** + {{#appName}} + * {{{appName}}} + * + {{/appName}} + {{#appDescription}} + *

{{{appDescription}}} + * + {{/appDescription}} + * API tests for {{classname}} + */ +{{#generateSpringBootApplication}} +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringBootApplication.class) +@WebAppConfiguration +@IntegrationTest("server.port=0") +{{/generateSpringBootApplication}} +public class {{classname}}Test { + +{{#generateSpringBootApplication}} + @Value("${local.server.port}") + private int serverPort; +{{/generateSpringBootApplication}} + + private {{classname}} api; + + @Before + public void setup() { + JacksonJsonProvider provider = new JacksonJsonProvider(); + List providers = new ArrayList(); + providers.add(provider); + +{{#generateSpringBootApplication}} + api = JAXRSClientFactory.create("http://localhost:" + serverPort + "/services", {{classname}}.class, providers); +{{/generateSpringBootApplication}} +{{^generateSpringBootApplication}} + api = JAXRSClientFactory.create("{{{basePath}}}", {{classname}}.class, providers); +{{/generateSpringBootApplication}} + org.apache.cxf.jaxrs.client.Client client = WebClient.client(api); + + ClientConfiguration config = WebClient.getConfig(client); +{{#useGzipFeatureForTests}} + // Example for using Gzipping + GZIPOutInterceptor gzipOutInterceptor = new GZIPOutInterceptor(); + // use Gzipping for first request sent to server + //gzipOutInterceptor.setForce(true); + config.getOutInterceptors().add(gzipOutInterceptor); + + config.getInInterceptors().add(new GZIPInInterceptor()); +{{/useGzipFeatureForTests}} +{{#useLoggingFeatureForTests}} + LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor(); + config.getOutInterceptors().add(loggingOutInterceptor); +{{/useLoggingFeatureForTests}} + } + + {{#operations}}{{#operation}} + /** + {{#summary}} + * {{summary}} + * + {{#notes}} + * {{notes}} + * + {{/notes}} + {{/summary}} + * @throws ApiException + * if the Api call fails + */ + @Test + public void {{operationId}}Test() { + {{#allParams}} + {{#isNot this 'file'}}{{{dataType}}} {{paramName}} = null;{{/isNot}}{{#is this 'file'}}org.apache.cxf.jaxrs.ext.multipart.Attachment {{paramName}} = null;{{/is}} + {{/allParams}} + //{{^vendorExtensions.x-java-is-response-void}}{{>returnTypes}} response = {{/vendorExtensions.x-java-is-response-void}}api.{{operationId}}({{#allParams}}{{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}}); + {{^vendorExtensions.x-java-is-response-void}}//assertNotNull(response);{{/vendorExtensions.x-java-is-response-void}} + // TODO: test validations + + + } + {{/operation}}{{/operations}} +} diff --git a/src/main/resources/v2/JavaJaxRS/cxf/beanValidation.mustache b/src/main/resources/v2/JavaJaxRS/cxf/beanValidation.mustache new file mode 100644 index 0000000000..c8c6946fef --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/beanValidation.mustache @@ -0,0 +1,4 @@ +{{#required}} + @NotNull +{{/required}} +{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/beanValidationCore.mustache b/src/main/resources/v2/JavaJaxRS/cxf/beanValidationCore.mustache new file mode 100644 index 0000000000..7c0e107796 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/beanValidationCore.mustache @@ -0,0 +1,20 @@ +{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#is this 'integer'}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/is}}{{! +isLong set +}}{{#is this 'long'}}{{#minimum}} @Min({{minimum}}L){{/minimum}}{{#maximum}} @Max({{maximum}}L){{/maximum}}{{/is}}{{! +Not Integer, not Long => we have a decimal value! +}}{{#isNot this 'integer'}}{{#isNot this 'long'}}{{#minimum}} @DecimalMin("{{minimum}}"){{/minimum}}{{#maximum}} @DecimalMax("{{maximum}}"){{/maximum}}{{/isNot}}{{/isNot}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/beanValidationPathParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf/beanValidationPathParams.mustache new file mode 100644 index 0000000000..051bd53c0a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/beanValidationPathParams.mustache @@ -0,0 +1 @@ +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/beanValidationQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf/beanValidationQueryParams.mustache new file mode 100644 index 0000000000..f8eef8f94c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/beanValidationQueryParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/bodyParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf/bodyParams.mustache new file mode 100644 index 0000000000..1b0cae179a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/bodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}{{#useBeanValidation}}@Valid {{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/bodyParamsImpl.mustache b/src/main/resources/v2/JavaJaxRS/cxf/bodyParamsImpl.mustache new file mode 100644 index 0000000000..c7433bffe8 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/bodyParamsImpl.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/enumClass.mustache b/src/main/resources/v2/JavaJaxRS/cxf/enumClass.mustache new file mode 100644 index 0000000000..2662e8e1c3 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/enumClass.mustache @@ -0,0 +1,33 @@ +@XmlType(name="{{datatypeWithEnum}}") +@XmlEnum({{datatype}}.class) +public enum {{datatypeWithEnum}} { + + {{#allowableValues}} +{{#enumVars}}@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) {{name}}({{datatype}}.valueOf({{{value}}})){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}} + {{/allowableValues}} + + + private {{datatype}} value; + + {{datatypeWithEnum}} ({{datatype}} v) { + value = v; + } + + public {{datatype}} value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static {{datatypeWithEnum}} fromValue(String v) { + for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { + if (String.valueOf(b.value).equals(v)) { + return b; + } + } + return null; + } +} diff --git a/src/main/resources/v2/JavaJaxRS/cxf/enumOuterClass.mustache b/src/main/resources/v2/JavaJaxRS/cxf/enumOuterClass.mustache new file mode 100644 index 0000000000..41ee748ef5 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/enumOuterClass.mustache @@ -0,0 +1,48 @@ +{{#jackson}} +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +{{/jackson}} + +/** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} + */ +public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { + {{#if 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}} + {{/if}} + {{#unless gson}} + {{#allowableValues}}{{#enumVars}} + {{{name}}}({{{value}}}){{^@last}}, + {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}} + {{/unless}} + + private {{{dataType}}} value; + + {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) { + this.value = value; + } + + @Override +{{#jackson}} + @JsonValue +{{/jackson}} + public String toString() { + return String.valueOf(value); + } + +{{#jackson}} + @JsonCreator +{{/jackson}} + 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/src/main/resources/v2/JavaJaxRS/cxf/formParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf/formParams.mustache new file mode 100644 index 0000000000..114e75a7b4 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/formParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}@Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}} @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/formParamsImpl.mustache b/src/main/resources/v2/JavaJaxRS/cxf/formParamsImpl.mustache new file mode 100644 index 0000000000..f71c62f71f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/formParamsImpl.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}} Attachment {{paramName}}Detail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/generatedAnnotation.mustache b/src/main/resources/v2/JavaJaxRS/cxf/generatedAnnotation.mustache new file mode 100644 index 0000000000..49110fc1ad --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/generatedAnnotation.mustache @@ -0,0 +1 @@ +@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}") \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/headerParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf/headerParams.mustache new file mode 100644 index 0000000000..076cccc2fb --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/headerParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/headerParamsImpl.mustache b/src/main/resources/v2/JavaJaxRS/cxf/headerParamsImpl.mustache new file mode 100644 index 0000000000..835635d68c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/headerParamsImpl.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/licenseInfo.mustache b/src/main/resources/v2/JavaJaxRS/cxf/licenseInfo.mustache new file mode 100644 index 0000000000..861d97234c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/licenseInfo.mustache @@ -0,0 +1,23 @@ +/** + * {{{appName}}} + * {{{appDescription}}} + * + * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} + * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + */ diff --git a/src/main/resources/v2/JavaJaxRS/cxf/model.mustache b/src/main/resources/v2/JavaJaxRS/cxf/model.mustache new file mode 100644 index 0000000000..20e40f7f1a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/model.mustache @@ -0,0 +1,18 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} + +{{#models}} +{{#model}} +{{#is this 'enum'}} +{{>enumOuterClass}} +{{/is}} +{{#isNot this 'enum'}} +{{>pojo}} +{{/isNot}} +{{/model}} +{{/models}} diff --git a/src/main/resources/v2/JavaJaxRS/cxf/pathParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf/pathParams.mustache new file mode 100644 index 0000000000..52f80cb09a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/pathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}@PathParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/pathParamsImpl.mustache b/src/main/resources/v2/JavaJaxRS/cxf/pathParamsImpl.mustache new file mode 100644 index 0000000000..30eb348564 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/pathParamsImpl.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/pojo.mustache b/src/main/resources/v2/JavaJaxRS/cxf/pojo.mustache new file mode 100644 index 0000000000..ba9320cadf --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/pojo.mustache @@ -0,0 +1,127 @@ +import io.swagger.annotations.ApiModelProperty; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import com.fasterxml.jackson.annotation.JsonProperty; + +{{#withXml}} +@XmlAccessorType(XmlAccessType.FIELD) +{{#has this 'vars'}} @XmlType(name = "{{classname}}", propOrder = + { {{#vars}}"{{name}}"{{^@last}}, {{/@last}}{{/vars}} +}){{/has}} +{{#hasNot this 'vars'}}@XmlType(name = "{{classname}}"){{/hasNot}} +{{^parent}}@XmlRootElement(name="{{classname}}"){{/parent}} +{{/withXml}} +{{#description}} +/** + * {{{description}}} + **/ +@ApiModel(description="{{{description}}}") +{{/description}} +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { + {{#vars}}{{#is this 'enum'}}{{#isNot this 'container'}} + +{{>enumClass}}{{/isNot}}{{/is}}{{#is items 'enum'}}{{#items}} + +{{#isNot this 'container'}}{{>enumClass}}{{/isNot}}{{/items}}{{/is}} +{{#withXml}} + @XmlElement(name="{{baseName}}"{{#required}}, required = {{required}}{{/required}}) +{{/withXml}} + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") +{{#description}} + /** + * {{{description}}} + **/ +{{/description}} +{{#is this 'container'}} + private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}}; +{{/is}} +{{#isNot this 'container'}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}}; +{{/isNot}} + {{/vars}} + {{#vars}} + /** + {{#description}} + * {{description}} + {{/description}} + {{^description}} + * Get {{name}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + * @return {{name}} + **/ + @JsonProperty("{{baseName}}") +{{#vendorExtensions.extraAnnotation}} + {{{vendorExtensions.extraAnnotation}}} +{{/vendorExtensions.extraAnnotation}} +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{#is this 'enum'}}{{^isListContainer}}{{^isMapContainer}}public {{datatype}} {{#is this 'boolean'}}is{{/is}}{{getter}}() { + if ({{name}} == null) { + return null; + } + return {{name}}.value(); + }{{/isMapContainer}}{{/isListContainer}}{{/is}}{{#is this 'enum'}}{{#isListContainer}}public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{getter}}() { + return {{name}}; + }{{/isListContainer}}{{/is}}{{#is this 'enum'}}{{#isMapContainer}}public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{getter}}() { + return {{name}}; + }{{/isMapContainer}}{{/is}}{{#isNot this 'enum'}}public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{getter}}() { + return {{name}}; + }{{/isNot}} + + {{^isReadOnly}} + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + } + + 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}} + {{/isReadOnly}} + + {{/vars}} + + @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 static String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/resources/v2/JavaJaxRS/cxf/pom.mustache b/src/main/resources/v2/JavaJaxRS/cxf/pom.mustache new file mode 100644 index 0000000000..d31376757b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/pom.mustache @@ -0,0 +1,204 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{#appDescription}} + {{appDescription}} + {{/appDescription}} + {{artifactVersion}} + + src/main/java + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + + io.swagger + swagger-jaxrs + compile + ${swagger-core-version} + + + ch.qos.logback + logback-classic + ${logback-version} + compile + + + ch.qos.logback + logback-core + ${logback-version} + compile + + + junit + junit + ${junit-version} + test + +{{#useBeanValidation}} + + + javax.validation + validation-api + ${beanvalidation-version} + provided + +{{/useBeanValidation}} + + + org.apache.cxf + cxf-rt-rs-client + ${cxf-version} + test + + + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${cxf-version} + compile + + + org.apache.cxf + cxf-rt-rs-service-description + ${cxf-version} + compile + + + org.apache.cxf + cxf-rt-ws-policy + ${cxf-version} + compile + + + org.apache.cxf + cxf-rt-wsdl + ${cxf-version} + compile + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + ${jackson-jaxrs-version} + compile + +{{#java8}} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-jaxrs-version} + +{{/java8}} +{{^java8}} + + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson-jaxrs-version} + +{{/java8}} +{{#useBeanValidationFeature}} + + org.hibernate + hibernate-validator + 5.2.2.Final + +{{/useBeanValidationFeature}} + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + ${java.version} + ${java.version} + 1.5.18 + 9.2.9.v20150224 + 4.12 + 1.1.7 + 2.5 +{{#useBeanValidation}} + 1.1.0.Final +{{/useBeanValidation}} + 3.2.1 + 2.9.1 + UTF-8 + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/queryParams.mustache b/src/main/resources/v2/JavaJaxRS/cxf/queryParams.mustache new file mode 100644 index 0000000000..f44898c40a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/queryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#defaultValue}}@DefaultValue("{{{defaultValue}}}") {{/defaultValue}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/queryParamsImpl.mustache b/src/main/resources/v2/JavaJaxRS/cxf/queryParamsImpl.mustache new file mode 100644 index 0000000000..228fec8252 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/queryParamsImpl.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/returnTypes.mustache b/src/main/resources/v2/JavaJaxRS/cxf/returnTypes.mustache new file mode 100644 index 0000000000..6af86ffe4e --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/returnTypes.mustache @@ -0,0 +1,4 @@ +{{#useGenericResponse}}Response{{/useGenericResponse}}{{! non-generic response: +}}{{^useGenericResponse}}{{! +}}{{{returnType}}}{{! +}}{{/useGenericResponse}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/ApplicationContext.xml.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/ApplicationContext.xml.mustache new file mode 100644 index 0000000000..b4cdc5b6cf --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/ApplicationContext.xml.mustache @@ -0,0 +1,149 @@ + + + + + + + + +{{#useMultipartFeature}} + +{{/useMultipartFeature}} + + +{{#useSpringAnnotationConfig}} + + +{{/useSpringAnnotationConfig}} +{{^useSpringAnnotationConfig}} +{{#apiInfo}} +{{#apis}} + +{{/apis}} +{{/apiInfo}} +{{/useSpringAnnotationConfig}} + +{{#useSwaggerFeature}} + + {{! http://cxf.apache.org/docs/swagger2feature.html }} + + +{{#useSwaggerUI}} + +{{/useSwaggerUI}} + + +{{/useSwaggerFeature}} + + + +{{#useGzipFeature}} + +{{/useGzipFeature}} +{{#useBeanValidationFeature}} + + +{{/useBeanValidationFeature}} + + +{{#useGzipFeature}} + +{{/useGzipFeature}} +{{#useBeanValidationFeature}} + + +{{/useBeanValidationFeature}} + + +{{#useLoggingFeature}} + +{{/useLoggingFeature}} +{{#useGzipFeature}} + +{{/useGzipFeature}} + + + + + + +{{#useWadlFeature}} + + + +{{/useWadlFeature}} + +{{#useGzipFeature}} + + + + + + + +{{/useGzipFeature}} + +{{#useBeanValidationFeature}} + + + + + + + + + + + +{{/useBeanValidationFeature}} +{{^useBeanValidationFeature}} + + + +{{/useBeanValidationFeature}} + + + + +{{#apiInfo}} +{{#apis}} + +{{/apis}} +{{/apiInfo}} + + + +{{#useMultipartFeature}} + +{{/useMultipartFeature}} +{{#useWadlFeature}} + +{{/useWadlFeature}} + + +{{#useSwaggerFeature}} + +{{/useSwaggerFeature}} +{{#useBeanValidationFeature}} + +{{/useBeanValidationFeature}} + + + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/SpringBootApplication.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/SpringBootApplication.mustache new file mode 100644 index 0000000000..f6d08e7129 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/SpringBootApplication.mustache @@ -0,0 +1,23 @@ +package {{apiPackage}}; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; +import org.springframework.context.annotation.ImportResource; + +@ImportResource({"classpath:/ApplicationContext.xml"}) +@EnableAutoConfiguration +public class SpringBootApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SpringBootApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(SpringBootApplication.class, args); + } + + +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/application.properties.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/application.properties.mustache new file mode 100644 index 0000000000..dae5715173 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/application.properties.mustache @@ -0,0 +1 @@ +cxf.path=/ \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/context.xml.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/context.xml.mustache new file mode 100644 index 0000000000..a14b9a13d0 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/context.xml.mustache @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/jboss-web.xml.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/jboss-web.xml.mustache new file mode 100644 index 0000000000..ef688c10e9 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/jboss-web.xml.mustache @@ -0,0 +1,7 @@ + + + + + swagger-cxf-server + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/nonspring-web.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/nonspring-web.mustache new file mode 100644 index 0000000000..d47da9810b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/nonspring-web.mustache @@ -0,0 +1,26 @@ + + + + + CXF Non-Spring Jaxrs Servlet + CXFNonSpringJaxrsServlet + org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet +{{#apiInfo}} + + jaxrs.serviceClasses + {{#apis}}{{package}}.impl.{{classname}}ServiceImpl{{^@last}},{{/@last}}{{/apis}} + +{{/apiInfo}} + + jaxrs.providers + com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider + + + + + CXFNonSpringJaxrsServlet + /rest/* + + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/pom.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/pom.mustache new file mode 100644 index 0000000000..e75e19c0c4 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/pom.mustache @@ -0,0 +1,261 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + war + {{artifactId}} + {{#appDescription}} + {{appDescription}} + {{/appDescription}} + {{artifactVersion}} + + src/main/java + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + maven-war-plugin + 3.1.0 + + false + + + + + + + io.swagger + swagger-jaxrs + compile + ${swagger-core-version} + + + ch.qos.logback + logback-classic + ${logback-version} + compile + + + ch.qos.logback + logback-core + ${logback-version} + compile + + + junit + junit + ${junit-version} + test + +{{#useBeanValidation}} + + + javax.validation + validation-api + ${beanvalidation-version} + provided + +{{/useBeanValidation}} + + + org.apache.cxf + cxf-rt-rs-client + ${cxf-version} + test + + + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${cxf-version} + compile + + + org.apache.cxf + cxf-rt-rs-service-description + ${cxf-version} + compile + + + org.apache.cxf + cxf-rt-rs-service-description-swagger + ${cxf-version} + compile + + + org.apache.cxf + cxf-rt-ws-policy + ${cxf-version} + compile + + + org.apache.cxf + cxf-rt-wsdl + ${cxf-version} + compile + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + ${jackson-jaxrs-version} + compile + +{{#java8}} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-jaxrs-version} + +{{/java8}} +{{^java8}} + + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson-jaxrs-version} + +{{/java8}} +{{#generateSpringApplication}} + + + org.springframework + spring-context + ${spring-version} + + + org.springframework + spring-web + ${spring-version} + +{{/generateSpringApplication}} +{{#generateSpringBootApplication}} + + + org.springframework.boot + spring-boot-starter-tomcat + ${spring.boot-version} + provided + + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot-version} + test + + + + org.apache.cxf + cxf-spring-boot-starter-jaxrs + ${cxf-version} + provided + +{{/generateSpringBootApplication}} +{{#useSwaggerUI}} + + org.webjars + swagger-ui + 3.6.1 + +{{/useSwaggerUI}} + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + ${java.version} + ${java.version} + 1.5.18 + 9.2.9.v20150224 + 4.12 + 1.1.7 + 2.5 +{{#useBeanValidation}} + 1.1.0.Final +{{/useBeanValidation}} +{{#generateSpringApplication}} + 4.3.13.RELEASE +{{/generateSpringApplication}} +{{#generateSpringBootApplication}} + 1.5.9.RELEASE +{{/generateSpringBootApplication}} + 3.2.1 + 2.9.1 + UTF-8 + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/readme.md b/src/main/resources/v2/JavaJaxRS/cxf/server/readme.md new file mode 100644 index 0000000000..0f26af2212 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/readme.md @@ -0,0 +1,36 @@ + +# JAX-RS CXF 3 server application + +## Supported features +* Bean-Validation-API support +* Spring-configuration of Swagger, WADL and Endpoints +* Swagger-API is accessible (CXF3 Swagger2Feature) +* Swagger-UI can be included as Web-Jar automatically +* WADL is accessible (CXF WADL-Generator) +* Unit-tests include Gzip-Interceptors for demonstration + + +## Urls to access the REST API +### Urls for Spring Boot + +* Available services listing +http://localhost:8080/ + +* Swagger API + http://localhost:8080/services/swagger.json + +* CXF WADL + http://localhost:8080/services?_wadl + + +### Urls if deployed to an AS +* Available services listing +http://localhost:8080/swagger-cxf-server/rest/services/ + +* Swagger API + http://localhost:8080/swagger-cxf-server/rest/services/swagger.json + +* CXF WADL + http://localhost:8080/swagger-cxf-server/rest/services?_wadl + + diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/swagger-codegen-ignore.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/swagger-codegen-ignore.mustache new file mode 100644 index 0000000000..70b88e7103 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/swagger-codegen-ignore.mustache @@ -0,0 +1,25 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md + +**/impl/* \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/cxf/server/web.mustache b/src/main/resources/v2/JavaJaxRS/cxf/server/web.mustache new file mode 100644 index 0000000000..9d905ae076 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/cxf/server/web.mustache @@ -0,0 +1,23 @@ + + + + + contextConfigLocation + WEB-INF/context.xml + + + org.springframework.web.context.ContextLoaderListener + + + CXF Service Servlet + CXFServiceServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServiceServlet + /rest/* + + + diff --git a/src/main/resources/v2/JavaJaxRS/enumClass.mustache b/src/main/resources/v2/JavaJaxRS/enumClass.mustache new file mode 100644 index 0000000000..4e9f8f2a51 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/enumClass.mustache @@ -0,0 +1,44 @@ + /** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} + */ + public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { + {{#if 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}} + {{/if}} + {{#unless gson}} + {{#allowableValues}} + {{#enumVars}} + {{{name}}}({{{value}}}){{^@last}}, + {{/@last}}{{#@last}};{{/@last}} + {{/enumVars}} + {{/allowableValues}} + {{/unless}} + + 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/src/main/resources/v2/JavaJaxRS/enumOuterClass.mustache b/src/main/resources/v2/JavaJaxRS/enumOuterClass.mustache new file mode 100644 index 0000000000..c410202df8 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/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}} { + {{#if 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}} + {{/if}} + {{#unless gson}} + {{#allowableValues}}{{#enumVars}} + {{{name}}}({{{value}}}){{^@last}}, + {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}} + {{/unless}} + + 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/src/main/resources/v2/JavaJaxRS/formParams.mustache b/src/main/resources/v2/JavaJaxRS/formParams.mustache new file mode 100644 index 0000000000..13e1c6a5af --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/formParams.mustache @@ -0,0 +1,3 @@ +{{#is this 'form-param'}}{{#notFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#vendorExtensions.x-multipart}}@FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/notFile}}{{#is this 'file'}} + @FormDataParam("{{baseName}}") InputStream {{paramName}}InputStream, + @FormDataParam("{{baseName}}") FormDataContentDisposition {{paramName}}Detail{{/is}}{{/is}} diff --git a/src/main/resources/v2/JavaJaxRS/generatedAnnotation.mustache b/src/main/resources/v2/JavaJaxRS/generatedAnnotation.mustache new file mode 100644 index 0000000000..a47b6faa85 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/generatedAnnotation.mustache @@ -0,0 +1 @@ +{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/headerParams.mustache b/src/main/resources/v2/JavaJaxRS/headerParams.mustache new file mode 100644 index 0000000000..4af80acc1c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/headerParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/jacksonJsonProvider.mustache b/src/main/resources/v2/JavaJaxRS/jacksonJsonProvider.mustache new file mode 100644 index 0000000000..5fa284e809 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/jacksonJsonProvider.mustache @@ -0,0 +1,39 @@ +package {{apiPackage}}; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +{{#java8}} +import com.fasterxml.jackson.datatype.jsr310.*; +{{/java8}} +{{^java8}} +import com.fasterxml.jackson.datatype.joda.*; +{{/java8}} + +import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; + +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.ext.Provider; + +@Provider +@Produces({MediaType.APPLICATION_JSON}) +public class JacksonJsonProvider extends JacksonJaxbJsonProvider { + + public JacksonJsonProvider() { + + ObjectMapper objectMapper = new ObjectMapper() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) +{{#java8}} + .registerModule(new JavaTimeModule()) +{{/java8}} +{{^java8}} + .registerModule(new JodaModule()) +{{/java8}} + .setDateFormat(new RFC3339DateFormat()); + + setMapper(objectMapper); + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/LocalDateProvider.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/LocalDateProvider.mustache new file mode 100644 index 0000000000..8c4cd4cbd1 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/LocalDateProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import java.time.LocalDate; +import java.util.List; + +@Provider +public class LocalDateProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public LocalDateProvider(@Context UriInfo uriInfo) { + super(LocalDate.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public LocalDate getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return LocalDate.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/OffsetDateTimeProvider.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/OffsetDateTimeProvider.mustache new file mode 100644 index 0000000000..876aeb327b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/OffsetDateTimeProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import java.time.OffsetDateTime; +import java.util.List; + +@Provider +public class OffsetDateTimeProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public OffsetDateTimeProvider(@Context UriInfo uriInfo) { + super(OffsetDateTime.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public OffsetDateTime getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return OffsetDateTime.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/api.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/api.mustache new file mode 100644 index 0000000000..bea2feac4b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/api.mustache @@ -0,0 +1,63 @@ +package {{package}}; + +import {{modelPackage}}.*; +import {{package}}.{{classname}}Service; +import {{package}}.factories.{{classname}}ServiceFactory; + +import io.swagger.annotations.ApiParam; +import io.swagger.jaxrs.*; + +import com.sun.jersey.multipart.FormDataParam; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.Map; +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; + +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.*; + +@Path("/{{{baseName}}}") +{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} +{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} +@io.swagger.annotations.Api(description = "the {{{baseName}}} API") +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}} { + private final {{classname}}Service delegate = {{classname}}ServiceFactory.get{{classname}}(); + +{{#operation}} + @{{httpMethod}} + {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} + {{#has this 'consumes'}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/has}} + {{#has this 'produces'}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/has}} + @io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#is this 'oauth'}}, scopes = { + {{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/is}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) + @io.swagger.annotations.ApiResponses(value = { {{#responses}} + @io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#has this 'more'}},{{/has}}{{/responses}} }) + public Response {{nickname}}( + {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}, + {{/allParams}}@Context SecurityContext securityContext) + throws NotFoundException { + return delegate.{{nickname}}({{#allParams}}{{#is this 'file'}}inputStream, fileDetail{{/is}}{{#isNot this 'file'}}{{paramName}}{{/isNot}},{{/allParams}}securityContext); + } +{{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/apiService.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/apiService.mustache new file mode 100644 index 0000000000..0d3ab0ebe1 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/apiService.mustache @@ -0,0 +1,32 @@ +package {{package}}; + +import {{package}}.*; +import {{modelPackage}}.*; + +import com.sun.jersey.multipart.FormDataParam; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{>generatedAnnotation}} +{{#operations}} +public abstract class {{classname}}Service { + {{#operation}} + public abstract Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}},{{/allParams}}SecurityContext securityContext) + throws NotFoundException; + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/apiServiceImpl.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/apiServiceImpl.mustache new file mode 100644 index 0000000000..abe789f1cb --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/apiServiceImpl.mustache @@ -0,0 +1,36 @@ +package {{package}}.impl; + +import {{package}}.*; +import {{modelPackage}}.*; + +import com.sun.jersey.multipart.FormDataParam; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}}ServiceImpl extends {{classname}}Service { + {{#operation}} + @Override + public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/formParams.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/formParams.mustache new file mode 100644 index 0000000000..c22d1401bb --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/formParams.mustache @@ -0,0 +1,2 @@ +{{#is this 'form-param'}}{{#notFile}}{{^vendorExtensions.x-multipart}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/vendorExtensions.x-multipart}}{{#vendorExtensions.x-multipart}}@FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/notFile}}{{#is this 'file'}}@FormDataParam("{{baseName}}") InputStream inputStream, + @FormDataParam("{{baseName}}") FormDataContentDisposition fileDetail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/pom.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/pom.mustache new file mode 100644 index 0000000000..20dea2c312 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/pom.mustache @@ -0,0 +1,203 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{artifactVersion}} + + src/main/java + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty-version} + + + / + + target/${project.artifactId}-${project.version} + 8079 + stopit + 10 + + {{serverPort}} + 60000 + + + + + start-jetty + pre-integration-test + + start + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + + io.swagger + swagger-jersey-jaxrs + ${swagger-core-version} + + + 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} + + + com.sun.jersey.contribs + jersey-multipart + ${jersey-version} + + + com.sun.jersey + jersey-server + ${jersey-version} + + + javax.servlet + servlet-api + ${servlet-api-version} + + + + junit + junit + ${junit-version} + test + + + com.sun.jersey + jersey-client + ${jersey-version} + test + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson-version} + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + ${jackson-version} + + + org.testng + testng + 6.8.8 + test + + + junit + junit + + + snakeyaml + org.yaml + + + bsh + org.beanshell + + + +{{#useBeanValidation}} + + + javax.validation + validation-api + 1.1.0.Final + provided + +{{/useBeanValidation}} + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + ${java.version} + ${java.version} + 1.5.18 + 9.2.9.v20150224 + 1.19.1 + 2.8.9 + 1.7.21 + 4.12 + 2.5 + UTF-8 + + diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/project/build.properties b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/project/build.properties new file mode 100644 index 0000000000..a8c2f849be --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.12.0 diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey1/project/plugins.sbt b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/project/plugins.sbt new file mode 100644 index 0000000000..713b7f3e99 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/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/v2/JavaJaxRS/libraries/jersey1/web.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/web.mustache new file mode 100644 index 0000000000..2c859d04eb --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey1/web.mustache @@ -0,0 +1,54 @@ + + + + + jersey + com.sun.jersey.spi.container.servlet.ServletContainer + + com.sun.jersey.config.property.packages + io.swagger.jaxrs.json;io.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 + io.swagger.jaxrs.config.DefaultJaxrsConfig + + api.version + 1.0.0 + + + swagger.api.title + {{{title}}} + + + swagger.api.basepath + {{{basePath}}} + + 2 + + + + jersey + {{contextPath}}/* + + + ApiOriginFilter + {{apiPackage}}.ApiOriginFilter + + + ApiOriginFilter + /* + + diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey2/LocalDateProvider.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey2/LocalDateProvider.mustache new file mode 100644 index 0000000000..90a5fb6208 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey2/LocalDateProvider.mustache @@ -0,0 +1,28 @@ +package {{apiPackage}}; + +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; +import javax.ws.rs.ext.Provider; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.time.LocalDate; + +@Provider +public class LocalDateProvider implements ParamConverterProvider { + + public ParamConverter getConverter(Class clazz, Type type, Annotation[] annotations) { + if (clazz.getName().equals(LocalDate.class.getName())) { + return new ParamConverter() { + @SuppressWarnings("unchecked") + public T fromString(String value) { + return value!=null ? (T) LocalDate.parse(value) : null; + } + + public String toString(T bean) { + return bean!=null ? bean.toString() : ""; + } + }; + } + return null; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/libraries/jersey2/OffsetDateTimeProvider.mustache b/src/main/resources/v2/JavaJaxRS/libraries/jersey2/OffsetDateTimeProvider.mustache new file mode 100644 index 0000000000..fccb0deb16 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/libraries/jersey2/OffsetDateTimeProvider.mustache @@ -0,0 +1,28 @@ +package {{apiPackage}}; + +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; +import javax.ws.rs.ext.Provider; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.time.OffsetDateTime; + +@Provider +public class OffsetDateTimeProvider implements ParamConverterProvider { + + public ParamConverter getConverter(Class clazz, Type type, Annotation[] annotations) { + if (clazz.getName().equals(OffsetDateTime.class.getName())) { + return new ParamConverter() { + @SuppressWarnings("unchecked") + public T fromString(String value) { + return value != null ? (T) OffsetDateTime.parse(value) : null; + } + + public String toString(T bean) { + return bean != null ? bean.toString() : ""; + } + }; + } + return null; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/licenseInfo.mustache b/src/main/resources/v2/JavaJaxRS/licenseInfo.mustache new file mode 100644 index 0000000000..94c36dda3a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/licenseInfo.mustache @@ -0,0 +1,11 @@ +/* + * {{{appName}}} + * {{{appDescription}}} + * + * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} + * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ diff --git a/src/main/resources/v2/JavaJaxRS/model.mustache b/src/main/resources/v2/JavaJaxRS/model.mustache new file mode 100644 index 0000000000..8cd0a87aa6 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/model.mustache @@ -0,0 +1,24 @@ +{{>licenseInfo}} + +package {{package}}; + +{{^supportJava6}} +import java.util.Objects; +{{/supportJava6}} +{{#supportJava6}} +import org.apache.commons.lang3.ObjectUtils; +{{/supportJava6}} +{{#imports}}import {{import}}; +{{/imports}} +{{#serializableModel}} +import java.io.Serializable; +{{/serializableModel}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} + +{{#models}} +{{#model}} +{{#is this 'enum'}}{{>modelEnum}}{{/is}}{{#isNot this 'enum'}}{{>pojo}}{{/isNot}} +{{/model}} +{{/models}} diff --git a/src/main/resources/v2/JavaJaxRS/modelEnum.mustache b/src/main/resources/v2/JavaJaxRS/modelEnum.mustache new file mode 100644 index 0000000000..e7fb0dc0ca --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/modelEnum.mustache @@ -0,0 +1,43 @@ +{{#jackson}} +import com.fasterxml.jackson.annotation.JsonCreator; +{{/jackson}} + +/** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} + */ +public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { + {{#if 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}} + {{/if}} + {{#unless gson}} + {{#allowableValues}}{{#enumVars}} + {{{name}}}({{{value}}}){{^@last}}, + {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}} + {{/unless}} + + private {{{dataType}}} value; + + {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) { + this.value = value; + } + + @Override + public String toString() { + return String.valueOf(value); + } +{{#jackson}} + + @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; + } +{{/jackson}} +} diff --git a/src/main/resources/v2/JavaJaxRS/pathParams.mustache b/src/main/resources/v2/JavaJaxRS/pathParams.mustache new file mode 100644 index 0000000000..8149af1034 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/pathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/pojo.mustache b/src/main/resources/v2/JavaJaxRS/pojo.mustache new file mode 100644 index 0000000000..50721c63ee --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/pojo.mustache @@ -0,0 +1,165 @@ +/** + * {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}} + */{{#description}} +@ApiModel(description = "{{{description}}}"){{/description}} +{{>generatedAnnotation}} +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { + {{#vars}} + {{#is this 'enum'}} + {{#isNot this 'container'}} +{{>enumClass}} + {{/isNot}} + {{/is}} + {{#is items 'enum'}} + {{#items}} + {{#isNot this 'container'}} +{{>enumClass}} + {{/isNot}} + {{/items}} + {{/is}} + {{#jackson}} + @JsonProperty("{{baseName}}") + {{/jackson}} + {{#if gson}} + @SerializedName("{{baseName}}") + {{/if}} + {{#is this 'container'}} + private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}}; + {{/is}} + {{#isNot this 'container'}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}}; + {{/isNot}} + + {{/vars}} + {{#vars}} + {{^isReadOnly}} + public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + return this; + } + {{#isListContainer}} + + public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { + {{^required}} + if (this.{{name}} == null) { + this.{{name}} = {{{defaultValue}}}; + } + {{/required}} + this.{{name}}.add({{name}}Item); + return this; + } + {{/isListContainer}} + {{#isMapContainer}} + + public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { + {{^required}} + if (this.{{name}} == null) { + this.{{name}} = {{{defaultValue}}}; + } + {{/required}} + this.{{name}}.put(key, {{name}}Item); + return this; + } + {{/isMapContainer}} + + {{/isReadOnly}} + /** + {{#description}} + * {{description}} + {{/description}} + {{^description}} + * Get {{name}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + * @return {{name}} + **/ + {{#vendorExtensions.extraAnnotation}} + {{{vendorExtensions.extraAnnotation}}} + {{/vendorExtensions.extraAnnotation}} + {{#jackson}} + @JsonProperty("{{baseName}}") + {{/jackson}} + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{getter}}() { + return {{name}}; + } + {{^isReadOnly}} + + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + } + {{/isReadOnly}} + + {{/vars}} + +{{^supportJava6}} + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + }{{#has this 'vars'}} + {{classname}} {{classVarName}} = ({{classname}}) o; + return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#has this 'more'}} && + {{/has}}{{/vars}}{{#parent}} && + super.equals(o){{/parent}};{{/has}}{{#hasNot this 'vars'}} + return true;{{/hasNot}} + } + + @Override + public int hashCode() { + return Objects.hash({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}{{#parent}}{{#has this 'vars'}}, {{/has}}super.hashCode(){{/parent}}); + } + +{{/supportJava6}} +{{#supportJava6}} + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + }{{#has this 'vars'}} + {{classname}} {{classVarName}} = ({{classname}}) o; + return {{#vars}}ObjectUtils.equals(this.{{name}}, {{classVarName}}.{{name}}){{#has this 'more'}} && + {{/has}}{{/vars}}{{#parent}} && + super.equals(o){{/parent}};{{/has}}{{#hasNot this 'vars'}} + return true;{{/hasNot}} + } + + @Override + public int hashCode() { + return ObjectUtils.hashCodeMulti({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}{{#parent}}{{#has this 'vars'}}, {{/has}}super.hashCode(){{/parent}}); + } + +{{/supportJava6}} + + @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/src/main/resources/v2/JavaJaxRS/pom.mustache b/src/main/resources/v2/JavaJaxRS/pom.mustache new file mode 100644 index 0000000000..7ab35a399c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/pom.mustache @@ -0,0 +1,213 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{artifactVersion}} + + + + {{licenseName}} + {{licenseUrl}} + repo + + + + + src/main/java + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty-version} + + + / + + target/${project.artifactId}-${project.version} + 8079 + stopit + 10 + + {{serverPort}} + 60000 + + + + + start-jetty + pre-integration-test + + start + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + + io.swagger + swagger-jersey2-jaxrs + compile + ${swagger-core-version} + + + ch.qos.logback + logback-classic + ${logback-version} + compile + + + ch.qos.logback + logback-core + ${logback-version} + compile + + + junit + junit + ${junit-version} + test + + + javax.servlet + servlet-api + ${servlet-api-version} + + + org.glassfish.jersey.containers + jersey-container-servlet-core + ${jersey2-version} + + + org.glassfish.jersey.media + jersey-media-multipart + ${jersey2-version} + + {{#java8}} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-version} + + {{/java8}} + {{^java8}} + + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson-version} + + {{/java8}} + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + ${jackson-version} + + + + com.brsanthu + migbase64 + 2.2 + + + {{#supportJava6}} + + org.apache.commons + commons-lang3 + ${commons_lang3_version} + + + + commons-io + commons-io + ${commons_io_version} + + {{/supportJava6}} + +{{#useBeanValidation}} + + + javax.validation + validation-api + 1.1.0.Final + provided + +{{/useBeanValidation}} + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + ${java.version} + ${java.version} + 1.5.18 + 9.2.9.v20150224 + 2.22.2 + 2.8.9 + {{#supportJava6}} + 2.5 + 3.5 + {{/supportJava6}} + 4.12 + 1.1.7 + 2.5 + UTF-8 + + diff --git a/src/main/resources/v2/JavaJaxRS/queryParams.mustache b/src/main/resources/v2/JavaJaxRS/queryParams.mustache new file mode 100644 index 0000000000..7a9070cb40 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/queryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/ApiException.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/ApiException.mustache new file mode 100644 index 0000000000..f616114770 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/ApiException.mustache @@ -0,0 +1,10 @@ +package {{apiPackage}}; + +{{>generatedAnnotation}} +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/v2/JavaJaxRS/resteasy/ApiOriginFilter.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/ApiOriginFilter.mustache new file mode 100644 index 0000000000..090fd8cb55 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/ApiOriginFilter.mustache @@ -0,0 +1,22 @@ +package {{apiPackage}}; + +import java.io.IOException; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; + +{{>generatedAnnotation}} +public class ApiOriginFilter implements javax.servlet.Filter { + 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); + } + + public void destroy() {} + + public void init(FilterConfig filterConfig) throws ServletException {} +} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/ApiResponseMessage.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/ApiResponseMessage.mustache new file mode 100644 index 0000000000..f47a535094 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/ApiResponseMessage.mustache @@ -0,0 +1,69 @@ +package {{apiPackage}}; + +import javax.xml.bind.annotation.XmlTransient; + +@javax.xml.bind.annotation.XmlRootElement +{{>generatedAnnotation}} +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/v2/JavaJaxRS/resteasy/JacksonConfig.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/JacksonConfig.mustache new file mode 100644 index 0000000000..5a0da70233 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/JacksonConfig.mustache @@ -0,0 +1,47 @@ +package {{invokerPackage}}; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.fasterxml.jackson.datatype.joda.JodaModule; +import org.joda.time.DateTime; +import org.joda.time.LocalDate; +import org.joda.time.format.ISODateTimeFormat; + +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; +import java.io.IOException; + +@Provider +public class JacksonConfig implements ContextResolver { + private final ObjectMapper objectMapper; + + public JacksonConfig() throws Exception { + + objectMapper = new ObjectMapper() + .setDateFormat(new RFC3339DateFormat()) + .registerModule(new JodaModule() { + { + addSerializer(DateTime.class, new StdSerializer(DateTime.class) { + @Override + public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { + jgen.writeString(ISODateTimeFormat.dateTimeNoMillis().print(value)); + } + }); + addSerializer(LocalDate.class, new StdSerializer(LocalDate.class) { + @Override + public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { + jgen.writeString(ISODateTimeFormat.date().print(value)); + } + }); + + } + }); + } + + public ObjectMapper getContext(Class arg0) { + return objectMapper; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/JodaDateTimeProvider.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/JodaDateTimeProvider.mustache new file mode 100644 index 0000000000..74c24c8777 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/JodaDateTimeProvider.mustache @@ -0,0 +1,39 @@ +package {{apiPackage}}; + +import org.joda.time.DateTime; +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; +import javax.ws.rs.ext.Provider; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + + +@Provider +public class JodaDateTimeProvider implements ParamConverterProvider { + + public static class JodaDateTimeConverter implements ParamConverter { + + public DateTime fromString(String string) { + try { + DateTime dateTime = DateTime.parse(string); + return dateTime; + } catch (Exception e) { + throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). + entity(string + " must be valid DateTime").build()); + } + } + + public String toString(DateTime t) { + return t.toString(); + } + } + + public ParamConverter getConverter(Class type, Type type1, Annotation[] antns) { + if (DateTime.class.equals(type)) { + return (ParamConverter) new JodaDateTimeConverter(); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/JodaLocalDateProvider.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/JodaLocalDateProvider.mustache new file mode 100644 index 0000000000..0b28c915dd --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/JodaLocalDateProvider.mustache @@ -0,0 +1,39 @@ +package {{apiPackage}}; + +import org.joda.time.LocalDate; +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; +import javax.ws.rs.ext.Provider; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + + +@Provider +public class JodaLocalDateProvider implements ParamConverterProvider { + + public static class JodaLocalDateConverter implements ParamConverter { + + public LocalDate fromString(String string) { + try { + LocalDate localDate = LocalDate.parse(string); + return localDate; + } catch (Exception e) { + throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). + entity(string + " must be valid LocalDate").build()); + } + } + + public String toString(LocalDate t) { + return t.toString(); + } + } + + public ParamConverter getConverter(Class type, Type type1, Annotation[] antns) { + if (LocalDate.class.equals(type)) { + return (ParamConverter) new JodaLocalDateConverter(); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/LocalDateProvider.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/LocalDateProvider.mustache new file mode 100644 index 0000000000..a57e3e7475 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/LocalDateProvider.mustache @@ -0,0 +1,31 @@ +package {{apiPackage}}; + +import java.time.LocalDate; +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; +import javax.ws.rs.ext.Provider; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +@Provider +public class LocalDateProvider implements ParamConverterProvider { + + public static class LocalDateConverter implements ParamConverter { + + public LocalDate fromString(String string) { + LocalDate localDate = LocalDate.parse(string); + return localDate; + } + + public String toString(LocalDate t) { + return t.toString(); + } + } + + public ParamConverter getConverter(Class type, Type type1, Annotation[] antns) { + if (LocalDate.class.equals(type)) { + return (ParamConverter) new LocalDateConverter(); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/NotFoundException.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/NotFoundException.mustache new file mode 100644 index 0000000000..40c25c5ea5 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/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/src/main/resources/v2/JavaJaxRS/resteasy/OffsetDateTimeProvider.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/OffsetDateTimeProvider.mustache new file mode 100644 index 0000000000..a3974c3c53 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/OffsetDateTimeProvider.mustache @@ -0,0 +1,31 @@ +package {{apiPackage}}; + +import java.time.OffsetDateTime; +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; +import javax.ws.rs.ext.Provider; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +@Provider +public class OffsetDateTimeProvider implements ParamConverterProvider { + + public static class OffsetDateTimeConverter implements ParamConverter { + + public OffsetDateTime fromString(String string) { + OffsetDateTime offsetDateTime = OffsetDateTime.parse(string); + return offsetDateTime; + } + + public String toString(OffsetDateTime t) { + return t.toString(); + } + } + + public ParamConverter getConverter(Class type, Type type1, Annotation[] antns) { + if (OffsetDateTime.class.equals(type)) { + return (ParamConverter) new OffsetDateTimeConverter(); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/README.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/README.mustache new file mode 100644 index 0000000000..3551b9e991 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/README.mustache @@ -0,0 +1,23 @@ +# Swagger generated server + +## Overview +This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the +[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +is an example of building a swagger-enabled JAX-RS server. + +This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework. + +To run the server, please execute the following: + +``` +mvn clean package jetty:run +``` + +You can then view the swagger listing here: + +``` +http://localhost:{{serverPort}}{{contextPath}}/swagger.json +``` + +Note that if you have configured the `host` to be something other than localhost, the calls through +swagger-ui will be directed to that host and not localhost! \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/RFC3339DateFormat.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/RFC3339DateFormat.mustache new file mode 100644 index 0000000000..11dc552692 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/RFC3339DateFormat.mustache @@ -0,0 +1,19 @@ +package {{invokerPackage}}; + +import com.fasterxml.jackson.databind.util.ISO8601DateFormat; +import com.fasterxml.jackson.databind.util.ISO8601Utils; + +import java.text.FieldPosition; +import java.util.Date; + +public class RFC3339DateFormat extends ISO8601DateFormat { + + // Same as ISO8601DateFormat but serializing milliseconds. + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + String value = ISO8601Utils.format(date, true); + toAppendTo.append(value); + return toAppendTo; + } + +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/RestApplication.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/RestApplication.mustache new file mode 100644 index 0000000000..df9a31434b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/RestApplication.mustache @@ -0,0 +1,9 @@ +package {{invokerPackage}}; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/") +public class RestApplication extends Application { + +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/StringUtil.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/StringUtil.mustache new file mode 100644 index 0000000000..073966b0c2 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/StringUtil.mustache @@ -0,0 +1,42 @@ +package {{invokerPackage}}; + +{{>generatedAnnotation}} +public class StringUtil { + /** + * Check if the given array contains the given value (with case-insensitive comparison). + * + * @param array The array + * @param value The value to search + * @return true if the array contains the value + */ + public static boolean containsIgnoreCase(String[] array, String value) { + for (String str : array) { + if (value == null && str == null) return true; + if (value != null && value.equalsIgnoreCase(str)) return true; + } + return false; + } + + /** + * Join an array of strings with the given separator. + *

+ * Note: This might be replaced by utility method from commons-lang or guava someday + * if one of those libraries is added as dependency. + *

+ * + * @param array The array of strings + * @param separator The separator + * @return the resulting string + */ + public static String join(String[] array, String separator) { + int len = array.length; + if (len == 0) return ""; + + StringBuilder out = new StringBuilder(); + out.append(array[0]); + for (int i = 1; i < len; i++) { + out.append(separator).append(array[i]); + } + return out.toString(); + } +} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/allowableValues.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/allowableValues.mustache new file mode 100644 index 0000000000..d8b42439fa --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/allowableValues.mustache @@ -0,0 +1 @@ +{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^@last}}, {{/@last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/api.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/api.mustache new file mode 100644 index 0000000000..43630cb8b2 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/api.mustache @@ -0,0 +1,60 @@ +package {{package}}; + +import {{modelPackage}}.*; +import {{package}}.{{classname}}Service; + +import io.swagger.annotations.ApiParam; +import io.swagger.jaxrs.*; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.Map; +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.*; +import javax.inject.Inject; + +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; +{{/isMultipart}}{{/operation}}{{/operations}} +@Path("/{{{baseName}}}") +{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} +{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} +@io.swagger.annotations.Api(description = "the {{{baseName}}} API") +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}} { + + @Inject {{classname}}Service service; + +{{#operation}} + @{{httpMethod}} + {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} + {{#has this 'consumes'}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/has}} + {{#has this 'produces'}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/has}} + @io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#is this 'oauth'}}, scopes = { + {{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/is}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) + @io.swagger.annotations.ApiResponses(value = { {{#responses}} + @io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#has this 'more'}}, + {{/has}}{{/responses}} }) + public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{^isMultipart}}{{>formParams}},{{/isMultipart}}{{#isMultipart}}{{#isNot this 'form-param'}},{{/isNot}}{{/isMultipart}}{{/allParams}}@Context SecurityContext securityContext) + throws NotFoundException { + return service.{{nickname}}({{#isMultipart}}input,{{/isMultipart}}{{#allParams}}{{^isMultipart}}{{paramName}},{{/isMultipart}}{{#isMultipart}}{{#isNot this 'form-param'}}{{paramName}},{{/isNot}}{{/isMultipart}}{{/allParams}}securityContext); + } +{{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/apiService.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/apiService.mustache new file mode 100644 index 0000000000..bbc880d329 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/apiService.mustache @@ -0,0 +1,27 @@ +package {{package}}; + +import {{package}}.*; +import {{modelPackage}}.*; +{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; +{{/isMultipart}}{{/operation}}{{/operations}} + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +{{>generatedAnnotation}} +{{#operations}} +public interface {{classname}}Service { + {{#operation}} + Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{#isNot this 'form-param'}},{{/isNot}}{{/isMultipart}}{{/allParams}}SecurityContext securityContext) + throws NotFoundException; + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/apiServiceImpl.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/apiServiceImpl.mustache new file mode 100644 index 0000000000..e4631cc76b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/apiServiceImpl.mustache @@ -0,0 +1,32 @@ +package {{package}}.impl; + +import {{package}}.*; +import {{modelPackage}}.*; +{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; +{{/isMultipart}}{{/operation}}{{/operations}} + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import {{package}}.NotFoundException; + +import java.io.InputStream; + +import javax.enterprise.context.RequestScoped; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +@RequestScoped +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}}ServiceImpl implements {{classname}}Service { + {{#operation}} + public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{#isNot this 'form-param'}},{{/isNot}}{{/isMultipart}}{{/allParams}}SecurityContext securityContext) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/beanValidation.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidation.mustache new file mode 100644 index 0000000000..c8c6946fef --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidation.mustache @@ -0,0 +1,4 @@ +{{#required}} + @NotNull +{{/required}} +{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationCore.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationCore.mustache new file mode 100644 index 0000000000..7c0e107796 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationCore.mustache @@ -0,0 +1,20 @@ +{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#is this 'integer'}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/is}}{{! +isLong set +}}{{#is this 'long'}}{{#minimum}} @Min({{minimum}}L){{/minimum}}{{#maximum}} @Max({{maximum}}L){{/maximum}}{{/is}}{{! +Not Integer, not Long => we have a decimal value! +}}{{#isNot this 'integer'}}{{#isNot this 'long'}}{{#minimum}} @DecimalMin("{{minimum}}"){{/minimum}}{{#maximum}} @DecimalMax("{{maximum}}"){{/maximum}}{{/isNot}}{{/isNot}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationPathParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationPathParams.mustache new file mode 100644 index 0000000000..051bd53c0a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationPathParams.mustache @@ -0,0 +1 @@ +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationQueryParams.mustache new file mode 100644 index 0000000000..f8eef8f94c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/beanValidationQueryParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/bodyParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/bodyParams.mustache new file mode 100644 index 0000000000..ab6c2a25cc --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/bodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/JacksonConfig.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/JacksonConfig.mustache new file mode 100644 index 0000000000..923d26477d --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/JacksonConfig.mustache @@ -0,0 +1,44 @@ +package {{invokerPackage}}; + +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; +{{#java8}} +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +{{/java8}} +{{^java8}} +import com.fasterxml.jackson.datatype.joda.JodaModule; +{{/java8}} + +@Provider +@Produces(MediaType.APPLICATION_JSON) +public class JacksonConfig implements ContextResolver { + + private static final Logger LOG = LoggerFactory.getLogger(JacksonConfig.class); + + private ObjectMapper objectMapper; + + public JacksonConfig() throws Exception { + this.objectMapper = new ObjectMapper(); + +{{#java8}} + this.objectMapper.registerModule(new JavaTimeModule()); +{{/java8}} +{{^java8}} + this.objectMapper.registerModule(new JodaModule()); +{{/java8}} + + // sample to convert any DateTime to readable timestamps + //this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true); + } + + public ObjectMapper getContext(Class objectType) { + return objectMapper; + } +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/README.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/README.mustache new file mode 100644 index 0000000000..a0396fc361 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/README.mustache @@ -0,0 +1,19 @@ +# Swagger generated server + +## Overview +This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the +[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +is an example of building a swagger-enabled JAX-RS server. + +This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework for Jboss Resteasy. + +You can deploy the WAR file to Jboss EAP or any other JEE server supporting Jboss Resteasy. + +You can then view the swagger listing here: + +``` +http://localhost:{{serverPort}}{{contextPath}}/swagger.json +``` + +Note that if you have configured the `host` to be something other than localhost, the calls through +swagger-ui will be directed to that host and not localhost! \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/RestApplication.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/RestApplication.mustache new file mode 100644 index 0000000000..cdab3c0830 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/RestApplication.mustache @@ -0,0 +1,55 @@ +package {{invokerPackage}}; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +import java.util.Set; +import java.util.HashSet; +{{#useSwaggerFeature}} +import io.swagger.jaxrs.config.BeanConfig; +{{/useSwaggerFeature}} + +{{#apiInfo}} +{{#apis}} +import {{package}}.impl.{{classname}}ServiceImpl; +{{/apis}} +{{/apiInfo}} + +@ApplicationPath("/") +public class RestApplication extends Application { + +{{#useSwaggerFeature}} + public RestApplication() { + super(); + // Customize the dynamic contract + BeanConfig beanConfig = new BeanConfig(); + beanConfig.setTitle("{{appName}}"); + beanConfig.setVersion("{{version}}"); + beanConfig.setSchemes(new String[] { "{{scheme}}" }); + beanConfig.setHost("{{host}}"); + beanConfig.setBasePath("{{basePathWithoutHost}}"); + beanConfig.setResourcePackage("{{invokerPackage}}"); + beanConfig.setScan(true); + + } +{{/useSwaggerFeature}} + + public Set> getClasses() { + Set> resources = new HashSet>(); +{{#apiInfo}} +{{#apis}} + resources.add({{classname}}ServiceImpl.class); +{{/apis}} +{{/apiInfo}} + +{{#useSwaggerFeature}} + resources.add(io.swagger.jaxrs.listing.ApiListingResource.class); + resources.add(io.swagger.jaxrs.listing.SwaggerSerializers.class); +{{/useSwaggerFeature}} + return resources; + } + + + + +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/api.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/api.mustache new file mode 100644 index 0000000000..87b589942f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/api.mustache @@ -0,0 +1,51 @@ +package {{package}}; + +import {{modelPackage}}.*; + +import io.swagger.annotations.ApiParam; +import io.swagger.jaxrs.*; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import java.util.Map; + +import java.io.InputStream; + +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.*; +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; +{{/isMultipart}}{{/operation}}{{/operations}} +@Path("/{{{baseName}}}") +{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} +{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} +@io.swagger.annotations.Api(description = "the {{{baseName}}} API") +{{>generatedAnnotation}} +{{#operations}} +public interface {{classname}} { + +{{#operation}} + @{{httpMethod}} + {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} + {{#has this 'consumes'}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/has}} + {{#has this 'produces'}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/has}} + @io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#is this 'oauth'}}, scopes = { + {{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/is}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) + @io.swagger.annotations.ApiResponses(value = { {{#responses}} + @io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#has this 'more'}}, + {{/has}}{{/responses}} }) + public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{^isMultipart}}{{>formParams}},{{/isMultipart}}{{#isMultipart}}{{#isNot this 'form-param'}},{{/isNot}}{{/isMultipart}}{{/allParams}}@Context SecurityContext securityContext); +{{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/apiServiceImpl.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/apiServiceImpl.mustache new file mode 100644 index 0000000000..45382501cc --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/apiServiceImpl.mustache @@ -0,0 +1,28 @@ +package {{package}}.impl; + +import {{package}}.*; +import {{modelPackage}}.*; +{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; +{{/isMultipart}}{{/operation}}{{/operations}} + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}}ServiceImpl implements {{classname}} { + {{#operation}} + public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{#isNot this 'form-param'}},{{/isNot}}{{/isMultipart}}{{/allParams}}SecurityContext securityContext) { + // do some magic! + return Response.ok().build(); + } + {{/operation}} +} +{{/operations}} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/beanValidation.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/beanValidation.mustache new file mode 100644 index 0000000000..cba488e41b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/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}} +{{#is this 'integer'}} +{{#minimum}} + @Min({{minimum}}) +{{/minimum}} +{{#maximum}} + @Max({{maximum}}) +{{/maximum}} +{{/is}} +{{#isNot this 'integer'}} +{{#minimum}} + @DecimalMin("{{minimum}}") +{{/minimum}} +{{#maximum}} + @DecimalMax("{{maximum}}") +{{/maximum}} +{{/isNot}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/beanValidationPathParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/beanValidationPathParams.mustache new file mode 100644 index 0000000000..0b4d31b4bf --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/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/src/main/resources/v2/JavaJaxRS/resteasy/eap/beanValidationQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/beanValidationQueryParams.mustache new file mode 100644 index 0000000000..4bad1be636 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/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/src/main/resources/v2/JavaJaxRS/resteasy/eap/bodyParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/bodyParams.mustache new file mode 100644 index 0000000000..ab6c2a25cc --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/bodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/enumClass.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/enumClass.mustache new file mode 100644 index 0000000000..ca4431a72a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/enumClass.mustache @@ -0,0 +1,24 @@ + /** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} + */ + public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { + {{#allowableValues}} + {{#enumVars}} + {{{name}}}({{{value}}}){{^@last}}, + + {{/@last}}{{#@last}}; + {{/@last}} + {{/enumVars}} + {{/allowableValues}} + private {{datatype}} value; + + {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + } diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/enumOuterClass.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/enumOuterClass.mustache new file mode 100644 index 0000000000..0ea67b7248 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/enumOuterClass.mustache @@ -0,0 +1,7 @@ +public enum {{classname}} { + {{#allowableValues}} + {{#enumVars}} + {{{name}}}{{^@last}},{{/@last}}{{#@last}};{{/@last}} + {{/enumVars}} + {{/allowableValues}} +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/formParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/formParams.mustache new file mode 100644 index 0000000000..94460d3f70 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/formParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/generatedAnnotation.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/generatedAnnotation.mustache new file mode 100644 index 0000000000..a47b6faa85 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/generatedAnnotation.mustache @@ -0,0 +1 @@ +{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/gradle.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/gradle.mustache new file mode 100644 index 0000000000..60f4d69117 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/gradle.mustache @@ -0,0 +1,38 @@ +apply plugin: 'war' + +project.version = "{{artifactVersion}}" +project.group = "{{groupId}}" + +repositories { + mavenCentral() +} + +dependencies { + providedCompile 'org.jboss.resteasy:resteasy-jaxrs:3.0.11.Final' + providedCompile 'org.jboss.resteasy:jaxrs-api:3.0.11.Final' + providedCompile 'org.jboss.resteasy:resteasy-validator-provider-11:3.0.11.Final' + providedCompile 'org.jboss.resteasy:resteasy-multipart-provider:3.0.11.Final' + providedCompile 'javax.annotation:javax.annotation-api:1.2' + providedCompile 'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final' + compile 'org.jboss.resteasy:resteasy-jackson2-provider:3.0.11.Final' +{{#useBeanValidation}} + providedCompile 'javax.validation:validation-api:1.1.0.Final' +{{/useBeanValidation}} +{{^java8}} + compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.6.3' + compile 'joda-time:joda-time:2.7' +{{/java8}} +{{#java8}} + compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.3' +{{/java8}} + testCompile 'junit:junit:4.12', + 'org.hamcrest:hamcrest-core:1.3' +} + +sourceSets { + main { + java { + srcDir 'src/gen/java' + } + } +} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/headerParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/headerParams.mustache new file mode 100644 index 0000000000..4af80acc1c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/headerParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/jboss-web.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/jboss-web.mustache new file mode 100644 index 0000000000..788fc867d9 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/jboss-web.mustache @@ -0,0 +1,3 @@ + + {{contextPath}} + \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/model.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/model.mustache new file mode 100644 index 0000000000..cb48311dff --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/model.mustache @@ -0,0 +1,22 @@ +package {{package}}; + +import java.util.Objects; +import java.util.ArrayList; +{{#imports}}import {{import}}; +{{/imports}} +{{#serializableModel}} +import java.io.Serializable; +{{/serializableModel}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{#models}} +{{#model}} +{{#is this 'enum'}} +{{>enumOuterClass}} +{{/is}} +{{#isNot this 'enum'}} +{{>pojo}} +{{/isNot}} +{{/model}} +{{/models}} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/pathParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/pathParams.mustache new file mode 100644 index 0000000000..10ebafc92b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/pathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}} @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/pojo.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/pojo.mustache new file mode 100644 index 0000000000..3391b9e32a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/pojo.mustache @@ -0,0 +1,79 @@ +import io.swagger.annotations.*; + +{{#description}}@ApiModel(description="{{{description}}}"){{/description}} +{{>generatedAnnotation}} +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { +{{#serializableModel}} + private static final long serialVersionUID = 1L; +{{/serializableModel}} + {{#vars}}{{#is this 'enum'}} + +{{>enumClass}}{{/is}}{{#is items 'enum'}}{{#items}} + +{{>enumClass}}{{/items}}{{/is}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + {{#vars}} + /** + {{#description}} + * {{description}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + **/ + {{#vendorExtensions.extraAnnotation}}{{{vendorExtensions.extraAnnotation}}}{{/vendorExtensions.extraAnnotation}} + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + @JsonProperty("{{baseName}}") +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{getter}}() { + return {{name}}; + } + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + } + + {{/vars}} + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + {{classname}} {{classVarName}} = ({{classname}}) o;{{#has this 'vars'}} + return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#has this 'more'}} && + {{/has}}{{#hasNot this 'more'}};{{/hasNot}}{{/vars}}{{/has}}{{#hasNot this 'vars'}} + return true;{{/hasNot}} + } + + @Override + public int hashCode() { + return Objects.hash({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}); + } + + @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(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/pom.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/pom.mustache new file mode 100644 index 0000000000..11c25090ad --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/pom.mustache @@ -0,0 +1,188 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + war + {{artifactId}} + {{artifactVersion}} + + src/main/java + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + + src/gen/java + + + + + + + + + + org.slf4j + slf4j-log4j12 + ${slf4j-version} + + + javax.servlet + servlet-api + ${servlet-api-version} + provided + + + + org.jboss.resteasy + resteasy-jaxrs + ${resteasy-version} + provided + + + org.jboss.resteasy + jaxrs-api + ${resteasy-version} + provided + + + org.jboss.resteasy + resteasy-validator-provider-11 + ${resteasy-version} + provided + + + org.jboss.resteasy + resteasy-multipart-provider + ${resteasy-version} + provided + + + org.jboss.resteasy + resteasy-jackson2-provider + ${resteasy-version} + provided + + + javax.annotation + javax.annotation-api + 1.2 + provided + + + + io.swagger + swagger-jaxrs + ${swagger-core-version} + + + junit + junit + ${junit-version} + test + + + org.testng + testng + 6.8.8 + test + + + junit + junit + + + snakeyaml + org.yaml + + + bsh + org.beanshell + + + +{{#useBeanValidation}} + + + javax.validation + validation-api + 1.1.0.Final + provided + +{{/useBeanValidation}} +{{^java8}} + + joda-time + joda-time + 2.7 + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + 2.6.3 + +{{/java8}} +{{#java8}} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.6.3 + +{{/java8}} + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + 1.5.18 + 9.2.9.v20150224 + 3.0.11.Final + 1.6.3 + 4.8.1 + 2.5 + + diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/queryParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/queryParams.mustache new file mode 100644 index 0000000000..0f8d4995af --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/queryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceBodyParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceBodyParams.mustache new file mode 100644 index 0000000000..c7433bffe8 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceBodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceFormParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceFormParams.mustache new file mode 100644 index 0000000000..430fd19848 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceFormParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}}FormDataContentDisposition fileDetail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceHeaderParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceHeaderParams.mustache new file mode 100644 index 0000000000..835635d68c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceHeaderParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/servicePathParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/servicePathParams.mustache new file mode 100644 index 0000000000..30eb348564 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/servicePathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceQueryParams.mustache new file mode 100644 index 0000000000..228fec8252 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/serviceQueryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/settingsGradle.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/settingsGradle.mustache new file mode 100644 index 0000000000..b8fd6c4c41 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/settingsGradle.mustache @@ -0,0 +1 @@ +rootProject.name = "{{artifactId}}" \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/eap/web.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/eap/web.mustache new file mode 100644 index 0000000000..be8e25fc2c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/eap/web.mustache @@ -0,0 +1,9 @@ + + + + resteasy.providers + {{invokerPackage}}.JacksonConfig + + diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/enumClass.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/enumClass.mustache new file mode 100644 index 0000000000..ca4431a72a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/enumClass.mustache @@ -0,0 +1,24 @@ + /** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} + */ + public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { + {{#allowableValues}} + {{#enumVars}} + {{{name}}}({{{value}}}){{^@last}}, + + {{/@last}}{{#@last}}; + {{/@last}} + {{/enumVars}} + {{/allowableValues}} + private {{datatype}} value; + + {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + } diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/enumOuterClass.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/enumOuterClass.mustache new file mode 100644 index 0000000000..fd5a5a3f5f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/enumOuterClass.mustache @@ -0,0 +1,3 @@ +public enum {{classname}} { + {{#allowableValues}}{{.}}{{^@last}}, {{/@last}}{{/allowableValues}} +} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/formParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/formParams.mustache new file mode 100644 index 0000000000..94460d3f70 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/formParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/generatedAnnotation.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/generatedAnnotation.mustache new file mode 100644 index 0000000000..a47b6faa85 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/generatedAnnotation.mustache @@ -0,0 +1 @@ +{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/gradle.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/gradle.mustache new file mode 100644 index 0000000000..65d748762c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/gradle.mustache @@ -0,0 +1,38 @@ +apply plugin: 'war' + +project.version = "{{artifactVersion}}" +project.group = "{{groupId}}" + +repositories { + mavenCentral() +} + +dependencies { + providedCompile 'org.jboss.resteasy:resteasy-jaxrs:3.0.11.Final' + providedCompile 'org.jboss.resteasy:jaxrs-api:3.0.11.Final' + providedCompile 'org.jboss.resteasy:resteasy-validator-provider-11:3.0.11.Final' + providedCompile 'org.jboss.resteasy:resteasy-multipart-provider:3.0.11.Final' + providedCompile 'javax.annotation:javax.annotation-api:1.2' + providedCompile 'javax:javaee-api:7.0' + providedCompile 'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final' + compile 'io.swagger:swagger-annotations:1.5.10' + compile 'org.jboss.resteasy:resteasy-jackson2-provider:3.0.11.Final' +{{#useBeanValidation}} + providedCompile 'javax.validation:validation-api:1.1.0.Final' +{{/useBeanValidation}} + compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.1' + compile 'joda-time:joda-time:2.7' + //TODO: swaggerFeature + compile 'io.swagger:swagger-jaxrs:1.5.12' + + testCompile 'junit:junit:4.12', + 'org.hamcrest:hamcrest-core:1.3' +} + +sourceSets { + main { + java { + srcDir 'src/gen/java' + } + } +} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/headerParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/headerParams.mustache new file mode 100644 index 0000000000..4af80acc1c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/headerParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/jboss-web.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/jboss-web.mustache new file mode 100644 index 0000000000..788fc867d9 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/jboss-web.mustache @@ -0,0 +1,3 @@ + + {{contextPath}} + \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/model.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/model.mustache new file mode 100644 index 0000000000..cb48311dff --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/model.mustache @@ -0,0 +1,22 @@ +package {{package}}; + +import java.util.Objects; +import java.util.ArrayList; +{{#imports}}import {{import}}; +{{/imports}} +{{#serializableModel}} +import java.io.Serializable; +{{/serializableModel}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} +{{#models}} +{{#model}} +{{#is this 'enum'}} +{{>enumOuterClass}} +{{/is}} +{{#isNot this 'enum'}} +{{>pojo}} +{{/isNot}} +{{/model}} +{{/models}} diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/pathParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/pathParams.mustache new file mode 100644 index 0000000000..10ebafc92b --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/pathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}} @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/pojo.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/pojo.mustache new file mode 100644 index 0000000000..ebbbaf8c86 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/pojo.mustache @@ -0,0 +1,79 @@ +import io.swagger.annotations.*; + +{{#description}}@ApiModel(description="{{{description}}}"){{/description}} +{{>generatedAnnotation}} +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { +{{#serializableModel}} + private static final long serialVersionUID = 1L; +{{/serializableModel}} + {{#vars}}{{#is this 'enum'}}{{#isNot this 'container'}} + +{{>enumClass}}{{/isNot}}{{/is}}{{#is items 'enum'}}{{#items}} + +{{#isNot this 'container'}}{{>enumClass}}{{/isNot}}{{/items}}{{/is}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + {{#vars}} + /** + {{#description}} + * {{description}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + **/ + {{#vendorExtensions.extraAnnotation}}{{{vendorExtensions.extraAnnotation}}}{{/vendorExtensions.extraAnnotation}} + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + @JsonProperty("{{baseName}}") +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{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; + } + {{classname}} {{classVarName}} = ({{classname}}) o;{{#has this 'vars'}} + return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#has this 'more'}} && + {{/has}}{{#hasNot this 'more'}};{{/hasNot}}{{/vars}}{{/has}}{{#hasNot this 'vars'}} + return true;{{/hasNot}} + } + + @Override + public int hashCode() { + return Objects.hash({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}); + } + + @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/src/main/resources/v2/JavaJaxRS/resteasy/pom.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/pom.mustache new file mode 100644 index 0000000000..d8e8fb2c63 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/pom.mustache @@ -0,0 +1,192 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + war + {{artifactId}} + {{artifactVersion}} + + src/main/java + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + + src/gen/java + + + + + + + + + + + javax + javaee-api + 7.0 + provided + + + + io.swagger + swagger-annotations + ${swagger-core-version} + + + org.slf4j + slf4j-log4j12 + ${slf4j-version} + + + javax.servlet + servlet-api + ${servlet-api-version} + provided + + + + org.jboss.resteasy + resteasy-jaxrs + ${resteasy-version} + provided + + + org.jboss.resteasy + jaxrs-api + ${resteasy-version} + provided + + + org.jboss.resteasy + resteasy-validator-provider-11 + ${resteasy-version} + provided + + + org.jboss.resteasy + resteasy-multipart-provider + ${resteasy-version} + provided + + + org.jboss.resteasy + resteasy-jackson2-provider + ${resteasy-version} + provided + + + javax.annotation + javax.annotation-api + 1.2 + provided + + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + 2.4.1 + + + joda-time + joda-time + 2.7 + + + io.swagger + swagger-jaxrs + ${swagger-core-version} + + + junit + junit + ${junit-version} + test + + + org.testng + testng + 6.8.8 + test + + + junit + junit + + + snakeyaml + org.yaml + + + bsh + org.beanshell + + + +{{#useBeanValidation}} + + + javax.validation + validation-api + 1.1.0.Final + provided + +{{/useBeanValidation}} + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + 1.5.18 + 9.2.9.v20150224 + 3.0.11.Final + 1.6.3 + 4.8.1 + 2.5 + + diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/queryParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/queryParams.mustache new file mode 100644 index 0000000000..0664f130b3 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/queryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/returnTypes.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/returnTypes.mustache new file mode 100644 index 0000000000..c8f7a56938 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/returnTypes.mustache @@ -0,0 +1 @@ +{{#returnContainer}}{{#isMapContainer}}Map{{/isMapContainer}}{{#isListContainer}}List<{{{returnType}}}>{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/serviceBodyParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/serviceBodyParams.mustache new file mode 100644 index 0000000000..c7433bffe8 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/serviceBodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/serviceFormParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/serviceFormParams.mustache new file mode 100644 index 0000000000..430fd19848 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/serviceFormParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}}FormDataContentDisposition fileDetail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/serviceHeaderParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/serviceHeaderParams.mustache new file mode 100644 index 0000000000..835635d68c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/serviceHeaderParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/servicePathParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/servicePathParams.mustache new file mode 100644 index 0000000000..30eb348564 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/servicePathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/serviceQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/serviceQueryParams.mustache new file mode 100644 index 0000000000..228fec8252 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/serviceQueryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/settingsGradle.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/settingsGradle.mustache new file mode 100644 index 0000000000..b8fd6c4c41 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/settingsGradle.mustache @@ -0,0 +1 @@ +rootProject.name = "{{artifactId}}" \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/resteasy/web.mustache b/src/main/resources/v2/JavaJaxRS/resteasy/web.mustache new file mode 100644 index 0000000000..6453a110a3 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/resteasy/web.mustache @@ -0,0 +1,14 @@ + + + + + ApiOriginFilter + {{apiPackage}}.ApiOriginFilter + + + ApiOriginFilter + /* + + diff --git a/src/main/resources/v2/JavaJaxRS/returnTypes.mustache b/src/main/resources/v2/JavaJaxRS/returnTypes.mustache new file mode 100644 index 0000000000..c8f7a56938 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/returnTypes.mustache @@ -0,0 +1 @@ +{{#returnContainer}}{{#isMapContainer}}Map{{/isMapContainer}}{{#isListContainer}}List<{{{returnType}}}>{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/serviceBodyParams.mustache b/src/main/resources/v2/JavaJaxRS/serviceBodyParams.mustache new file mode 100644 index 0000000000..c7433bffe8 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/serviceBodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/serviceFormParams.mustache b/src/main/resources/v2/JavaJaxRS/serviceFormParams.mustache new file mode 100644 index 0000000000..75f280a09f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/serviceFormParams.mustache @@ -0,0 +1 @@ +{{#is this 'form-param'}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}}InputStream {{paramName}}InputStream, FormDataContentDisposition {{paramName}}Detail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/serviceHeaderParams.mustache b/src/main/resources/v2/JavaJaxRS/serviceHeaderParams.mustache new file mode 100644 index 0000000000..835635d68c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/serviceHeaderParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/servicePathParams.mustache b/src/main/resources/v2/JavaJaxRS/servicePathParams.mustache new file mode 100644 index 0000000000..3f34fc1902 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/servicePathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/serviceQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/serviceQueryParams.mustache new file mode 100644 index 0000000000..d00f19e434 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/serviceQueryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/RestApplication.mustache b/src/main/resources/v2/JavaJaxRS/spec/RestApplication.mustache new file mode 100644 index 0000000000..82b8d9533e --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/RestApplication.mustache @@ -0,0 +1,9 @@ +package {{invokerPackage}}; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/") +public class RestApplication extends Application { + +} diff --git a/src/main/resources/v2/JavaJaxRS/spec/allowableValues.mustache b/src/main/resources/v2/JavaJaxRS/spec/allowableValues.mustache new file mode 100644 index 0000000000..d8b42439fa --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/allowableValues.mustache @@ -0,0 +1 @@ +{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^@last}}, {{/@last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/api.mustache b/src/main/resources/v2/JavaJaxRS/spec/api.mustache new file mode 100644 index 0000000000..4ccb9cc73a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/api.mustache @@ -0,0 +1,27 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} + +import javax.ws.rs.*; +import javax.ws.rs.core.Response; + +import io.swagger.annotations.*; + +import java.util.Map; +import java.util.List; +{{#useBeanValidation}}import javax.validation.constraints.*; +import javax.validation.Valid;{{/useBeanValidation}} + +@Path("/{{{baseName}}}") +@Api(description = "the {{{baseName}}} API"){{#hasConsumes}} +@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} +@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} +{{>generatedAnnotation}}public {{#interfaceOnly}}interface{{/interfaceOnly}}{{^interfaceOnly}}class{{/interfaceOnly}} {{classname}} { +{{#operations}} +{{#operation}} + +{{#interfaceOnly}}{{>apiInterface}}{{/interfaceOnly}}{{^interfaceOnly}}{{>apiMethod}}{{/interfaceOnly}} +{{/operation}} +} +{{/operations}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/apiInterface.mustache b/src/main/resources/v2/JavaJaxRS/spec/apiInterface.mustache new file mode 100644 index 0000000000..013e6dbb8e --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/apiInterface.mustache @@ -0,0 +1,14 @@ + @{{httpMethod}}{{#subresourceOperation}} + @Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}} + @Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} + @Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} + @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}"{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@Authorization(value = "{{name}}"{{#is this 'oauth'}}, scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/is}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}){{#has this 'more'}},{{/has}}{{/responses}} }) + {{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{>returnTypeInterface}}{{/returnResponse}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#has this 'more'}},{{/has}}{{/allParams}}); \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/apiMethod.mustache b/src/main/resources/v2/JavaJaxRS/spec/apiMethod.mustache new file mode 100644 index 0000000000..4048752cb0 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/apiMethod.mustache @@ -0,0 +1,17 @@ + @{{httpMethod}}{{#subresourceOperation}} + @Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}} + @Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} + @Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} + @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@Authorization(value = "{{name}}"{{#is this 'oauth'}}, scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/is}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#has this 'more'}},{{/has}}{{/responses}} + }) + public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#has this 'more'}},{{/has}}{{/allParams}}) { + return Response.ok().entity("magic!").build(); + } \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/beanValidation.mustache b/src/main/resources/v2/JavaJaxRS/spec/beanValidation.mustache new file mode 100644 index 0000000000..c8c6946fef --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/beanValidation.mustache @@ -0,0 +1,4 @@ +{{#required}} + @NotNull +{{/required}} +{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/beanValidationCore.mustache b/src/main/resources/v2/JavaJaxRS/spec/beanValidationCore.mustache new file mode 100644 index 0000000000..7c0e107796 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/beanValidationCore.mustache @@ -0,0 +1,20 @@ +{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#is this 'integer'}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/is}}{{! +isLong set +}}{{#is this 'long'}}{{#minimum}} @Min({{minimum}}L){{/minimum}}{{#maximum}} @Max({{maximum}}L){{/maximum}}{{/is}}{{! +Not Integer, not Long => we have a decimal value! +}}{{#isNot this 'integer'}}{{#isNot this 'long'}}{{#minimum}} @DecimalMin("{{minimum}}"){{/minimum}}{{#maximum}} @DecimalMax("{{maximum}}"){{/maximum}}{{/isNot}}{{/isNot}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/beanValidationPathParams.mustache b/src/main/resources/v2/JavaJaxRS/spec/beanValidationPathParams.mustache new file mode 100644 index 0000000000..051bd53c0a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/beanValidationPathParams.mustache @@ -0,0 +1 @@ +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/beanValidationQueryParams.mustache b/src/main/resources/v2/JavaJaxRS/spec/beanValidationQueryParams.mustache new file mode 100644 index 0000000000..f8eef8f94c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/beanValidationQueryParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/bodyParams.mustache b/src/main/resources/v2/JavaJaxRS/spec/bodyParams.mustache new file mode 100644 index 0000000000..1b0cae179a --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/bodyParams.mustache @@ -0,0 +1 @@ +{{#is this 'body-param'}}{{#useBeanValidation}}@Valid {{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/enumClass.mustache b/src/main/resources/v2/JavaJaxRS/spec/enumClass.mustache new file mode 100644 index 0000000000..e01687ee5d --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/enumClass.mustache @@ -0,0 +1,33 @@ +public enum {{datatypeWithEnum}} { + + {{#allowableValues}} + {{#enumVars}}{{name}}({{datatype}}.valueOf({{{value}}})){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}} + {{/allowableValues}} + + + private {{datatype}} value; + + {{datatypeWithEnum}} ({{datatype}} v) { + value = v; + } + + public String value() { + return value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static {{datatypeWithEnum}} fromValue(String v) { + for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { + if (String.valueOf(b.value).equals(v)) { + return b; + } + } + return null; + } +} diff --git a/src/main/resources/v2/JavaJaxRS/spec/enumOuterClass.mustache b/src/main/resources/v2/JavaJaxRS/spec/enumOuterClass.mustache new file mode 100644 index 0000000000..961975d028 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/enumOuterClass.mustache @@ -0,0 +1,43 @@ +{{#jackson}} +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +{{/jackson}} + +/** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} + */ +public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { + {{#if 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}} + {{/if}} + {{#unless gson}} + {{#allowableValues}}{{#enumVars}} + {{{name}}}({{{value}}}){{^@last}}, + {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}} + {{/unless}} + + 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/src/main/resources/v2/JavaJaxRS/spec/formParams.mustache b/src/main/resources/v2/JavaJaxRS/spec/formParams.mustache new file mode 100644 index 0000000000..f4dd64d3e5 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/formParams.mustache @@ -0,0 +1,2 @@ +{{#is this 'form-param'}}{{#notFile}}@FormParam(value = "{{baseName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}} @FormParam(value = "{{baseName}}") InputStream {{paramName}}InputStream, + @FormParam(value = "{{baseName}}") Attachment {{paramName}}Detail{{/is}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/generatedAnnotation.mustache b/src/main/resources/v2/JavaJaxRS/spec/generatedAnnotation.mustache new file mode 100644 index 0000000000..ad17a426e9 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/generatedAnnotation.mustache @@ -0,0 +1,3 @@ +{{^hideGenerationTimestamp}} +@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}") +{{/hideGenerationTimestamp}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/headerParams.mustache b/src/main/resources/v2/JavaJaxRS/spec/headerParams.mustache new file mode 100644 index 0000000000..5b6ec42d2f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/headerParams.mustache @@ -0,0 +1 @@ +{{#is this 'header-param'}}@HeaderParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} {{#description}} @ApiParam("{{description}}"){{/description}} {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/model.mustache b/src/main/resources/v2/JavaJaxRS/spec/model.mustache new file mode 100644 index 0000000000..9ff78cba4f --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/model.mustache @@ -0,0 +1,23 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +{{#serializableModel}} +import java.io.Serializable; +{{/serializableModel}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +import javax.validation.Valid; +{{/useBeanValidation}} + +{{#models}} +{{#model}}{{#description}} +/** + * {{description}} + **/{{/description}} +{{#is this 'enum'}} +{{>enumOuterClass}} +{{/is}} +{{#isNot this 'enum'}}{{>pojo}}{{/isNot}} +{{/model}} +{{/models}} diff --git a/src/main/resources/v2/JavaJaxRS/spec/pathParams.mustache b/src/main/resources/v2/JavaJaxRS/spec/pathParams.mustache new file mode 100644 index 0000000000..4a6bc33985 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/pathParams.mustache @@ -0,0 +1 @@ +{{#is this 'path-param'}}@PathParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#description}} @ApiParam("{{description}}"){{/description}} {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/pojo.mustache b/src/main/resources/v2/JavaJaxRS/spec/pojo.mustache new file mode 100644 index 0000000000..e1a3c791a4 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/pojo.mustache @@ -0,0 +1,82 @@ +import io.swagger.annotations.*; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +{{#description}}@ApiModel(description = "{{{description}}}"){{/description}} + +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { + {{#vars}}{{#is this 'enum'}}{{#isNot this 'container'}} + +{{>enumClass}}{{/isNot}}{{/is}}{{#is items 'enum'}}{{#items}} + +{{#isNot this 'container'}}{{>enumClass}}{{/isNot}}{{/items}}{{/is}} + private {{#useBeanValidation}}@Valid{{/useBeanValidation}} {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + {{#vars}} + /** + {{#description}} + * {{description}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + **/ + public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + return this; + } + + {{#vendorExtensions.extraAnnotation}}{{{vendorExtensions.extraAnnotation}}}{{/vendorExtensions.extraAnnotation}} + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + @JsonProperty("{{baseName}}") +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{#is this 'boolean'}}is{{/is}}{{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; + } + {{classname}} {{classVarName}} = ({{classname}}) o;{{#has this 'vars'}} + return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#has this 'more'}} && + {{/has}}{{#hasNot this 'more'}};{{/hasNot}}{{/vars}}{{/has}}{{#hasNot this 'vars'}} + return true;{{/hasNot}} + } + + @Override + public int hashCode() { + return Objects.hash({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}); + } + + @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/src/main/resources/v2/JavaJaxRS/spec/pom.mustache b/src/main/resources/v2/JavaJaxRS/spec/pom.mustache new file mode 100644 index 0000000000..b0316d5873 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/pom.mustache @@ -0,0 +1,90 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + {{#interfaceOnly}}jar{{/interfaceOnly}}{{^interfaceOnly}}war{{/interfaceOnly}} + {{artifactId}} + {{artifactVersion}} + + src/main/java + {{#interfaceOnly}} + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + {{/interfaceOnly}}{{^interfaceOnly}} + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + false + + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + {{/interfaceOnly}} + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + provided + + + io.swagger + swagger-annotations + provided + 1.5.3 + + + junit + junit + ${junit-version} + test + {{^interfaceOnly}} + + org.testng + testng + 6.8.8 + test + + + junit + junit + + + snakeyaml + org.yaml + + + bsh + org.beanshell + + + {{/interfaceOnly}} + {{#useBeanValidation}} + + + javax.validation + validation-api + 1.1.0.Final + provided + +{{/useBeanValidation}} + + + 4.8.1 + + diff --git a/src/main/resources/v2/JavaJaxRS/spec/queryParams.mustache b/src/main/resources/v2/JavaJaxRS/spec/queryParams.mustache new file mode 100644 index 0000000000..bdffda366c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/queryParams.mustache @@ -0,0 +1 @@ +{{#is this 'query-param'}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} {{#description}} @ApiParam("{{description}}"){{/description}} {{{dataType}}} {{paramName}}{{/is}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/spec/returnTypeInterface.mustache b/src/main/resources/v2/JavaJaxRS/spec/returnTypeInterface.mustache new file mode 100644 index 0000000000..1bfa056f0c --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/spec/returnTypeInterface.mustache @@ -0,0 +1 @@ +{{{returnType}}} \ No newline at end of file diff --git a/src/main/resources/v2/JavaJaxRS/typeInfoAnnotation.mustache b/src/main/resources/v2/JavaJaxRS/typeInfoAnnotation.mustache new file mode 100644 index 0000000000..2d7983d010 --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/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 = {{classname}}.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/src/main/resources/v2/JavaJaxRS/web.mustache b/src/main/resources/v2/JavaJaxRS/web.mustache new file mode 100644 index 0000000000..46ac2e4ffa --- /dev/null +++ b/src/main/resources/v2/JavaJaxRS/web.mustache @@ -0,0 +1,63 @@ + + + + + jersey + org.glassfish.jersey.servlet.ServletContainer + + jersey.config.server.provider.packages + + io.swagger.jaxrs.listing, + io.swagger.sample.resource, + {{apiPackage}} + + + + jersey.config.server.provider.classnames + org.glassfish.jersey.media.multipart.MultiPartFeature + + + jersey.config.server.wadl.disableWadl + true + + 1 + + + + Jersey2Config + io.swagger.jersey.config.JerseyJaxrsConfig + + api.version + 1.0.0 + + + swagger.api.title + {{{title}}} + + + swagger.api.basepath + {{{basePath}}} + + + 2 + + + Bootstrap + {{apiPackage}}.Bootstrap + 2 + + + jersey + {{contextPath}}/* + + + ApiOriginFilter + {{apiPackage}}.ApiOriginFilter + + + ApiOriginFilter + /* + +