Skip to content

fix: [#817] make validator.Bind populate anonymous embedded struct fields in ValidateRequest#1276

Merged
almas-x merged 1 commit intomasterfrom
almas/#817
Nov 25, 2025
Merged

fix: [#817] make validator.Bind populate anonymous embedded struct fields in ValidateRequest#1276
almas-x merged 1 commit intomasterfrom
almas/#817

Conversation

@almas-x
Copy link
Contributor

@almas-x almas-x commented Nov 24, 2025

📑 Description

Closes goravel/goravel#817

This pull request updates the struct binding logic in the Validator to support embedded structs, and adds corresponding unit tests to ensure the new behavior works as expected.

Improvements to struct binding:

  • validation/validator.go: Added the Squash: true option to the decoder configuration in the Bind method, enabling fields from embedded structs to be properly bound.

Test coverage for embedded structs:

  • validation/validator_test.go: Introduced a new embedded struct Embed within the test Data struct, and added a test case to verify that fields from embedded structs are correctly bound and validated. [1] [2] [3]

✅ Checks

  • Added test cases for my code

@almas-x almas-x requested a review from a team as a code owner November 24, 2025 08:48
Copilot AI review requested due to automatic review settings November 24, 2025 08:48
@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.19%. Comparing base (6252baa) to head (f464610).
⚠️ Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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: true to the DecoderConfig in the Bind method 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.

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

Good catch, thanks!

@almas-x almas-x merged commit c6d10d2 into master Nov 25, 2025
20 checks passed
@almas-x almas-x deleted the almas/#817 branch November 25, 2025 01:13
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.

Request validation does not support binding anonymous embedded struct fields

3 participants