forked from loafle/openapi-generator-original
Merge pull request #1731 from evigeant/feature/jaxrs-no-sys-property
[jaxrs] Updated generator to use additional properties instead of system properties
This commit is contained in:
@@ -28,6 +28,9 @@ public class CodegenConstants {
|
||||
public static final String SOURCE_FOLDER = "sourceFolder";
|
||||
public static final String SOURCE_FOLDER_DESC = "source folder for generated code";
|
||||
|
||||
public static final String IMPL_FOLDER = "implFolder";
|
||||
public static final String IMPL_FOLDER_DESC = "folder for generated implementation code";
|
||||
|
||||
public static final String LOCAL_VARIABLE_PREFIX = "localVariablePrefix";
|
||||
public static final String LOCAL_VARIABLE_PREFIX_DESC = "prefix for generated code members and local variables";
|
||||
|
||||
|
||||
@@ -11,30 +11,27 @@ import java.util.*;
|
||||
public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
protected String dateLibrary = "default";
|
||||
protected String title = "Swagger Server";
|
||||
protected String implFolder = "src/main/java";
|
||||
|
||||
public static final String DATE_LIBRARY = "dateLibrary";
|
||||
public JaxRSServerCodegen() {
|
||||
super.processOpts();
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-server";
|
||||
|
||||
outputFolder = System.getProperty("swagger.codegen.jaxrs.genfolder", "generated-code/javaJaxRS");
|
||||
outputFolder = "generated-code/javaJaxRS";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
apiTemplateFiles.put("apiService.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
|
||||
apiPackage = System.getProperty("swagger.codegen.jaxrs.apipackage", "io.swagger.api");
|
||||
modelPackage = System.getProperty("swagger.codegen.jaxrs.modelpackage", "io.swagger.model");
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
|
||||
embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "jersey1_18";
|
||||
|
||||
for(int i = 0; i < cliOptions.size(); i++) {
|
||||
@@ -62,6 +59,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
library.setEnum(supportedLibraries);
|
||||
|
||||
cliOptions.add(library);
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +80,10 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if(additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
// if("jersey2".equals(getLibrary())) {
|
||||
// embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "jersey2";
|
||||
@@ -267,19 +269,12 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java";
|
||||
|
||||
String output = System.getProperty("swagger.codegen.jaxrs.impl.source");
|
||||
if(output == null) {
|
||||
output = "src" + File.separator + "main" + File.separator + "java";
|
||||
}
|
||||
result = result.replace(apiFileFolder(), implFileFolder(output));
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if (templateName.endsWith("Factory.mustache")) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java";
|
||||
|
||||
String output = System.getProperty("swagger.codegen.jaxrs.impl.source");
|
||||
if (output != null) {
|
||||
result = result.replace(apiFileFolder(), implFileFolder(output));
|
||||
}
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if (templateName.endsWith("Service.mustache")) {
|
||||
int ix = result.lastIndexOf('.');
|
||||
result = result.substring(0, ix) + "Service.java";
|
||||
|
||||
Reference in New Issue
Block a user