Skip to content

[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

Closed
wants to merge 11 commits into from

Conversation

prmedipa
Copy link

Fix 19107

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    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.
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328
Copy link
Member

wing328 commented Jul 15, 2024

Thanks for the PR. I dont think required fields or parameters should have default values. Agreed?

@vvb
Copy link
Contributor

vvb commented Jul 16, 2024

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.

@@ -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|
Copy link
Member

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.

@@ -15,6 +15,7 @@ additionalProperties:
packageName: petstore
disallowAdditionalPropertiesIfNotPresent: false
generateInterfaces: true
initRequiredVars: true
Copy link
Member

@wing328 wing328 Jul 19, 2024

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

}
{{/initRequiredVars}}
{{/defaultValue}}
{{/isReadOnly}}
Copy link
Member

@wing328 wing328 Jul 19, 2024

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

Copy link
Author

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{} {
Copy link
Member

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?

Copy link
Author

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}}}
Copy link
Member

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

@wing328
Copy link
Member

wing328 commented Jul 19, 2024

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
Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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?

Copy link
Contributor

@vvb vvb left a 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.

@prmedipa
Copy link
Author

@vvb @wing328
Please review the following pull request: #19218.
The file samples/openapi3/client/petstore/go/go-petstore/model_category.go contains code for default values.

@prmedipa prmedipa closed this Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQ] [Go] Set Default Values for Required Variables where only one value is possible.
3 participants