I’m trying to understand how does the open api sepcification work using go language.
I created yaml file which I want to generate to my go code for requests and responses structs.
But some structs need the custom validator. So wrote it in this way:
var validate *validator.Validate
func init() {
validate = validator.New()
if err := validate.RegisterValidation("email", validateEmail); err != nil {
logger.Fatalf("Couldn't register email validator, err=%v", err)
}
}
func validateEmail(fl validator.FieldLevel) bool {
email := fl.Field().String()
emailRegex := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$`
return regexp.MustCompile(emailRegex).MatchString(email)
}
So I can write struct with such validator now
type somStruct struct {
Email string `validate:"email"`
}
So is it possible to add to open api specification that will be generated to such struct?