-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Custom validation tag is ignored when validating a field that is of type struct #367
Comments
@ptcoda I will try to take a look this week. |
Hey @ptcoda sorry for the delay, I was looking deep into the code and to make this work properly will definitely be a breaking change, I did not anticipate this specific use case; I will add this to the list of v10 improvements :) however, not to fret, all is not lost, this is actually a perfect use case for Struct Level validation; I would add a validation for your Please let me know if this will help :) |
I just hit the same problem, but I don't think this can be solved by Struct Level validation as far as I can tell. The problem is that the validator (in this case PS. Great library, thanks! |
## Fixes #367, #906 **Make sure that you've checked the boxes below before you submit PR:** - [x] Tests exist or have been written that cover this particular change. 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
Package version eg. v8, v9:
v9
Issue, Question or Enhancement:
The custom validation tag appears to have no impact when it is used against a field that is of type struct. If the tag is not registered, the validator library panics as expected, however if the tag is registered and deliberately set to return false, I would expect validation to fail.
However it does not.
Is this intended behaviour? Can field validation not be performed in this way? If I was to use my custom tag against a standard system type, such as a string, the validation fails as expected.
Apologies if this is covered in the documentation somewhere.
Code sample, to showcase or reproduce:
The text was updated successfully, but these errors were encountered: