-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
API client, use object not arg variables #589
base: master
Are you sure you want to change the base?
Conversation
So we move from get(id: int, from: Date, to: Date) to get(q: {id: int, from: Date, to: Date}) which opens up all the goodness of object destructuring, spread operators, and other es6 features
this actually only needs aff7013 |
This is a major breaking change in the generated code... |
@RSuter sure - probably best off as an issue? |
Yes, please create an issue and reference this pr. We will discuss this there... |
@bakesteve: Great idea, I thought about doing this a while back but didn't get around to implementing it. However as you said above, I think this needs to be an opt-in feature to avoid the breaking change. You can also avoid forking the templates too much by destructuring inside the parameter list of the function declaration, i.e.
so This would remove the need to write |
Hello there, |
@RicoSuter Any news on this? |
@RicoSuter any news on this? :-) |
Found this package to be useful for generating typescript client: https://www.npmjs.com/package/swagger-typescript-api - Please avoid using NSwag ts client generation as it makes your codebase harder to maintain |
Not sure if there is a neater way to do this, and may want to make this optional, but this opens up the capabilities of spread operators and the like to any complex api client calls.
so if I start with an api that can take a number of options on a GET call, I would currently get each parameter as an argument variable.
This moves it to always generate with a single argument object
So we move from
get(id: int, from: Date, to: Date)
to
get(q: {id: int, from: Date, to: Date})
which opens up all the goodness of object destructuring, spread operators, and other es6 features
one alternate approach would be to only do this based on the original API signature in the web api controller.
so:
would generate
which I think may be a better approach, but coudlnt immediately see how to make that happen?