openapi-client-axios icon indicating copy to clipboard operation
openapi-client-axios copied to clipboard

Use it with an existing axios instance

Open gagagast opened this issue 3 years ago • 2 comments

Hello, I try to use this tool in an existing app. It already uses an axios instance in JWTService Class to handle auth. Is there a way to use the existing axios instance in the openApiClient instance rather than create a new one.

Thx

gagagast avatar Jul 18 '21 09:07 gagagast

That's a cool idea. PRs accepted :)

anttiviljami avatar Aug 10 '21 05:08 anttiviljami

I check this idea and what can I say:

  1. AxiosInstance does not have .create method for creating sub-instances https://github.com/axios/axios/issues/1170 https://github.com/axios/axios/pull/2040

  2. We can't use provided AxiosInstance without sub-instancing or cloning, it looks like antipattern with side effects to unexpected modifying provided object.

  3. Seems like defaultAxiosConfigs will not usable together with instance and constructor type will be like

 { ... } & ({
    axiosConfigDefaults?: AxiosRequestConfig;
    baseAxiosInstance?: never;
  } | {
    axiosConfigDefaults?: never;
    baseAxiosInstance?: AxiosInstance;
  })

@anttiviljami, @gagagast Maybe you can help me to found a nice solution for 1 and 2 list items.

npdev453 avatar Jan 06 '22 13:01 npdev453