mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-16 08:31:26 +00:00
Merge pull request #1866 from xhh/java-okhttp-gson-debugging
[Java okhttp-gson] Implement the "debugging" option of ApiClient
This commit is contained in:
@@ -11,6 +11,8 @@ import com.squareup.okhttp.MultipartBuilder;
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.Headers;
|
||||
import com.squareup.okhttp.internal.http.HttpMethod;
|
||||
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
|
||||
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@@ -116,6 +118,8 @@ public class ApiClient {
|
||||
private OkHttpClient httpClient;
|
||||
private JSON json;
|
||||
|
||||
private HttpLoggingInterceptor loggingInterceptor;
|
||||
|
||||
public ApiClient() {
|
||||
httpClient = new OkHttpClient();
|
||||
|
||||
@@ -452,6 +456,16 @@ public class ApiClient {
|
||||
* @param debugging To enable (true) or disable (false) debugging
|
||||
*/
|
||||
public ApiClient setDebugging(boolean debugging) {
|
||||
if (debugging != this.debugging) {
|
||||
if (debugging) {
|
||||
loggingInterceptor = new HttpLoggingInterceptor();
|
||||
loggingInterceptor.setLevel(Level.BODY);
|
||||
httpClient.interceptors().add(loggingInterceptor);
|
||||
} else {
|
||||
httpClient.interceptors().remove(loggingInterceptor);
|
||||
loggingInterceptor = null;
|
||||
}
|
||||
}
|
||||
this.debugging = debugging;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,11 @@
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${okhttp-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp</groupId>
|
||||
<artifactId>logging-interceptor</artifactId>
|
||||
<version>${okhttp-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
@@ -133,7 +138,7 @@
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<okhttp-version>2.4.0</okhttp-version>
|
||||
<okhttp-version>2.7.2</okhttp-version>
|
||||
<gson-version>2.3.1</gson-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
|
||||
Reference in New Issue
Block a user