Skip to content

Commit 508bd14

Browse files
committed
added okhttp4-gson ibrary for java generator
1 parent 5277b7d commit 508bd14

File tree

13 files changed

+2168
-1
lines changed

13 files changed

+2168
-1
lines changed

src/main/java/io/swagger/codegen/v3/generators/java/JavaClientCodegen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public JavaClientCodegen() {
9191
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.10.1");
9292
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.26. JSON processing: Jackson 2.10.1");
9393
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
94+
supportedLibraries.put("okhttp4-gson", "HTTP client: OkHttp 4.10.0. JSON processing: Gson 2.10.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
9495
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.");
9596
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.8.0. JSON processing: Gson 2.6.1 (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)");
9697
supportedLibraries.put("resttemplate", "HTTP client: Spring RestTemplate 4.3.9-RELEASE. JSON processing: Jackson 2.9.9");
@@ -231,7 +232,7 @@ public void processOpts() {
231232
additionalProperties.put("jackson", "true");
232233
supportingFiles.add(new SupportingFile("ParamExpander.mustache", invokerFolder, "ParamExpander.java"));
233234
supportingFiles.add(new SupportingFile("EncodingUtils.mustache", invokerFolder, "EncodingUtils.java"));
234-
} else if ("okhttp-gson".equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) {
235+
} else if ("okhttp-gson".equals(getLibrary()) || "okhttp4-gson".equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) {
235236
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
236237
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
237238
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{>licenseInfo}}
2+
3+
package {{invokerPackage}};
4+
5+
import java.io.IOException;
6+
7+
import java.util.Map;
8+
import java.util.List;
9+
10+
/**
11+
* Callback for asynchronous API call.
12+
*
13+
* @param <T> The return type
14+
*/
15+
public interface ApiCallback<T> {
16+
/**
17+
* This is called when the API call fails.
18+
*
19+
* @param e The exception causing the failure
20+
* @param statusCode Status code of the response if available, otherwise it would be 0
21+
* @param responseHeaders Headers of the response if available, otherwise it would be null
22+
*/
23+
void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders);
24+
25+
/**
26+
* This is called when the API call succeeded.
27+
*
28+
* @param result The result deserialized from response
29+
* @param statusCode Status code of the response
30+
* @param responseHeaders Headers of the response
31+
*/
32+
void onSuccess(T result, int statusCode, Map<String, List<String>> responseHeaders);
33+
34+
/**
35+
* This is called when the API upload processing.
36+
*
37+
* @param bytesWritten bytes Written
38+
* @param contentLength content length of request body
39+
* @param done write end
40+
*/
41+
void onUploadProgress(long bytesWritten, long contentLength, boolean done);
42+
43+
/**
44+
* This is called when the API downlond processing.
45+
*
46+
* @param bytesRead bytes Read
47+
* @param contentLength content lenngth of the response
48+
* @param done Read end
49+
*/
50+
void onDownloadProgress(long bytesRead, long contentLength, boolean done);
51+
}

0 commit comments

Comments
 (0)