-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required controller input validation #171
Comments
I'm thinking of doing an easy version of this first where we generate a struct compatible with https://github.com/go-playground/validator. Long-run I'd like to generate the unmarshaler (maybe using or inspired by easyjson), but that's going to take some time and I'd like to have the interface working earlier. |
Users already have to add |
That's even more straightforward solution. I think that'd be a great first step! My main concern of just allowing an unaltered version of this is around needing to break the API at some point. I'm doubtful all the decisions in validator will be good decisions for Bud. But maybe that could be a 1.x or 2.x transition. I like the idea of getting all the pieces in place, then refining as we learn more. |
(Linking an existing draft: #15) If we go the validator route, we'll still want to generate required struct tags. For example: func (c *Controller) Signup(email, password string, age *int) error { ... } Would correspond to the following generated struct: type SignupInput struct {
Email string `json:"email" validate:"required"`
Password string `json:"password" validate:"required"`
Age *int `json:"age"`
} Bud's API contract is required by default rather than optional by default like Go. If you want optional, you use pointers. The documentation has more details: https://www.notion.so/Hey-Bud-4d81622cc49942f9917c5033e5205c69#f385e0bd96d349f1b78da9fbfc305eb6 |
Using |
That's a good point @FeldrinH. I think this needs to be thought through a bit further, but the place we'd like to get to is when you have func Signup(email, password string, age *int) The following would be allowed: { "email": "", "password": "" } But this would not be: { "email": "" } Because |
Given the following controller/controller.go:
If you run the following request:
GET /?name=Alice
, you'll get back the following response:It should actually be a validation error, "email cannot be blank", never run the controller action and most likely return a 422.
The text was updated successfully, but these errors were encountered: