govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

Wrong error msg when required field is not set

Open sclu1034 opened this issue 6 years ago • 2 comments

When govalidator.SetFieldsRequiredByDefault is enabled, the error message for an unset field is misleading. It reports "validation missing" for any validation except valid:"-":

All fields are required to at least have one validation defined;

Full Test Case

package main

import (
	"log"

	"github.com/asaskevich/govalidator"
)

type S struct {
	Url string `valid:"url"`
}

func main() {
	govalidator.SetFieldsRequiredByDefault(true)
	s := &S{}

	_, err := govalidator.ValidateStruct(s)
	if err != nil {
		log.Print(err)
	}
}

sclu1034 avatar Sep 03 '17 09:09 sclu1034

I think this is expected behavior, unless I'm not understanding the documentation correctly. See the main README. Search for Activate behavior to require all fields have a validation tag by default. It explains what you are seeing and yes "-" would mark a specific field except from the check.

jasonlam604 avatar Oct 19 '17 15:10 jasonlam604

Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev