go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.06k stars 1.29k forks source link

StructPartial does not dive to slice of structs #1265

Open cascadetile opened 1 month ago

cascadetile commented 1 month ago

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

I would like to point out that StructPartial does not dive into slice of structs

Code sample, to showcase or reproduce:

type Order struct {
    Goods     []Good `json:"goods" validate:"required,min=1,max=30,dive"`
}
type Good struct {
    ID     int     `json:"id" validate:"required,gt=0"`
    Amount float64 `json:"amount" validate:"required,gt=0,max=5"`
}

err = validate.StructPartial(Order{Goods: []Good{{ID: -1, Amount: -1}}}, "Goods")
        if err != nil {
            for _, err := range err.(validator.ValidationErrors) {
                fmt.Printf("%+v\n", err)
            }
            return
        }