-
Notifications
You must be signed in to change notification settings - Fork 14
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
Validate Params #113
base: master
Are you sure you want to change the base?
Validate Params #113
Conversation
…iven parameters & either raises an error or ignores unknown fields Signed-off-by: Shirish Pampoorickal <[email protected]>
…c_validate_params
…c_validate_params
…ted parameters on the endpoint - 'brainstem_validate_params!' validates input parameters against the documented parameters on the endpoint. It raises Brainstem::UnknownParams error when the input params are malformed or unkown params are encountered - 'brainstem_ignore_unknown_params!' returns a sanitized hash while excluding unknown params
…rning sanitized params Signed-off-by: Jason Carter <[email protected]>
This is awesome. What else needs to happen for this to go in? |
end | ||
|
||
def sanitize_input_params!(input_params) | ||
malformed_params_error! unless input_params.is_a?(Hash) && input_params.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we to_h
params at some point before this? Otherwise this won't work in Rails 5, since ActionController::Parameters
no longer descend from Hash
.
EDIT: It looks we call with_indifferent_access
on them above. I don't have an environment setup to test that on Rails 5 right now, but I'm not sure if ActionController::Parameters
supports that method in 5.
@brandonduff I was not very happy with the formatting of the error messages on nested attributes. I would be happy to talk through it if you like. |
@shirish-pampoorickal Would love to help if I can. May be fun to pair on. It would be great to start rolling this out in our controllers. I think it could do a lot to standardize error responses when invalid params are passed and save future devs time having to handle it. |
brainstem_validate_params!
raises an error if unknown parameters are encountered.