go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.41k stars 1.31k forks source link

Feature: nested struct validation #1122

Closed MysteriousPotato closed 1 year ago

MysteriousPotato commented 1 year ago

Fixes #367, #906

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

A test has been added for custom tags, however I was not brave enough to actually update the tests for all required/excluded tag variants before getting an initial feedback, but I'm willing to do so if this ever gets any further.

Same goes for documentation.

The implementation supports both struct and struct pointer validations for custom tags and all required/excluded tag variants.

Struct validity is evaluated first and fields are evaluated only if the struct is valid, though I'm not sure if this is the desired behavior.

@go-playground/validator-maintainers

coveralls commented 1 year ago

Coverage Status

coverage: 73.987% (+0.02%) from 73.972% when pulling b43cc52401fb4df932fb933b43f2614a8e97c20d on MysteriousPotato:master into bd1113d5c1901c5205fc0a7af031a11268ff13ee on go-playground:master.

deankarn commented 1 year ago

Thanks for the PR @MysteriousPotato!

I like the approach here and yes fields after valid struct is the order that's required to not cause breaking changes. Going to let it sit with me for a big to digest.

deankarn commented 1 year ago

@MysteriousPotato I really like this PR!

If you can update the tests I'd be happy to merge this :)

MysteriousPotato commented 1 year ago

@deankarn Great!

There are now tests for all tags that are compatible with this implementation of nested struct validation. This inlcudes the tags below:

I did not make a lot of changes to the documentation except a few places where the behavior is specified for each type. Let me know if you want the documentation to be more explicit about the behavior.

deankarn commented 1 year ago

Awesome @MysteriousPotato!

I will try and review early this week :)

deankarn commented 1 year ago

Sorry I haven’t forgotten about this, just been a heck of a week thus far, still high on my list :)