-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[Go] Set Default Values for Required Variables where only one value is possible #19160
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
Conversation
Thanks for the PR. I dont think required fields or parameters should have default values. Agreed? |
Ideally yes, but this is just a fallback in cases when only one value is possible as per the OAS. The Python SDK also has the same behaviour implemented. |
docs/generators/fsharp-functions.md
Outdated
@@ -34,7 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | |||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| | |||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| | |||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| | |||
|sourceFolder|source folder for generated code| |OpenAPI/src| | |||
|sourceFolder|source folder for generated code| |OpenAPI\src| |
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.
samples incorrectly updated. please fix it.
bin/configs/go-petstore.yaml
Outdated
@@ -15,6 +15,7 @@ additionalProperties: | |||
packageName: petstore | |||
disallowAdditionalPropertiesIfNotPresent: false | |||
generateInterfaces: true | |||
initRequiredVars: true |
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.
please rename this option to "useDefaultValuesForRequiredVars" instead
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.
addressed
} | ||
{{/initRequiredVars}} | ||
{{/defaultValue}} | ||
{{/isReadOnly}} |
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.
Better wrap the whole block inside {{#useDefaultValuesForRequiredVars}} ... {{/useDefaultValuesForRequiredVars}}
instead
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.
I have addressed
{{^isReadOnly}} | ||
{{#defaultValue}} | ||
{{#initRequiredVars}} | ||
func (o *{{classname}}) GetDefault{{baseName}}() interface{} { |
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.
what about adding a docstring (a line or 2) explaining what this function does?
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.
I have addressed
{{#defaultValue}} | ||
{{#initRequiredVars}} | ||
func (o *{{classname}}) GetDefault{{baseName}}() interface{} { | ||
var {{baseName}} {{{dataType}}} = {{{defaultValue}}} |
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.
i don't think we need an additional variable to hold the default value which can be used directly in the line below
look likes there are additional code added to the code base (template) even though the option is switched off. can you please revise? |
src/Api/AuthApi.php | ||
src/Api/BodyApi.php | ||
src/Api/FormApi.php | ||
src/Api/HeaderApi.php | ||
src/Api/PathApi.php | ||
src/Api/QueryApi.php | ||
src/ApiException.php |
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.
are you using git bash or WSL to run the sample update script under windows?
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.
I am using git bash
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.
can you try WSL instead?
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.
@prmedipa Run the cmds in a unix/linux environment and update the PR. There are a lot of unnecessary diff because of the windows related tooling.
Fix 19107
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)