swagger-typescript-api
swagger-typescript-api copied to clipboard
Type collisions in Axios HTTP client
Right now when setting
httpClientType: "axios"
Inside HTTPClient class there are some type collisions when constructing headers


I assume this file is autogenerated from here
You can use axios with version 0.21.4
"dependencies": {
"axios": "^0.21.4",
You can use axios with version 0.21.4
"dependencies": { "axios": "^0.21.4",
While this works, of course, it's not a real solution. Is there any progress made on this?
The problem was introduced with this commit in Axios 0.23.0 by adding explicit type for default headers.
This should not be too hard to fix. I can do the PR, just need some feedback on my initial analysis (due to my limited experience and usage of/with the generator):
mergeRequestParams- I don't understand why this function works with Axios defaults (this.instance.defaultsandthis.instance.defaults.headers) in the first place. Defaults are set on the instance and will be merged into a request config by Axios itself. So these lines can be safely removedrequestfunction (if (type === ContentType.FormDatacondition) - little bit harder to make a call as I don't understand the reason for the code and even the PR which introduced it is not clear why it manipulates the headers (almost feels like it was just useful for the contributor himself for his use case). Anywaycommon,putetc. keys are not allowed onheaderskey of the request config and must be removed
Any feedback appreciated
Fingers crossed for compatible fix with axios 0.24 🤞
any update?
Any update on this? Would love to update axios to latest version.
any updates on that? thanks.
as workaround, you can remove default headers from the api instance.
const api = new Api();
api.instance.defaults.headers.put = {};
api.instance.defaults.headers.post = {};
api.instance.defaults.headers.patch = {};
api.auth.login()
now, type: ContentType.Json is working properly. I will try to create a PR to fix this behavior (so, type prop will have more prio)
Actually, it's already fixed in https://github.com/acacode/swagger-typescript-api/commit/94087eca8ff3d717fec054725c159e8f9f5d9cb8 (upcoming release)
I also have a type problem (axios 0.21.4)

this is used here

But if you just delete HeadersDefaults everything is fine.