change java default lib to okhttp-gson

This commit is contained in:
wing328
2016-07-06 22:10:00 +08:00
parent d402f35711
commit 3b780e30d8
127 changed files with 5393 additions and 3484 deletions

View File

@@ -32,17 +32,19 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
supportedLibraries.put(DEFAULT_LIBRARY, "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");
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");
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.2.0. JSON processing: Gson 2.6.1 (Retrofit 2.0.2). Enable the RxJava adapter using '-DuseRxJava=true'. (RxJava 1.1.3)");
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
library.setEnum(supportedLibraries);
library.setDefault(DEFAULT_LIBRARY);
cliOptions.add(library);
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
libraryOption.setEnum(supportedLibraries);
libraryOption.setDefault("okhttp-gson");
cliOptions.add(libraryOption);
setLibrary("okhttp-gson");
}
@@ -96,6 +98,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
if (!StringUtils.isEmpty(getLibrary())) {
// set library to okhttp-gson as default
setLibrary("okhttp-gson");
//TODO: add sbt support to default client
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
}
@@ -116,7 +121,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
if ("feign".equals(getLibrary())) {
supportingFiles.add(new SupportingFile("FormAwareEncoder.mustache", invokerFolder, "FormAwareEncoder.java"));
additionalProperties.put("jackson", "true");
} else if ("okhttp-gson".equals(getLibrary())) {
} else if ("okhttp-gson".equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) {
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
@@ -131,8 +136,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
} else if("jersey2".equals(getLibrary())) {
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
additionalProperties.put("jackson", "true");
} else if(StringUtils.isEmpty(getLibrary())) {
} else if("jersey1".equals(getLibrary())) {
additionalProperties.put("jackson", "true");
} else {
LOGGER.error("Unknown library option (-l/--library): " + StringUtils.isEmpty(getLibrary()));
}
}
@@ -175,7 +182,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
if(!BooleanUtils.toBoolean(model.isEnum)) {
final String lib = getLibrary();
//final String lib = getLibrary();
//Needed imports for Jackson based libraries
if(additionalProperties.containsKey("jackson")) {
model.imports.add("JsonProperty");