forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
@@ -3330,4 +3330,23 @@ public class DefaultCodegen {
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads propertyKey from additionalProperties, converts it to a boolean and
|
||||
* writes it back to additionalProperties to be usable as a boolean in
|
||||
* mustache files.
|
||||
*
|
||||
* @param propertyKey
|
||||
* @return property value as boolean
|
||||
*/
|
||||
public boolean convertPropertyToBooleanAndWriteBack(String propertyKey) {
|
||||
boolean booleanValue = false;
|
||||
if (additionalProperties.containsKey(propertyKey)) {
|
||||
booleanValue = Boolean.valueOf(additionalProperties.get(propertyKey).toString());
|
||||
// write back as boolean
|
||||
additionalProperties.put(propertyKey, booleanValue);
|
||||
}
|
||||
|
||||
return booleanValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -935,4 +935,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toRegularExpression(String pattern) {
|
||||
return escapeText(pattern);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.languages.features.CXFFeatures;
|
||||
import io.swagger.codegen.languages.features.LoggingFeatures;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
public class JavaCXFClientCodegen extends AbstractJavaCodegen implements CXFFeatures
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaCXFClientCodegen.class);
|
||||
|
||||
/**
|
||||
* 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 boolean useBeanValidation = false;
|
||||
|
||||
protected boolean useGzipFeature = false;
|
||||
|
||||
protected boolean useLoggingFeature = false;
|
||||
|
||||
protected boolean useBeanValidationFeature = false;
|
||||
|
||||
|
||||
public JavaCXFClientCodegen()
|
||||
{
|
||||
super();
|
||||
|
||||
supportsInheritance = true;
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-client";
|
||||
dateLibrary = "legacy"; //TODO: add joda support to all jax-rs
|
||||
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
outputFolder = "generated-code/JavaJaxRS-CXF";
|
||||
|
||||
// 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");
|
||||
|
||||
|
||||
typeMapping.put("date", "LocalDate");
|
||||
typeMapping.put("DateTime", "javax.xml.datatype.XMLGregorianCalendar"); // Map DateTime fields to Java standart class 'XMLGregorianCalendar'
|
||||
|
||||
importMapping.put("LocalDate", "org.joda.time.LocalDate");
|
||||
|
||||
embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Use Gzip Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION_FEATURE, "Use BeanValidation Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE, "Use Logging Feature"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processOpts()
|
||||
{
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
|
||||
this.setUseBeanValidation(useBeanValidationProp);
|
||||
}
|
||||
|
||||
this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE));
|
||||
this.setUseLoggingFeature(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE));
|
||||
|
||||
boolean useBeanValidationFeature = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION_FEATURE);
|
||||
this.setUseBeanValidationFeature(useBeanValidationFeature);
|
||||
if (useBeanValidationFeature) {
|
||||
LOGGER.info("make sure your client supports Bean Validation 1.1");
|
||||
}
|
||||
|
||||
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf-client";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenType getTag()
|
||||
{
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> 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 "Generates a Java JAXRS Client based on Apache CXF framework.";
|
||||
}
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
|
||||
public void setUseGzipFeature(boolean useGzipFeature) {
|
||||
this.useGzipFeature = useGzipFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseLoggingFeature(boolean useLoggingFeature) {
|
||||
this.useLoggingFeature = useLoggingFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseBeanValidationFeature(boolean useBeanValidationFeature) {
|
||||
this.useBeanValidationFeature = useBeanValidationFeature;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,23 +5,51 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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.models.Operation;
|
||||
|
||||
public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
public JavaCXFServerCodegen()
|
||||
{
|
||||
public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen implements CXFServerFeatures
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaCXFServerCodegen.class);
|
||||
|
||||
protected boolean useBeanValidation = false;
|
||||
|
||||
protected boolean generateSpringApplication = false;
|
||||
|
||||
protected boolean useSwaggerFeature = false;
|
||||
|
||||
protected boolean useWadlFeature = false;
|
||||
|
||||
protected boolean useMultipartFeature = false;
|
||||
|
||||
protected boolean useGzipFeature = false;
|
||||
|
||||
protected boolean useLoggingFeature = false;
|
||||
|
||||
protected boolean useBeanValidationFeature = false;
|
||||
|
||||
protected boolean generateSpringBootApplication= false;
|
||||
|
||||
public JavaCXFServerCodegen()
|
||||
{
|
||||
super();
|
||||
sourceFolder = "gen" + File.separator + "java";
|
||||
|
||||
supportsInheritance = true;
|
||||
|
||||
artifactId = "swagger-cxf-server";
|
||||
|
||||
outputFolder = "generated-code/JavaJaxRS-CXF";
|
||||
apiTestTemplateFiles.clear(); // TODO: add test template
|
||||
|
||||
//TODO add auto-generated pom.xml for maven
|
||||
//apiTemplateFiles.put("pom.mustache", "pom.xml");
|
||||
|
||||
|
||||
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
|
||||
@@ -36,14 +64,86 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
|
||||
embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";
|
||||
|
||||
}
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
cliOptions.add(CliOption.newBoolean(GENERATE_SPRING_APPLICATION, "Generate Spring application"));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_SWAGGER_FEATURE, "Use Swagger Feature"));
|
||||
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_BEANVALIDATION_FEATURE, "Use BeanValidation Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE, "Use Logging Feature"));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(GENERATE_SPRING_BOOT_APPLICATION, "Generate Spring Boot application"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf";
|
||||
}
|
||||
@Override
|
||||
public void processOpts()
|
||||
{
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
|
||||
this.setUseBeanValidation(useBeanValidationProp);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_SPRING_APPLICATION)) {
|
||||
this.setGenerateSpringApplication(convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_APPLICATION));
|
||||
|
||||
this.setUseSwaggerFeature(convertPropertyToBooleanAndWriteBack(USE_SWAGGER_FEATURE));
|
||||
this.setUseWadlFeature(convertPropertyToBooleanAndWriteBack(USE_WADL_FEATURE));
|
||||
this.setUseMultipartFeature(convertPropertyToBooleanAndWriteBack(USE_MULTIPART_FEATURE));
|
||||
this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE));
|
||||
this.setUseLoggingFeature(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE));
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("server/pom.mustache", "", "pom.xml"));
|
||||
|
||||
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
|
||||
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"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
@@ -65,4 +165,46 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
return "Generates a Java JAXRS Server application based on Apache CXF framework.";
|
||||
}
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
public void setGenerateSpringApplication(boolean generateSpringApplication) {
|
||||
this.generateSpringApplication = generateSpringApplication;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.codegen.languages.features.BeanValidationFeatures;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -9,7 +11,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
public class JavaClientCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
|
||||
@SuppressWarnings("hiding")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);
|
||||
|
||||
@@ -24,6 +26,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
protected boolean useRxJava = false;
|
||||
protected boolean parcelableModel = false;
|
||||
protected boolean supportJava6= false;
|
||||
protected boolean useBeanValidation = false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
@@ -37,6 +40,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
|
||||
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library."));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
|
||||
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0. Enable Java6 support using '-DsupportJava6=true'.");
|
||||
supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.16.0. JSON processing: Jackson 2.7.0");
|
||||
@@ -81,6 +85,14 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
}
|
||||
// put the boolean value back to PARCELABLE_MODEL in additionalProperties
|
||||
additionalProperties.put(PARCELABLE_MODEL, parcelableModel);
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
boolean useBeanValidationProp = Boolean.valueOf(additionalProperties.get(USE_BEANVALIDATION).toString());
|
||||
this.setUseBeanValidation(useBeanValidationProp);
|
||||
|
||||
// write back as boolean
|
||||
additionalProperties.put(USE_BEANVALIDATION, useBeanValidationProp);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
|
||||
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
|
||||
@@ -187,7 +199,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
operation.returnType = "Void";
|
||||
}
|
||||
if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/"))
|
||||
operation.path = operation.path.substring(1);
|
||||
operation.path = operation.path.substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +247,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
public void setUseRxJava(boolean useRxJava) {
|
||||
this.useRxJava = useRxJava;
|
||||
}
|
||||
@@ -248,4 +260,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
this.supportJava6 = value;
|
||||
}
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class JavaMSF4JServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
protected static final String LIBRARY_JERSEY1 = "jersey1";
|
||||
protected static final String LIBRARY_JERSEY2 = "jersey2";
|
||||
|
||||
|
||||
public static final String DEFAULT_LIBRARY = LIBRARY_JERSEY2;
|
||||
|
||||
public JavaMSF4JServerCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/JavaJaxRS-Jersey";
|
||||
apiTemplateFiles.put("apiService.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
|
||||
apiTestTemplateFiles.clear();
|
||||
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
embeddedTemplateDir = templateDir = "MSF4J";
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "msf4j";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp()
|
||||
{
|
||||
return "Generates a Java Micro Service based on WSO2 Microservices Framework for Java (MSF4J)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
if("null".equals(property.example)) {
|
||||
property.example = null;
|
||||
}
|
||||
|
||||
//Add imports for Jackson
|
||||
if(!BooleanUtils.toBoolean(model.isEnum)) {
|
||||
model.imports.add("JsonProperty");
|
||||
|
||||
if(BooleanUtils.toBoolean(model.hasEnums)) {
|
||||
model.imports.add("JsonValue");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// 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 ("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"));
|
||||
supportingFiles.add(new SupportingFile("Application.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "Application.java"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
||||
objs = super.postProcessModelsEnum(objs);
|
||||
|
||||
//Add imports for Jackson
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>)objs.get("imports");
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
// for enum model
|
||||
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
|
||||
cm.imports.add(importMapping.get("JsonValue"));
|
||||
Map<String, String> item = new HashMap<String, String>();
|
||||
item.put("import", importMapping.get("JsonValue"));
|
||||
imports.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> 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<CodegenOperation> opList = operations.get(basePath);
|
||||
if (opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(basePath, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,6 +55,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
private static final String API_NAMESPACE = "Modules";
|
||||
private static final String MODEL_NAMESPACE = "Models";
|
||||
private static final String IMMUTABLE_OPTION = "immutable";
|
||||
private static final String USE_BASE_PATH = "writeModulePath";
|
||||
|
||||
private static final Map<String, Predicate<Property>> propertyToSwaggerTypeMapping =
|
||||
createPropertyToSwaggerTypeMapping();
|
||||
@@ -89,6 +90,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
addSwitch(USE_COLLECTION, USE_COLLECTION_DESC, useCollection);
|
||||
addSwitch(RETURN_ICOLLECTION, RETURN_ICOLLECTION_DESC, returnICollection);
|
||||
addSwitch(IMMUTABLE_OPTION, "Enabled by default. If disabled generates model classes with setters", true);
|
||||
addSwitch(USE_BASE_PATH, "Enabled by default. If disabled, module paths will not mirror api base path", true);
|
||||
typeMapping.putAll(nodaTimeTypesMappings());
|
||||
languageSpecificPrimitives.addAll(nodaTimePrimitiveTypes());
|
||||
|
||||
@@ -348,7 +350,8 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
@Override
|
||||
public void preprocessSwagger(final Swagger swagger) {
|
||||
additionalProperties.put("packageContext", sanitizeName(swagger.getBasePath()));
|
||||
additionalProperties.put("baseContext", swagger.getBasePath());
|
||||
final Object basePathOption = additionalProperties.get(USE_BASE_PATH);
|
||||
additionalProperties.put("baseContext", basePathOption == null ? swagger.getBasePath() : "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface BeanValidationExtendedFeatures {
|
||||
|
||||
// Language (implementing Client/Server) supports automatic BeanValidation (1.1)
|
||||
public static final String USE_BEANVALIDATION_FEATURE = "useBeanValidationFeature";
|
||||
|
||||
public void setUseBeanValidationFeature(boolean useBeanValidationFeature);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface BeanValidationFeatures {
|
||||
|
||||
// Language supports generating BeanValidation-Annotations
|
||||
public static final String USE_BEANVALIDATION = "useBeanValidation";
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
/**
|
||||
* Features supported by CXF 3 (client + server)
|
||||
*
|
||||
*/
|
||||
public interface CXFFeatures extends LoggingFeatures, GzipFeatures, BeanValidationFeatures, BeanValidationExtendedFeatures {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
/**
|
||||
* Features supported by CXF 3 server
|
||||
*
|
||||
*/
|
||||
public interface CXFServerFeatures extends CXFFeatures, SwaggerFeatures, SpringFeatures {
|
||||
|
||||
public static final String USE_WADL_FEATURE = "useWadlFeature";
|
||||
|
||||
public static final String USE_MULTIPART_FEATURE = "useMultipartFeature";
|
||||
|
||||
public void setUseWadlFeature(boolean useWadlFeature);
|
||||
|
||||
public void setUseMultipartFeature(boolean useMultipartFeature);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface GzipFeatures {
|
||||
|
||||
public static final String USE_GZIP_FEATURE = "useGzipFeature";
|
||||
|
||||
public void setUseGzipFeature(boolean useGzipFeature);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface LoggingFeatures extends BeanValidationFeatures {
|
||||
|
||||
public static final String USE_LOGGING_FEATURE = "useLoggingFeature";
|
||||
|
||||
public void setUseLoggingFeature(boolean useLoggingFeature);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface SpringFeatures extends BeanValidationFeatures {
|
||||
|
||||
public static final String GENERATE_SPRING_APPLICATION = "generateSpringApplication";
|
||||
|
||||
public static final String GENERATE_SPRING_BOOT_APPLICATION = "generateSpringBootApplication";
|
||||
|
||||
public void setGenerateSpringApplication(boolean useGenerateSpringApplication);
|
||||
|
||||
public void setGenerateSpringBootApplication(boolean generateSpringBootApplication);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface SwaggerFeatures extends CXFFeatures {
|
||||
|
||||
public static final String USE_SWAGGER_FEATURE = "useSwaggerFeature";
|
||||
|
||||
public void setUseSwaggerFeature(boolean useSwaggerFeature);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user