forked from loafle/openapi-generator-original
[Java][jersey1] add Java6 support to Java (jersey1) API client (#3919)
* add java6 support to java jersey1 * properly handle boolean value in mustache tag * add test for supportJava6 option
This commit is contained in:
@@ -15,6 +15,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
|
||||
public static final String USE_RX_JAVA = "useRxJava";
|
||||
public static final String PARCELABLE_MODEL = "parcelableModel";
|
||||
public static final String SUPPORT_JAVA6 = "supportJava6";
|
||||
|
||||
public static final String RETROFIT_1 = "retrofit";
|
||||
public static final String RETROFIT_2 = "retrofit2";
|
||||
@@ -22,6 +23,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
protected String gradleWrapperPackage = "gradle.wrapper";
|
||||
protected boolean useRxJava = false;
|
||||
protected boolean parcelableModel = false;
|
||||
protected boolean supportJava6= false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
@@ -34,8 +36,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
|
||||
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library. (Default: false)"));
|
||||
|
||||
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0");
|
||||
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0. Enable Java6 support using '-DsupportJava6=true'.");
|
||||
supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.16.0. JSON processing: Jackson 2.7.0");
|
||||
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.22.2. JSON processing: Jackson 2.7.0");
|
||||
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.6.2. Enable Parcelable modles on Android using '-DparcelableModel=true'");
|
||||
@@ -44,9 +47,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
libraryOption.setEnum(supportedLibraries);
|
||||
// set okhttp-gson as the default
|
||||
libraryOption.setDefault("okhttp-gson");
|
||||
cliOptions.add(libraryOption);
|
||||
|
||||
setLibrary("okhttp-gson");
|
||||
|
||||
}
|
||||
@@ -79,6 +82,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
// put the boolean value back to PARCELABLE_MODEL in additionalProperties
|
||||
additionalProperties.put(PARCELABLE_MODEL, parcelableModel);
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
|
||||
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
|
||||
}
|
||||
additionalProperties.put(SUPPORT_JAVA6, supportJava6);
|
||||
|
||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||
|
||||
@@ -97,11 +105,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
|
||||
supportingFiles.add( new SupportingFile( "gradlew.mustache", "", "gradlew") );
|
||||
supportingFiles.add( new SupportingFile( "gradlew.bat.mustache", "", "gradlew.bat") );
|
||||
supportingFiles.add( new SupportingFile( "gradle-wrapper.properties.mustache",
|
||||
supportingFiles.add(new SupportingFile( "gradlew.mustache", "", "gradlew") );
|
||||
supportingFiles.add(new SupportingFile( "gradlew.bat.mustache", "", "gradlew.bat") );
|
||||
supportingFiles.add(new SupportingFile( "gradle-wrapper.properties.mustache",
|
||||
gradleWrapperPackage.replace( ".", File.separator ), "gradle-wrapper.properties") );
|
||||
supportingFiles.add( new SupportingFile( "gradle-wrapper.jar",
|
||||
supportingFiles.add(new SupportingFile( "gradle-wrapper.jar",
|
||||
gradleWrapperPackage.replace( ".", File.separator ), "gradle-wrapper.jar") );
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
@@ -232,4 +240,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
public void setParcelableModel(boolean parcelableModel) {
|
||||
this.parcelableModel = parcelableModel;
|
||||
}
|
||||
|
||||
public void setSupportJava6(boolean value) {
|
||||
this.supportJava6 = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user