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

[REQ] typescript-axios useSingleRequestParameter should mark parameter optional if all properties are optional #6440

Closed
benwiley4000 opened this issue May 27, 2020 · 4 comments · Fixed by #6477

Comments

@benwiley4000
Copy link

Follow-up to #6288.

Is your feature request related to a problem? Please describe.

If the useSingleRequestParameter flag is passed to typescript axios, then an object is a required parameter of all request functions, even if all object properties are optional, so I end up with code like this:

myApiCall({}).

Describe the solution you'd like

The generator should be able to check if any of the params are required. If not, we can specify the whole object parameter optional with ?.

Describe alternatives you've considered

Additional context

@macjohnny
Copy link
Member

@benwiley4000 good suggestion, would you like to implement this?

@benwiley4000
Copy link
Author

@macjohnny perhaps, if you can point me to where I would need to look in the code.

@macjohnny
Copy link
Member

should be somewhere here:

{{#useSingleRequestParameter}}
{{#operation}}
{{#allParams.0}}
/**
* Request parameters for {{nickname}} operation in {{classname}}.
* @export
* @interface {{classname}}{{operationIdCamelCase}}Request
*/
export interface {{classname}}{{operationIdCamelCase}}Request {
{{#allParams}}
/**
* {{description}}
* @type {{=<% %>=}}{<%&dataType%>}<%={{ }}=%>
* @memberof {{classname}}{{operationIdCamelCase}}
*/
readonly {{paramName}}{{^required}}?{{/required}}: {{{dataType}}}
{{^-last}}
{{/-last}}
{{/allParams}}
}
{{/allParams.0}}
{{/operation}}
{{/useSingleRequestParameter}}

the


part should already prevent generation of an interface if no parameters are available, but somehow this doesn't work.
maybe @codeserk can help, as he implemented this feature in #6288

@codeserk
Copy link
Contributor

codeserk commented May 28, 2020

@benwiley4000
Hello!
That sounds indeed like a legit suggestion, myApiCall({}) hurts a bit :D
I'm not sure if this is going to be straight forward to implement tho, since maybe we need to change something in Java to determine whether all the parameters of the request are optional or not.

I think this is the right line to check in mustache:

public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}options?: any) {

We should add ? like this requestParameters?: in case that condition is set to true (all the request params are optional). We should probably add a guard, or default to {} in the first line of the method too.

I can take a look a bit later :)

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