From 27609d8da8a69a1eae3b14bd034b70065a3ad253 Mon Sep 17 00:00:00 2001 From: John Guo Date: Fri, 26 Aug 2022 14:30:49 +0800 Subject: [PATCH] fix issue #1921 (#2091) * CI updates * fix issue in OpenAPI json marshaling of embedded struct definition; improve command gen service * improve logging content printing for internal log * fix issue #1921 --- util/gvalid/gvalid_validator_check_value.go | 7 +++++- .../gvalid_z_unit_feature_recursive_test.go | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/util/gvalid/gvalid_validator_check_value.go b/util/gvalid/gvalid_validator_check_value.go index 4678582c5..ebfb6d01f 100644 --- a/util/gvalid/gvalid_validator_check_value.go +++ b/util/gvalid/gvalid_validator_check_value.go @@ -560,8 +560,13 @@ func (v *Validator) doCheckValueRecursively(ctx context.Context, in doCheckValue // Ignore data, assoc, rules and messages from parent. var ( validator = v.Clone() - toBeValidatedObject = reflect.New(in.Type).Interface() + toBeValidatedObject interface{} ) + if in.Type.Kind() == reflect.Ptr { + toBeValidatedObject = reflect.New(in.Type.Elem()).Interface() + } else { + toBeValidatedObject = reflect.New(in.Type).Interface() + } validator.assoc = nil validator.rules = nil validator.messages = nil diff --git a/util/gvalid/gvalid_z_unit_feature_recursive_test.go b/util/gvalid/gvalid_z_unit_feature_recursive_test.go index f687a5172..ab3449eba 100755 --- a/util/gvalid/gvalid_z_unit_feature_recursive_test.go +++ b/util/gvalid/gvalid_z_unit_feature_recursive_test.go @@ -399,3 +399,25 @@ func Test_Issue1983(t *testing.T) { t.AssertNil(err) }) } + +// https://github.com/gogf/gf/issues/1921 +func Test_Issue1921(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + type SearchOption struct { + Size int `v:"max:100"` + } + type SearchReq struct { + Option *SearchOption `json:"option,omitempty"` + } + + var ( + req = SearchReq{ + Option: &SearchOption{ + Size: 10000, + }, + } + ) + err := g.Validator().Data(req).Run(ctx) + t.Assert(err, "The Size value `10000` must be equal or lesser than 100") + }) +}