validator
validator copied to clipboard
XOR validation question
- [ x] I have looked at the documentation here first?
- [ x] I have looked at the examples provided that may showcase my question here?
Package version eg. v9, v10: v10
Issue, Question or Enhancement:
I'm attempting to do XOR validations with structs. Works fine with strings as shown in this code example: https://go.dev/play/p/l67xEMBnKfM
Code sample, to showcase or reproduce:
// Essentially this does not work:
type A struct {
FieldA *string
}
type B struct {
FieldB *string
}
type StructTest struct {
StructA *A `validate:"required_without=StructB,excluded_with=StructB"`
StructB *B `validate:"required_without=StructA,excluded_with=StructA"`
}
// But this does work:
type StringTest struct {
A *string `validate:"required_without=B,excluded_with=B"`
B *string `validate:"required_without=A,excluded_with=A"`
}
I'm at a loss on how to get this to work for StructTest
, what am I missing?
Thanks in advance!
@khawkinson Thanks for the issue. This seems to be some kind of bug. I will try to write a test case for this and check what can I do.
This might be eligible for closing, I'm unable to reproduce the issue with the latest version of the package. I believe this was fixed by https://github.com/go-playground/validator/pull/1122 released in v10.15.0.
@zacharyarnaise yeah it looks like my test is now failing when it should, thanks!