io.swagger.codegen.v3.generators.java.JavaCXFClientCodegen Maven / Gradle / Ivy
package io.swagger.codegen.v3.generators.java;
import io.swagger.codegen.v3.CliOption;
import io.swagger.codegen.v3.CodegenModel;
import io.swagger.codegen.v3.CodegenOperation;
import io.swagger.codegen.v3.CodegenProperty;
import io.swagger.codegen.v3.CodegenType;
import io.swagger.codegen.v3.SupportingFile;
import io.swagger.codegen.v3.generators.features.BeanValidationFeatures;
import io.swagger.codegen.v3.generators.features.GzipTestFeatures;
import io.swagger.codegen.v3.generators.features.LoggingTestFeatures;
import io.swagger.codegen.v3.generators.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 JavaCXFClientCodegen extends AbstractJavaCodegen implements BeanValidationFeatures, UseGenericResponseFeatures, GzipTestFeatures, LoggingTestFeatures {
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 useGenericResponse = false;
protected boolean useGzipFeatureForTests = false;
protected boolean useLoggingFeatureForTests = 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";
typeMapping.put("date", "LocalDate");
importMapping.put("LocalDate", "org.joda.time.LocalDate");
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE_FOR_TESTS, "Use Gzip Feature for tests"));
cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE_FOR_TESTS, "Use Logging Feature for tests"));
cliOptions.add(CliOption.newBoolean(USE_GENERIC_RESPONSE, "Use generic response"));
}
@Override
public void processOpts() {
super.processOpts();
// clear model and api doc template as this codegen
// does not support auto-generated markdown doc at the moment
// TODO: add doc templates
modelDocTemplateFiles.remove("model_doc.mustache");
apiDocTemplateFiles.remove("api_doc.mustache");
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
this.setUseBeanValidation(useBeanValidationProp);
}
if (additionalProperties.containsKey(USE_GENERIC_RESPONSE)) {
this.setUseGenericResponse(convertPropertyToBoolean(USE_GENERIC_RESPONSE));
}
if (useGenericResponse) {
writePropertyBack(USE_GENERIC_RESPONSE, useGenericResponse);
}
this.setUseGzipFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS));
this.setUseLoggingFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS));
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> 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);
if (useOas2) {
model.imports.remove("ApiModelProperty");
model.imports.remove("ApiModel");
} else {
model.imports.remove("Schema");
}
model.imports.remove("JsonSerialize");
model.imports.remove("ToStringSerializer");
}
@Override
public Map postProcessOperations(Map objs) {
objs = super.postProcessOperations(objs);
return AbstractJavaJAXRSServerCodegen.jaxrsPostProcessOperations(objs);
}
@Override
public String getHelp() {
return "[WORK IN PROGRESS: generated code depends from Swagger v2 libraries] "
+ "Generates a Java JAXRS Client based on Apache CXF framework.";
}
public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}
public void setUseGzipFeatureForTests(boolean useGzipFeatureForTests) {
this.useGzipFeatureForTests = useGzipFeatureForTests;
}
public void setUseLoggingFeatureForTests(boolean useLoggingFeatureForTests) {
this.useLoggingFeatureForTests = useLoggingFeatureForTests;
}
public void setUseGenericResponse(boolean useGenericResponse) {
this.useGenericResponse = useGenericResponse;
}
@Override
public String getArgumentsLocation() {
return "";
}
@Override
public String getDefaultTemplateDir() {
return JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf";
}
}