-
Notifications
You must be signed in to change notification settings - Fork 125
Labels
bugSomething isn't workingSomething isn't working
Description
System (please complete the following information):
- OS:
masOs - GO Version:
1.23.3 - Pkg Version:
1.5.2
Describe the bug
When an struct has json tags and has an slice type in it error path is not complete
To Reproduce
package main
import (
"encoding/json"
"fmt"
"github.com/gookit/validate"
"os"
)
type (
InputGood struct {
Data []DataGood
}
DataGood struct {
Name string `validate:"required"`
}
InputBad struct {
Data []DataBad `json:"data"`
}
DataBad struct {
Name string `json:"name" validate:"required"`
}
)
func main() {
inputGood := InputGood{
Data: []DataGood{
{},
{},
},
}
validateData(inputGood)
inputBad := InputBad{
Data: []DataBad{
{},
{},
},
}
validateData(inputBad)
}
func validateData(i any) {
v := validate.Struct(i)
v.StopOnError = false
v.Validate()
_ = json.NewEncoder(os.Stdout).Encode(v.Errors)
fmt.Println()
fmt.Println()
fmt.Println()
}Expected behavior
Show error path using json tags instead struct attributes' names
Screenshots
This is the result of running above code

Additional context
It's just that 😃 Thank you for your time! 🎆
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working