-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Scala] Default Option parameters to None #6538
Conversation
@gmarz thank for the PR. |
@@ -61,7 +61,7 @@ class {{classname}}(val defBasePath: String = "{{{basePath}}}", | |||
{{#allParams}} * @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} | |||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} | |||
*/ | |||
def {{operationId}}({{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{#defaultValue}} /* = {{{defaultValue}}}*/{{/defaultValue}}{{/required}}{{^required}}Option[{{dataType}}]{{#defaultValue}} /* = {{{defaultValue}}}*/{{/defaultValue}}{{^defaultValue}} = None{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}: Option[{{returnType}}]{{/returnType}} = { | |||
def {{operationId}}({{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{#defaultValue}} /* = {{{defaultValue}}}*/{{/defaultValue}}{{/required}}{{^required}}Option[{{dataType}}]{{#defaultValue}} = None /* = {{{defaultValue}}}*/{{/defaultValue}}{{^defaultValue}} = None{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}: Option[{{returnType}}]{{/returnType}} = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmarz it's already default to None if defaultValue
is not provided:
{{^defaultValue}} = None{{/defaultValue}}
I think the following should be changed from
/* = {{{defaultValue}}}*/
to
= {{{defaultValue}}}
instead to use the default value provided in the spec.
(I do not recall why it's commented. Maybe it's not working for all default values)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmarz can you tell me what are the steps to reproduce the error, and I will test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wing328 sorry for the slow reply...
(I do not recall why it's commented. Maybe it's not working for all default values)
Yea, I'm not sure. Maybe because it needs to be wrapped in Some
...I think the current template will try and do Option[Boolean] = false
which isn't valid?
@ramzimaalej there is no error/issue here. This change just defaults Option
types to None
for convenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmarz do you mind resolving the conflicts and I will take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramzimaalej done :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmarz I think the current implementation should be able to meet your requirement:
/* = {{{defaultValue}}}*/{{/defaultValue}}{{^defaultValue}} = None{{/defaultValue}}
which is default to None
if defaultValue
is not provided.
In your spec, do you have the defaultValue
set to something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmarz do you mind double checking if current version solves the problem or not. if the problem is not solved, please create a ticket (if it does not exists) and attach the swagger-doc you used to reproduce the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is commented out anyway so it should not be a problem merging this PR into master if the spec contains default value. I'll create a separate "issue" to track the defaultValue
enhancement to Scala API client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmarz @wing328 @ramzimaalej the only issue I see with the previous default value is that if someone were to say defaultValue = null
it would fail as Some(null)
defines a value of null, which is unexpected. The optional value should be Option({{defaultValue}})
to account for this edge case, as Option(null)
becomes None
and Option(nonNull)
becomes Some(nonNull)
.
ee6af15
to
d219577
Compare
@wing328 LGTM |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for breaking (non-backward compatible) changes.Description of the PR
Defaults
Option
parameters toNone
which makes method calls and models less verbose.