Closed LucasRoesler closed 3 years ago
We might want to consider customizing the error message as well, consider this failing test case from Hub when i swap to the is.URL
. the error is very generic. Perhaps we should say must be a valid URL with HTTP or HTTPS scheme
as the custom error message instead?
expected: models.FieldErrorResponse{Errors:[]models.FieldError{models.FieldError{Key:"externalURL", Message:"must have HTTP or HTTPS as scheme", Type:"FieldError"}}}
actual : models.FieldErrorResponse{Errors:[]models.FieldError{models.FieldError{Key:"externalURL", Message:"must be a valid URL", Type:"FieldError"}}}
To set the custom message you can use the Error(string) Rule
method to set a new message value https://github.com/go-ozzo/ozzo-validation#customizing-error-messages
The URL validation uses
IsRequestURL
this looks correct, but is really validating it as a URI with a non-empty schema value.Instead we should be using
isURL
.I propose that we change the validation code so that
url
corresponds to theis.URL
validatoruri
corresponds to theis.RequestURI
validatorrequest-uri
corresponds tois.RequestURL
See https://pkg.go.dev/github.com/asaskevich/govalidato for the definition of the validators