contiamo / openapi-generator-go

An opinionated OpenAPI v3 code generator for Go. Use this to generate API models and router scaffolding.
MIT License
107 stars 12 forks source link

URL validation is not correct #12

Closed LucasRoesler closed 3 years ago

LucasRoesler commented 3 years ago

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

See https://pkg.go.dev/github.com/asaskevich/govalidato for the definition of the validators

LucasRoesler commented 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