From 6f81b7d8d0b81a4c5c233d7d83221dac425da9fe Mon Sep 17 00:00:00 2001 From: nigelis Date: Tue, 1 Sep 2020 21:11:11 +0800 Subject: [PATCH] Validate tag omitempty, only base on field value --- validator.go | 2 +- validator_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/validator.go b/validator.go index 342e72e..f097f39 100644 --- a/validator.go +++ b/validator.go @@ -249,7 +249,7 @@ OUTER: v.cf = cf v.ct = ct - if !v.fldIsPointer && !hasValue(v) { + if !hasValue(v) { return } diff --git a/validator_test.go b/validator_test.go index e76a3cd..a26dc75 100644 --- a/validator_test.go +++ b/validator_test.go @@ -8858,6 +8858,16 @@ func TestRequiredWithout(t *testing.T) { AssertError(t, errs, "Field6", "Field6", "Field6", "Field6", "required_without") AssertError(t, errs, "Field7", "Field7", "Field7", "Field7", "required_without") AssertError(t, errs, "Field8", "Field8", "Field8", "Field8", "required_without") + + test3 := struct { + Field1 *string `validate:"required_without=Field2,omitempty,min=1" json:"field_1"` + Field2 *string `validate:"required_without=Field1,omitempty,min=1" json:"field_2"` + }{ + Field1: &fieldVal, + } + + errs = validate.Struct(&test3) + Equal(t, errs, nil) } func TestRequiredWithoutAll(t *testing.T) {