Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,40 @@
import io.swagger.models.Operation;

public class JavaCXFClientCodegen extends AbstractJavaCodegen
implements BeanValidationFeatures, JaxbFeatures, GzipTestFeatures, LoggingTestFeatures
{
implements BeanValidationFeatures, JaxbFeatures, 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 useJaxbAnnotations = true;

protected boolean useBeanValidation = 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";

// clear model and api doc template as this codegen
// does not support auto-generated markdown doc at the moment
//TODO: add doc templates
Expand All @@ -63,7 +63,6 @@ public JavaCXFClientCodegen()


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");

Expand All @@ -72,19 +71,19 @@ public JavaCXFClientCodegen()
cliOptions.add(CliOption.newBoolean(USE_JAXB_ANNOTATIONS, "Use JAXB annotations for XML"));

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"));


}


@Override
public void processOpts()
{
super.processOpts();

if (additionalProperties.containsKey(USE_JAXB_ANNOTATIONS)) {
boolean useJaxbAnnotationsProp = convertPropertyToBooleanAndWriteBack(USE_JAXB_ANNOTATIONS);
this.setUseJaxbAnnotations(useJaxbAnnotationsProp);
Expand All @@ -94,15 +93,15 @@ public void processOpts()
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
this.setUseBeanValidation(useBeanValidationProp);
}

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
Expand All @@ -117,13 +116,13 @@ 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);
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
co.subresourceOperation = !co.path.isEmpty();
}

@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
Expand All @@ -132,17 +131,17 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
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 setUseJaxbAnnotations(boolean useJaxbAnnotations) {
this.useJaxbAnnotations = useJaxbAnnotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public JavaCXFServerCodegen()


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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import io.swagger.models.properties.Property;
import io.swagger.util.Json;

public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
{
public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
{

public JavaJAXRSSpecServerCodegen()
{
super();
Expand All @@ -48,7 +48,6 @@ public JavaJAXRSSpecServerCodegen()
additionalProperties.put("title", title);

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");

Expand All @@ -60,7 +59,7 @@ public JavaJAXRSSpecServerCodegen()
break;
}
}

CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
library.setDefault(DEFAULT_LIBRARY);

Expand All @@ -71,20 +70,20 @@ public JavaJAXRSSpecServerCodegen()

cliOptions.add(library);
}

@Override
public void processOpts()
{
super.processOpts();

supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));

writeOptional(outputFolder, new SupportingFile("RestApplication.mustache",
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java"));
}

}


@Override
public String getName()
Expand Down Expand Up @@ -119,7 +118,7 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
opList.add(co);
co.baseName = basePath;
}

@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
Expand All @@ -130,10 +129,10 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
model.imports.remove("JsonValue");
model.imports.remove("JsonProperty");
}

@Override
public void preprocessSwagger(Swagger swagger) {
//copy input swagger to output folder
//copy input swagger to output folder
try {
String swaggerJson = Json.pretty(swagger);
FileUtils.writeStringToFile(new File(outputFolder + File.separator + "swagger.json"), swaggerJson);
Expand Down