Add useTags option to JavaJersey server codegen (#6278)

This commit is contained in:
Thomas Townsend
2017-08-12 12:02:31 +02:00
committed by wing328
parent 11424a8cdd
commit 01477de711
3 changed files with 45 additions and 24 deletions

View File

@@ -18,6 +18,9 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
* 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();
@@ -46,6 +49,7 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
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
@@ -89,6 +93,10 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
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"));
@@ -136,30 +144,38 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
@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());
if (useTags) {
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
} else {
String basePath = resourcePath;
if (basePath.startsWith("/")) {
basePath = basePath.substring(1);
}
co.subresourceOperation = !co.path.isEmpty();
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;
}
List<CodegenOperation> opList = operations.get(basePath);
if (opList == null) {
opList = new ArrayList<CodegenOperation>();
operations.put(basePath, opList);
}
opList.add(co);
co.baseName = basePath;
}
public void setUseTags(boolean useTags) {
this.useTags = useTags;
}
}