validator icon indicating copy to clipboard operation
validator copied to clipboard

XOR validation question

Open khawkinson opened this issue 2 years ago • 1 comments

  • [ 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 avatar Sep 28 '22 19:09 khawkinson

@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.

zemzale avatar Oct 05 '22 07:10 zemzale

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 avatar Dec 19 '23 22:12 zacharyarnaise

@zacharyarnaise yeah it looks like my test is now failing when it should, thanks!

khawkinson avatar Dec 20 '23 05:12 khawkinson