-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[REQ][Typescript-axios], ability to pass in parameters as an object #5385
Comments
which generator do you use? e.g. the typescript-angular generator supports this feature already. |
We are using typescript-axios @macjohnny Would typescript-angular be appropriate for a react app? |
the openapi-generator/samples/client/petstore/typescript-rxjs/builds/default/apis/PetApi.ts Line 91 in 972ba18
or you could use the openapi-generator/samples/client/petstore/typescript-fetch/builds/multiple-parameters/apis/PetApi.ts Line 112 in 972ba18
|
Thanks, we would rather not introduce rxjs just for this, although the typescript-fetch looks promising, any idea how complex it would be to submit a PR to typescript-axios, allowing a flag to be passed which generates functions taking in objects rather than regular parameters? |
the simplest approach, which would cost you less than an hour, would be to conditionally wrap the method parameters with braces: someMethod(param1: string, param2: string) {
...
} to someMethod({param1, param2}: {param1: string, param2: string}) {
...
} you could do that here: openapi-generator/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache Line 37 in 972ba18
which currently results in openapi-generator/samples/client/petstore/typescript-axios/builds/default/api.ts Line 310 in 972ba18
A better approach would be to create separate |
That's exactly what I did in a previous project that used axios - worked well for me. A drawback, of course, is that occasionally I needed to modify my local template copy to catch up with the changes introduced by newer openapi-generator changes. |
Hey! We had the exact same issue, we came up with this:
Should we open a PR with this? |
@facundomedica PRs are welcome |
Any update? I'm facing the same. |
Anyone still looking for a solution, you can use |
Is your feature request related to a problem? Please describe.
It can be hard to read the code and can introduce bugs when using normal function parameters, for instance, if you have this:
and the backend adds an argument websiteId, after orgId, depending on the types of the items it won't necessarily cause a type error.
Describe the solution you'd like
I would like the option to pass in the parameters as an object
Describe alternatives you've considered
For now, I am manually creating helper functions like this, but it's still a hassle to make sure to keep them up to date, it would be nicer to have the security of having objects here so that if anything at all is wrong, it will give a type error
Additional context
No additional context, let me know if you have any questions
The text was updated successfully, but these errors were encountered: