RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.82k stars 1.3k forks source link

Feature Request: Use the 'getInstance(defaultInstance)' method from the base class (Typescript client) #3688

Open Mrks83 opened 3 years ago

Mrks83 commented 3 years ago

Currently there is an option to "getBaseUrl" from base class, which is fine. It would be awesome to get the same for the second constructor parameter instance. That way interceptors can easily be added and constructor-calls with undefined on the first parameter new MyClient(undefined, myInstance) are not needed.

constructor(baseUrl?: string, instance?: AxiosInstance) {
    super();
    this.instance = instance ? instance : axios.create();
    this.baseUrl = baseUrl !== undefined && baseUrl !== null ? baseUrl : this.getBaseUrl("https://localhost");
}
BoberPL commented 6 months ago

Yeah, that would be really awesome. Sadly this issue has been probably lost in tons of issues that are raised here. It would really help not having to pass the instance to which interceptors are wired up each time we are using a client, but use similar approach like with baseUrl. new MyClient().... how beautiful would it be.