diff --git a/pkg/infrastructure/validation/validation.go b/pkg/infrastructure/validation/validation.go index 190e0f0e..134e750e 100644 --- a/pkg/infrastructure/validation/validation.go +++ b/pkg/infrastructure/validation/validation.go @@ -269,6 +269,11 @@ func (v *Validation) apply(chk Validator, obj interface{}) *Result { Field := "" Label := "" parts := strings.Split(key, ".") + if len(parts) == 2 { + Field = parts[0] + Name = parts[1] + Label = Field + } if len(parts) == 3 { Field = parts[0] Name = parts[1] diff --git a/pkg/infrastructure/validation/validation_test.go b/pkg/infrastructure/validation/validation_test.go index b4b5b1b6..bca4f560 100644 --- a/pkg/infrastructure/validation/validation_test.go +++ b/pkg/infrastructure/validation/validation_test.go @@ -607,3 +607,28 @@ func TestCanSkipAlso(t *testing.T) { } } + +func TestFieldNoEmpty(t *testing.T) { + type User struct { + Name string `json:"name" valid:"Match(/^[a-zA-Z][a-zA-Z0-9._-]{0,31}$/)"` + } + u := User{ + Name: "*", + } + + valid := Validation{} + b, err := valid.Valid(u) + if err != nil { + t.Fatal(err) + } + if b { + t.Fatal("validation should be passed") + } + if len(valid.Errors) == 0 { + t.Fatal("validation should be passed") + } + validErr := valid.Errors[0] + if len(validErr.Field) == 0 { + t.Fatal("validation should be passed") + } +}