-
-
Notifications
You must be signed in to change notification settings - Fork 538
Allow usage of a custom axios instance #1434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4831157
to
b173c47
Compare
b173c47
to
f27366c
Compare
There's already docs and instructions for something like this: https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/docs/custom-request-file.md Looks like the dev has possibly abandoned this repo though, there are breaking bugs that havent had attention in months. |
Having to re-implement whole request logic means that there is a very high chance of things breaking on new version of this package being released. This change looks like it would be a lot less prone to that. Although ideally there would be some axios-client-specific method that one could override like |
I've mentioned this method in the docs i've added. But as @rchl mentioned, that process is very error-prone, and when attempting it I ended up copying hundreds of lines of code from the default generated version of |
Would really love to this merged as well. |
@yehonatanz |
@blipk this one with the |
Would love to see this merged - as others have already mentioned, this is a blocker for some people using customised Copying and overriding the request file won't do the trick in my case, since I am generating a client used by multiple projects, each of them having the need to pass in a custom |
I am also looking for this functionality, thank you! |
@ferdikoomen any chance this can be merged in? it's a relatively simple change, and it seems like it addresses a common pain point |
Would be awesome to see some movement on this, such a small change but such a big impact 🙏 |
thank you @ferdikoomen for merging this PR 🎈 |
Does this work for non-named clients too (
|
@ferdikoomen ref #942 I don't think that this implementation solves all cases when needing to provide a custom axios instance, since the axios instance instantiation can only occur inside the BaseHttpRequest override, it results in a too tightly coupled solution. The axios instance would be better provided as an injected dependency in the constructor, so that we can create and pass in the instance from anywhere. I am forking this repo to solve the problem, with backward compatibility, I'll create a PR and would be great if it could be considered to merge |
This PR solves #942, and any issues requesting specific advanced axios features (e.g. #1428, part of #1084)
Currently, it is impossible to add any interceptors to axios without modifying the global axios instance, which can effect other parts of your program in unwanted ways.
Also, hiding away the actual usage of the axios library in the
request
file means this generator will always play catch up with new axios features, or people asking for very specific axios parameters to be externalized.This PR allows passing in a custom axios instance to the inner request module, providing an escape hatch for advanced users.