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

Validate nested structs (take 2) #668

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zenovich
Copy link

Fixes #367 .

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

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

Change Details:
This change allows using (any: custom or backed in) validations on nested structs. This is the corrected version of #591.

@go-playground/admins

Copy link
Contributor

@deankarn deankarn left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, it's close to what is needed just the order of validation needs to be struct validations then fields of that struct.

v.fldIsPointer = vFldIsPointerOld
ns = oldNs
structNs = oldStructNs
if len(v.errs) > previousErrorsCount {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately I think this suffers from the same issue as another take on validating structs using tags.

The validations for the structs need to be run first and then the fields of that struct IF no errors occurred on the struct validations. this is important to be able to use validations like required with structs.

Achieving this however requires reworking of how the caching works in the library. It is achievable but needs much larger changes to occur.

Copy link
Author

Choose a reason for hiding this comment

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

This has been already discussed, see #591 (comment)

@nodivbyzero
Copy link
Contributor

Should we close this PR?

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.

Custom validation tag is ignored when validating a field that is of type struct
3 participants