-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Package version eg. v9, v10:
v10
Issue, Question or Enhancement:
The validator sees no difference between an additional field of type "struct" and embedded structures. This complicates further post-processing and forces you to pre-validate each structure and then merge the results.
Is there any way to correct this behavior? For example, by adding an additional tag.
Code sample, to showcase or reproduce:
package main
import (
"fmt"
"github.com/go-playground/validator/v10"
)
type User struct {
Name string `validate:"required"`
}
type GroupA struct {
Admin User
}
type GroupB struct {
User
}
func main() {
v := validator.New()
errs := v.Struct(new(GroupA))
fmt.Println("GroupA: ", errs)
errs = v.Struct(new(GroupB))
fmt.Println("GroupB: ", errs)
}
Output
GroupA: Key: 'GroupA.Admin.Name' Error:Field validation for 'Name' failed on the 'required' tag
GroupB: Key: 'GroupB.User.Name' Error:Field validation for 'Name' failed on the 'required' tag
But for "GroupB" the key "GroupB.Name" is expected.
ramongtx, abemedia, 23doors and vm-001
Metadata
Metadata
Assignees
Labels
No labels