Skip to content

Conversation

JunaidIslam2105
Copy link
Contributor

Fixes

Fixed support for validating struct values inside map fields. Previously, if no tag followed endkeys, the struct values were skipped. This PR ensures such struct values are still validated according to their own tags.

Enhancements to validation logic:

  • Updated validator.go to handle map values that are structs or pointers to structs by diving into their fields for validation.
  • Added test cases covering struct validation in maps, including basic rules, pointer structs, nested structs, and edge cases like nil pointers.

Check #1430 for more details.

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

@JunaidIslam2105 JunaidIslam2105 requested a review from a team as a code owner June 1, 2025 07:47
@coveralls
Copy link

coveralls commented Jun 1, 2025

Coverage Status

coverage: 73.674% (+0.01%) from 73.661%
when pulling fe71d89 on JunaidIslam2105:map-struct-validation-bug
into 5b9542b on go-playground:master.

@JunaidIslam2105 JunaidIslam2105 changed the title Fix: support validation for map values with struct types #1430 Fix: support validation for map values with struct types Jun 1, 2025
@JunaidIslam2105
Copy link
Contributor Author

Hi @nodivbyzero, I’m new here. I’d really appreciate it if you could kindly take a look whenever you get a chance.

@nodivbyzero
Copy link
Contributor

Hi @nodivbyzero, I’m new here. I’d really appreciate it if you could kindly take a look whenever you get a chance.

Thanks for making these changes!
Everything looks good to me - just a small suggestion regarding the asserts.

…qual assertions consistently for error checks in map struct validation tests
@JunaidIslam2105
Copy link
Contributor Author

Hey @nodivbyzero, thanks for the kind guidance. I have refactored the tests to use Equal/NotEqual to keep things consistent with the rest of the codebase and added comments as well. Let me know if I need to make any other changes.

@nodivbyzero nodivbyzero merged commit dfc7ccd into go-playground:master Jun 3, 2025
11 checks passed
@JunaidIslam2105 JunaidIslam2105 deleted the map-struct-validation-bug branch June 3, 2025 17: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.

3 participants