Skip to content

Allow configuration of other Feign HTTP clients (e.g., ApacheHttpClient) in ApiClient generated by org.openapitools.codegen.languages.JavaClientCodegen[REQ] Feature Request Description #18158

Open
@jerryt92

Description

@jerryt92

Today when I tried to launch my project using the code generated by OpenAPI, I encountered the following error:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'currentUserController': Unsatisfied dependency expressed through field 'tenantService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tenantService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userApiFeignClient' defined in class path resource [com/nms/platsvc/security/config/FeignClientConfig.class]: Unsatisfied dependency expressed through method 'userApiFeignClient' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'feignBuilder' defined in class path resource [com/nms/platcbb/http/config/PlatcbbHttpAutoConfig.class]: Unsatisfied dependency expressed through method 'feignBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'okHttpClient' defined in class path resource [com/nms/platcbb/http/config/PlatcbbHttpAutoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [okhttp3.OkHttpClient]: Factory method 'okHttpClient' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics

After my investigation, I found that the error was caused by the absence of the Kotlin standard library in our company's internal Maven repository.
At first, I attempted to replace Feign's HttpClient with ApacheHttpClient. However, I found that the ApiClient generated by org.openapitools.codegen.languages.JavaClientCodegen seemingly does not allow for such custom modifications.

The code generated by JavaClientCodegen is as follows:

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ApiClient {
  public ApiClient() {
    apiAuthorizations = new LinkedHashMap<String, RequestInterceptor>();
    objectMapper = createObjectMapper();
    feignBuilder = Feign.builder()
                .client(new OkHttpClient())
                .encoder(new FormEncoder(new JacksonEncoder(objectMapper)))
                .decoder(new ApiResponseDecoder(objectMapper))
                .logger(new Slf4jLogger());
  }
......

Although I can currently resolve the issue by introducing the dependency on the Kotlin standard library, I still wish for org.openapitools.codegen.languages.JavaClientCodegen to allow configuration of other Feign HTTP clients. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions