fix: [#817] make validator.Bind populate anonymous embedded struct fields in ValidateRequest#1276
Merged
fix: [#817] make validator.Bind populate anonymous embedded struct fields in ValidateRequest#1276
Conversation
…elds in ValidateRequest
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1276 +/- ##
=======================================
Coverage 68.19% 68.19%
=======================================
Files 264 264
Lines 15425 15426 +1
=======================================
+ Hits 10519 10520 +1
Misses 4449 4449
Partials 457 457 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #817 by enabling the validator's Bind method to properly populate fields from anonymous embedded structs. The fix adds the Squash: true configuration to the mapstructure decoder, which flattens embedded struct fields during decoding.
Key Changes:
- Added
Squash: trueto theDecoderConfigin theBindmethod to handle embedded struct fields - Added test coverage for embedded struct field binding with a simple test case
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| validation/validator.go | Added Squash: true to mapstructure decoder configuration to enable embedded struct field population |
| validation/validator_test.go | Added Embed struct type and test case to verify embedded struct fields are properly bound |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📑 Description
Closes goravel/goravel#817
This pull request updates the struct binding logic in the
Validatorto support embedded structs, and adds corresponding unit tests to ensure the new behavior works as expected.Improvements to struct binding:
validation/validator.go: Added theSquash: trueoption to the decoder configuration in theBindmethod, enabling fields from embedded structs to be properly bound.Test coverage for embedded structs:
validation/validator_test.go: Introduced a new embedded structEmbedwithin the testDatastruct, and added a test case to verify that fields from embedded structs are correctly bound and validated. [1] [2] [3]✅ Checks