Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (v *Validator) Bind(ptr any) error {
TagName: "form",
Result: &ptr,
DecodeHook: v.castValue(),
Squash: true,
})
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions validation/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
)

func TestBind_Rule(t *testing.T) {
type Embed struct {
C string `form:"c" json:"c"`
}
type Data struct {
A string `form:"a" json:"a"`
B int `form:"b" json:"b"`
Expand All @@ -44,6 +47,7 @@ func TestBind_Rule(t *testing.T) {
TimestampMicro *carbon.TimestampMicro `form:"timestamp_micro" json:"timestamp_micro"`
TimestampNano *carbon.TimestampNano `form:"timestamp_nano" json:"timestamp_nano"`
Time *time.Time `form:"time" json:"time"`
Embed
}

tests := []struct {
Expand Down Expand Up @@ -636,6 +640,14 @@ func TestBind_Rule(t *testing.T) {
assert.Equal(t, file.Filename, data.Files[1].Filename)
},
},
{
name: "data has embed struct field",
data: validate.FromMap(map[string]any{"c": "cc"}),
rules: map[string]string{"c": "required"},
assert: func(data Data) {
assert.Equal(t, "cc", data.C)
},
},
}

validation := NewValidation()
Expand Down
Loading