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

fix: Set default value for form fields #4047

Conversation

ahmadSaeedGoda
Copy link
Contributor

  • Use provided default value in struct tags when binding a request input to struct for validation.

Fixes: How to apply default value if empty value provided by client during model binding? #4042, #13042df, #a41721a

  • With pull requests:
    • Open your pull request against master
    • Your pull request should have no more than two commits, if not you should squash them.
    • It should pass all tests in the available continuous integration systems such as GitHub Actions.
    • You should add/modify tests to cover your proposed code changes.
    • If your pull request contains a new feature, please document it on the README.

- Use specified default value in struct tags when binding a request input to struct for validation, even if sent empty, not only when not sent at all.
- Add string field to `TestMappingDefault` test case.
- Add test case for not sent form field to default to the value specified via code.
- Add test case for form field sent empty to default to the value specified via code.

Fixes: How to apply default value if empty value provided by client during model binding? gin-gonic#4042, #13042df, #a41721a
@ahmadSaeedGoda ahmadSaeedGoda force-pushed the fix/apply-default-value-if-empty-value-provided-by-client-during-model-binding branch from b31017d to 497351c Compare September 4, 2024 03:14
@ahmadSaeedGoda
Copy link
Contributor Author

ahmadSaeedGoda commented Sep 5, 2024

@thinkerou @appleboy Kindly review this tiny portion, highly appreciated! 🆒

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.85%. Comparing base (3dc1cd6) to head (497351c).
Report is 69 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4047      +/-   ##
==========================================
- Coverage   99.21%   98.85%   -0.36%     
==========================================
  Files          42       44       +2     
  Lines        3182     2801     -381     
==========================================
- Hits         3157     2769     -388     
- Misses         17       19       +2     
- Partials        8       13       +5     
Flag Coverage Δ
?
-tags "sonic avx" 98.84% <100.00%> (?)
-tags go_json 98.84% <100.00%> (?)
-tags nomsgpack 98.83% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 98.85% <100.00%> (-0.36%) ⬇️
go-1.22 98.85% <100.00%> (?)
macos-latest 98.85% <100.00%> (-0.36%) ⬇️
ubuntu-latest 98.85% <100.00%> (-0.36%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@appleboy appleboy merged commit 28e57f5 into gin-gonic:master Sep 6, 2024
24 of 25 checks passed
@appleboy appleboy added the bug label Sep 6, 2024
@appleboy appleboy added this to the v1.11 milestone Sep 6, 2024
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.

2 participants