Skip to content
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

[v5] Axios generator is broken. #128

Closed
eddiecooro opened this issue May 12, 2021 · 3 comments
Closed

[v5] Axios generator is broken. #128

eddiecooro opened this issue May 12, 2021 · 3 comments

Comments

@eddiecooro
Copy link
Contributor

What are the steps to reproduce this issue?

  1. install orval@next
  2. create orval.config.js with output.client set to axios
  3. run orval

What happens?

Orval generates the following broken code:
image
ts playground

What were you expecting to happen?

Seemingly, the <Data = unknown> part cannot be parsed by typescript. Everything works perfectly fine if you remove the = unknown Though.
After searching for a while, It looks like there is really no way for having default value for generic object literal methods.
Not only the notation we use, but neither of { method: <Data = unknown>() => {} } nor { method: function<Data = unknown>() {} } works.

Solution

Multiple solutions comes to mind, but before anything, I'm failing to understand why the axios generator, unlike the others, generates the getExampleService function in the first place? Maybe it's a legacy thing we can fix while we are upgrading to v5? The problem wouldn't exist if the output was like the react-query one, only without the hooks.

But otherwise, doing the following can solve the issue:
image
ts playground

I'm still only somewhat familiar with the codebase, So I don't know how exactly we can split the definition and the export. But I believe the return value can easily be generated just by putting all of the function names together, separated with commas.

What versions are you using?

**Package Version:**v5.1.3

@anymaniax
Copy link
Owner

Wow! Nice catch I didn't saw the issue because I don't know why but when you have all options optional for the first function then typescript is happy 😭

@anymaniax
Copy link
Owner

And yes the global function is a legacy

@anymaniax
Copy link
Owner

anymaniax commented May 12, 2021

I fixed the problem in 5.2.0 and added a new client named axios-functions which only generate the functions by operation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants