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:
commit
ef24b66c6c
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l jaxrs -o samples/server/petstore/jaxrs -Dswagger.codegen.jaxrs.impl.source=src/main/java"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l jaxrs -o samples/server/petstore/jaxrs"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -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";
|
||||
|
@ -2,11 +2,13 @@ package io.swagger.codegen.options;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.swagger.codegen.languages.JaxRSServerCodegen;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class JaxRSServerOptionsProvider extends JavaOptionsProvider {
|
||||
public static final String JODA_DATE_LIBRARY = "joda";
|
||||
public static final String IMPL_FOLDER_VALUE = "src/main/java/impl";
|
||||
|
||||
@Override
|
||||
public boolean isServer() {
|
||||
@ -24,6 +26,7 @@ public class JaxRSServerOptionsProvider extends JavaOptionsProvider {
|
||||
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||
builder.putAll(options)
|
||||
.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE)
|
||||
.put(JaxRSServerCodegen.DATE_LIBRARY, "joda");
|
||||
|
||||
return builder.build();
|
||||
|
Loading…
x
Reference in New Issue
Block a user