forked from loafle/openapi-generator-original
[JAXRS-CXF] Issue 4569 - Re-added usage of contextPath in api.mustache (basePath) (#4580)
* jaxrs-cxf: Re-added usage of contextPath in api.mustache (basePath) * jaxrs-cxf: Added useAnnotatedBasePath and generateNonSpringApplication flags * useAnnotatedBasePath=true uses the @Path annotation in the generated interface to set the basePath, default is false * generateNonSpringApplication=true generates a web.xml with CXFNonSpringJaxrsServlets. If useAnnotatedBasePath=true only one servlet will be created, otherwise one for each API * jaxrs-cxf generateNonSpringApplication: removed creation of multiple servlets Multiple servlets were generated if useAnnotatedBasePath was false. This is not necessary as there is only ONE basePath per contract * jaxrs-cxf: added sample generation for useAnnotatedBasePath and generateNonSpringApplication
This commit is contained in:
@@ -56,6 +56,10 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
|
||||
protected boolean useLoggingFeatureForTests = false;
|
||||
|
||||
protected boolean useAnnotatedBasePath = false;
|
||||
|
||||
protected boolean generateNonSpringApplication = false;
|
||||
|
||||
public JavaCXFServerCodegen()
|
||||
{
|
||||
super();
|
||||
@@ -108,6 +112,9 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -159,6 +166,16 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
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"));
|
||||
@@ -191,10 +208,12 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
(testResourcesFolder + '/'), "application.properties"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (this.generateNonSpringApplication) {
|
||||
writeOptional(outputFolder, new SupportingFile("server/nonspring-web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,4 +312,12 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
this.addConsumesProducesJson = addConsumesProducesJson;
|
||||
}
|
||||
|
||||
public void setUseAnnotatedBasePath(boolean useAnnotatedBasePath) {
|
||||
this.useAnnotatedBasePath = useAnnotatedBasePath;
|
||||
}
|
||||
|
||||
public void setGenerateNonSpringApplication(boolean generateNonSpringApplication) {
|
||||
this.generateNonSpringApplication = generateNonSpringApplication;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,10 +15,18 @@ public interface CXFServerFeatures
|
||||
|
||||
public static final String ADD_CONSUMES_PRODUCES_JSON = "addConsumesProducesJson";
|
||||
|
||||
public static final String USE_ANNOTATED_BASE_PATH = "useAnnotatedBasePath";
|
||||
|
||||
public static final String GENERATE_NON_SPRING_APPLICATION = "generateNonSpringApplication";
|
||||
|
||||
public void setUseWadlFeature(boolean useWadlFeature);
|
||||
|
||||
public void setUseMultipartFeature(boolean useMultipartFeature);
|
||||
|
||||
public void setAddConsumesProducesJson(boolean addConsumesProducesJson);
|
||||
|
||||
public void setUseAnnotatedBasePath(boolean useAnnotatedBasePath);
|
||||
|
||||
public void setGenerateNonSpringApplication(boolean generateNonSpringApplication);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user