Skip to content

[Java][Server] fix default value#8577

Merged
wing328 merged 5 commits intoOpenAPITools:masterfrom
borsch:fix-default-value
Mar 15, 2021
Merged

[Java][Server] fix default value#8577
wing328 merged 5 commits intoOpenAPITools:masterfrom
borsch:fix-default-value

Conversation

@borsch
Copy link
Member

@borsch borsch commented Jan 29, 2021

Introduce new DefaultCode.toDefaultParameterValue(Schema). This method will be used to generate default value for method arguments. Default implementation use old toDefaultValue(Schema) to be backward compatible
Fix for: #8535

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/utils/export_docs_generators.sh
    
    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*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@borsch borsch force-pushed the fix-default-value branch 2 times, most recently from dd74161 to ca1a943 Compare January 30, 2021 07:10
@borsch
Copy link
Member Author

borsch commented Feb 1, 2021

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01)

@Zomzog
Copy link
Contributor

Zomzog commented Feb 2, 2021

I'm not sure to understand why you add a new property, why not fixing directly the default value?
Maybe with a method that can be overridden by other generators like it's done for examples.

@borsch
Copy link
Member Author

borsch commented Feb 3, 2021

@Zomzog you can see here https://github.com/OpenAPITools/openapi-generator/pull/8577/files#diff-df8051ffa04f7a4baff1a9795bf531584fa9b4bac81c2667a3c0f5ee44172dbcR181

defaultValue doesn't contains original literal from yaml/json schema but rather default object for specific language

@wing328
Copy link
Member

wing328 commented Feb 4, 2021

What about overriding the toDefaultValue method to accomplish what you need?

ref: https://github.com/OpenAPITools/openapi-generator/search?q=toDefaultValue

@borsch borsch force-pushed the fix-default-value branch from 233e841 to ea28394 Compare February 7, 2021 09:23
@borsch borsch force-pushed the fix-default-value branch from ea28394 to 5b8acc8 Compare February 7, 2021 09:24
@borsch
Copy link
Member Author

borsch commented Feb 7, 2021

@wing328 @Zomzog I have changed implementation

@borsch borsch closed this Feb 7, 2021
@borsch borsch reopened this Feb 7, 2021
@borsch borsch closed this Feb 7, 2021
@borsch borsch reopened this Feb 7, 2021
Copy link
Contributor

@Zomzog Zomzog left a comment

Choose a reason for hiding this comment

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

LGTM but maybe the new method must be limited to Java generators. @wing328 WDYT?

@borsch
Copy link
Member Author

borsch commented Mar 12, 2021

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01) @wing328 please review


// set default value
codegenParameter.defaultValue = toDefaultValue(parameterSchema);
codegenParameter.defaultValue = toDefaultParameterValue(parameterSchema);
Copy link
Member

Choose a reason for hiding this comment

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

FYI. @OpenAPITools/generator-core-team

@wing328
Copy link
Member

wing328 commented Mar 15, 2021

Please PM me via Slack when you've time. Thanks again for the PR, which mostly looks good.

Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

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

LGTM. As discussed I may file a PR later to consolidate the samples

@wing328 wing328 merged commit cfe86d9 into OpenAPITools:master Mar 15, 2021
@wing328
Copy link
Member

wing328 commented Mar 22, 2021

@borsch thanks for the PR, which has been included in the v5.1.0 release: https://twitter.com/oas_generator/status/1373636654024380423

@wing328
Copy link
Member

wing328 commented Feb 7, 2022

@Zomzog when you've time, can you please PM me via Slack? https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments