validate icon indicating copy to clipboard operation
validate copied to clipboard

Feature request: Override validation rule within a scene

Open OscarVanL opened this issue 3 years ago • 0 comments

I have defined some custom scenes so that I can validate my struct in different ways.

func (User) ConfigValidation(v *validate.Validation) {
	v.WithScenes(validate.SValues{
		Create:      []string{"Kind", "Name", "Birthday"},
		Update:     []string{"ID", "Kind", "Name", "Birthday"},
	})
}

I would love it if I could specify different rules for each of these scene fields.

For example, when I create a user I want to validate that the user has left ID empty. It is not enough to skip validation, I must make sure they have not filled it out.

func (User) ConfigValidation(v *validate.Validation) {
	v.WithScenes(validate.SValues{
		Create:      []string{"ID:'empty'", "Kind", "Name", "Birthday"},
		Update:     []string{"ID", "Kind", "Name", "Birthday"},
	})
}

If no rule is provided inside the SValue, then it should fall back to the rule defined on the struct tags.

OscarVanL avatar Aug 26 '22 13:08 OscarVanL