Skip to content

Commit

Permalink
Add useTags option to JavaJersey server codegen (#6278)
Browse files Browse the repository at this point in the history
  • Loading branch information
tht13 authored and wing328 committed Aug 12, 2017
1 parent 11424a8 commit 01477de
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -46,6 +49,7 @@ public JavaJerseyServerCodegen() {

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
Expand Down Expand Up @@ -89,6 +93,10 @@ public void processOpts() {
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"));
Expand Down Expand Up @@ -136,30 +144,38 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> 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 (useTags) {
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
} else {
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 (basePath == "") {
basePath = "default";
} else {
if (co.path.startsWith("/" + basePath)) {
co.path = co.path.substring(("/" + basePath).length());
}
co.subresourceOperation = !co.path.isEmpty();
}
co.subresourceOperation = !co.path.isEmpty();
}
List<CodegenOperation> opList = operations.get(basePath);
if (opList == null) {
opList = new ArrayList<CodegenOperation>();
operations.put(basePath, opList);
List<CodegenOperation> opList = operations.get(basePath);
if (opList == null) {
opList = new ArrayList<CodegenOperation>();
operations.put(basePath, opList);
}
opList.add(co);
co.baseName = basePath;
}
opList.add(co);
co.baseName = basePath;
}


public void setUseTags(boolean useTags) {
this.useTags = useTags;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ protected void setExpectations() {
clientCodegen.setSupportJava6(false);
times = 1;
clientCodegen.setUseBeanValidation(Boolean.valueOf(JaxRSServerOptionsProvider.USE_BEANVALIDATION));
times = 1;
clientCodegen.setUseTags(Boolean.valueOf(JaxRSServerOptionsProvider.USE_TAGS));
times = 1;
}};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.languages.JavaCXFServerCodegen;
import io.swagger.codegen.languages.JavaClientCodegen;
import io.swagger.codegen.languages.JavaJerseyServerCodegen;

import java.util.Map;

Expand Down Expand Up @@ -39,6 +40,7 @@ public class JaxRSServerOptionsProvider implements OptionsProvider {
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
public static final String JAVA8_MODE_VALUE = "false";
public static final String WITH_XML_VALUE = "false";
public static final String USE_TAGS = "useTags";


@Override
Expand Down Expand Up @@ -89,7 +91,8 @@ public Map<String, String> createOptions() {
.put("hideGenerationTimestamp", "true")
.put(JavaCXFServerCodegen.USE_BEANVALIDATION, USE_BEANVALIDATION)
.put("serverPort", "2345")
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE);
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
.put(JavaJerseyServerCodegen.USE_TAGS, USE_TAGS);

return builder.build();
}
Expand Down

0 comments on commit 01477de

Please sign in to comment.