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

JS client: Support for default parameter values #2027

Closed
delenius opened this issue Feb 3, 2016 · 6 comments
Closed

JS client: Support for default parameter values #2027

delenius opened this issue Feb 3, 2016 · 6 comments

Comments

@delenius
Copy link
Contributor

delenius commented Feb 3, 2016

This is a feature request to support default parameter values in the generated JS client. These seem to be ignored currently.

@wing328
Copy link
Contributor

wing328 commented Feb 4, 2016

For other API clients, we don't implement default value for parameters because the default value should be handled/added in the server side.

For your case, if the default value is not provided, will the server handle it properly?

@wing328 wing328 added this to the v2.1.6 milestone Feb 4, 2016
@delenius
Copy link
Contributor Author

delenius commented Feb 4, 2016

I see, but then the problem is that the client will get confused about the arguments. For example, if I have one operation foo that takes one parameter bar (say as a query param), which has a default value, then the generated client API function will be

self.foo = function(bar, callback) {
...
}

Now, if the user just calls foo(myCallback), things will not work. You would have to at least call it with foo(null, myCallback) (which is kind of ugly).

However, I realize now that there will be problems when you have a mix of default and non-default parameters. E.g. this would not work:

self.foo = function(p1, p2 = true, p3, p4 = false){
 ...
}

I guess this is why the other JS client uses named parameters, like

foo({ p1: 17, p3: 1, p4: true })

(this would result in the server using the default for p2 since it is not passed, whereas p4 overrides its default).

@wing328
Copy link
Contributor

wing328 commented Feb 5, 2016

Definitely valid point and we'll evaluate your suggestion using named parameter (which is already supported by C#, Ruby, etc)

@xhh
Copy link
Contributor

xhh commented Feb 17, 2016

We can implement optional parameters like in Ruby client. I'll submit a PR for it.

@wing328
Copy link
Contributor

wing328 commented Feb 17, 2016

@delenius what's your view on using Ruby's style optional parameter in JS functions?

@delenius
Copy link
Contributor Author

I like it, and I have seen that style used in JS libraries before.

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

No branches or pull requests

3 participants