openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
558 stars 67 forks source link

Use it with an existing axios instance #77

Open gagagast opened 3 years ago

gagagast commented 3 years ago

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

anttiviljami commented 3 years ago

That's a cool idea. PRs accepted :)

npdev453 commented 2 years ago

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.