forked from loafle/openapi-generator-original
Add useTags option to JavaJersey server codegen (#6278)
This commit is contained in:
parent
11424a8cdd
commit
01477de711
@ -18,6 +18,9 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
|||||||
* Default library template to use. (Default:{@value #DEFAULT_LIBRARY})
|
* Default library template to use. (Default:{@value #DEFAULT_LIBRARY})
|
||||||
*/
|
*/
|
||||||
public static final String DEFAULT_LIBRARY = LIBRARY_JERSEY2;
|
public static final String DEFAULT_LIBRARY = LIBRARY_JERSEY2;
|
||||||
|
public static final String USE_TAGS = "useTags";
|
||||||
|
|
||||||
|
protected boolean useTags = false;
|
||||||
|
|
||||||
public JavaJerseyServerCodegen() {
|
public JavaJerseyServerCodegen() {
|
||||||
super();
|
super();
|
||||||
@ -46,6 +49,7 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
|||||||
|
|
||||||
cliOptions.add(library);
|
cliOptions.add(library);
|
||||||
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1/2 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
|
@Override
|
||||||
@ -89,6 +93,10 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
|||||||
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||||
implFolder = (String) additionalProperties.get(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)) {
|
if ("joda".equals(dateLibrary)) {
|
||||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||||
@ -136,30 +144,38 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||||
String basePath = resourcePath;
|
if (useTags) {
|
||||||
if (basePath.startsWith("/")) {
|
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
|
||||||
basePath = basePath.substring(1);
|
} else {
|
||||||
}
|
String basePath = resourcePath;
|
||||||
int pos = basePath.indexOf("/");
|
if (basePath.startsWith("/")) {
|
||||||
if (pos > 0) {
|
basePath = basePath.substring(1);
|
||||||
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();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,8 @@ public class JaxRSServerOptionsTest extends AbstractOptionsTest {
|
|||||||
clientCodegen.setSupportJava6(false);
|
clientCodegen.setSupportJava6(false);
|
||||||
times = 1;
|
times = 1;
|
||||||
clientCodegen.setUseBeanValidation(Boolean.valueOf(JaxRSServerOptionsProvider.USE_BEANVALIDATION));
|
clientCodegen.setUseBeanValidation(Boolean.valueOf(JaxRSServerOptionsProvider.USE_BEANVALIDATION));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setUseTags(Boolean.valueOf(JaxRSServerOptionsProvider.USE_TAGS));
|
||||||
times = 1;
|
times = 1;
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
import io.swagger.codegen.CodegenConstants;
|
import io.swagger.codegen.CodegenConstants;
|
||||||
import io.swagger.codegen.languages.JavaCXFServerCodegen;
|
import io.swagger.codegen.languages.JavaCXFServerCodegen;
|
||||||
import io.swagger.codegen.languages.JavaClientCodegen;
|
import io.swagger.codegen.languages.JavaClientCodegen;
|
||||||
|
import io.swagger.codegen.languages.JavaJerseyServerCodegen;
|
||||||
|
|
||||||
import java.util.Map;
|
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 ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||||
public static final String JAVA8_MODE_VALUE = "false";
|
public static final String JAVA8_MODE_VALUE = "false";
|
||||||
public static final String WITH_XML_VALUE = "false";
|
public static final String WITH_XML_VALUE = "false";
|
||||||
|
public static final String USE_TAGS = "useTags";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,7 +91,8 @@ public class JaxRSServerOptionsProvider implements OptionsProvider {
|
|||||||
.put("hideGenerationTimestamp", "true")
|
.put("hideGenerationTimestamp", "true")
|
||||||
.put(JavaCXFServerCodegen.USE_BEANVALIDATION, USE_BEANVALIDATION)
|
.put(JavaCXFServerCodegen.USE_BEANVALIDATION, USE_BEANVALIDATION)
|
||||||
.put("serverPort", "2345")
|
.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();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user