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
@ -90,6 +94,10 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
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"));
supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java"));
@ -136,6 +144,9 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
@Override
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
if (useTags) {
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
} else {
String basePath = resourcePath;
if (basePath.startsWith("/")) {
basePath = basePath.substring(1);
@ -161,5 +172,10 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
opList.add(co);
co.baseName = basePath;
}
}
public void setUseTags(boolean useTags) {
this.useTags = useTags;
}
}

View File

@ -76,6 +76,8 @@ public class JaxRSServerOptionsTest extends AbstractOptionsTest {
times = 1;
clientCodegen.setUseBeanValidation(Boolean.valueOf(JaxRSServerOptionsProvider.USE_BEANVALIDATION));
times = 1;
clientCodegen.setUseTags(Boolean.valueOf(JaxRSServerOptionsProvider.USE_TAGS));
times = 1;
}};
}
}

View File

@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap;
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;
@ -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
@ -89,7 +91,8 @@ public class JaxRSServerOptionsProvider implements OptionsProvider {
.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();
}