swagger-codegen-generators icon indicating copy to clipboard operation
swagger-codegen-generators copied to clipboard

Problems that occur when using --library okhttp4-gson configuration,version:3.0.50

Open bai-xuan opened this issue 1 year ago • 5 comments

The version I'm using is:3.0.50 image

Set debug mode, httpClient should not add Interceptor through httpClient.interceptors().add()

image

Because httpClient.interceptors() returns views that cannot be modified. The specific situation is as follows:

image image image

. My solution is: image

bai-xuan avatar Nov 06 '23 08:11 bai-xuan

Thanks @bai-xuan for filing this issue. I have a doubt about your solution. Wouldn't that code replace any interceptor added previously?

HugoMario avatar Nov 09 '23 01:11 HugoMario

Thanks @bai-xuan for filing this issue. I have a doubt about your solution. Wouldn't that code replace any interceptor added previously?

An immutable list will definitely not take effect, and he even reported an error

bai-xuan avatar Nov 09 '23 06:11 bai-xuan

Thanks @bai-xuan for filing this issue. I have a doubt about your solution. Wouldn't that code replace any interceptor added previously?

The code where the problem occurs: httpClient.interceptors().add(loggingInterceptor);

interceptors() The implementation is: @get:JvmName("interceptors") val interceptors: List<Interceptor> = builder.interceptors.toImmutableList()

toImmutableList() The implementation is:

/** Returns an immutable copy of this. */ fun <T> List<T>.toImmutableList(): List<T> { return Collections.unmodifiableList(toMutableList()) }

bai-xuan avatar Nov 09 '23 06:11 bai-xuan

It has been explained in detail in unmodifiableList:

image

bai-xuan avatar Nov 09 '23 06:11 bai-xuan

Let me add one more thing, in okhttp-2.7.5 The implementation of interceptors is like this:

image image

What I'm talking about is using --library okhttp4-gson His okhttp version is 4.10.0: image

This is the implementation in version 4.10.0: image

Specific code: https://github.com/square/okhttp/blob/6b07f6227416506a44bb97012551929cd6a1dd79/okhttp/src/main/kotlin/okhttp3/OkHttpClient.kt#L134

bai-xuan avatar Nov 09 '23 07:11 bai-xuan