swagger-codegen-generators
swagger-codegen-generators copied to clipboard
Problems that occur when using --library okhttp4-gson configuration,version:3.0.50
The version I'm using is:3.0.50
Set debug mode, httpClient should not add Interceptor through httpClient.interceptors().add()
Because httpClient.interceptors() returns views that cannot be modified. The specific situation is as follows:
. My solution is:
Thanks @bai-xuan for filing this issue. I have a doubt about your solution. Wouldn't that code replace any interceptor added previously?
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
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()) }
It has been explained in detail in unmodifiableList:
Let me add one more thing, in okhttp-2.7.5 The implementation of interceptors is like this:
What I'm talking about is using --library okhttp4-gson
His okhttp version is 4.10.0:
This is the implementation in version 4.10.0:
Specific code: https://github.com/square/okhttp/blob/6b07f6227416506a44bb97012551929cd6a1dd79/okhttp/src/main/kotlin/okhttp3/OkHttpClient.kt#L134