Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Validate Params #113

wants to merge 12 commits into from

Conversation

shirish-pampoorickal
Copy link
Member

@shirish-pampoorickal shirish-pampoorickal commented Apr 12, 2018

  • Add the capability to validate params based on documented parameters on endpoints. Invoking
    brainstem_validate_params! raises an error if unknown parameters are encountered.

Jason Carter and others added 10 commits April 4, 2018 14:16
…iven parameters & either raises an error or ignores unknown fields

Signed-off-by: Shirish Pampoorickal <[email protected]>
…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
@shirish-pampoorickal shirish-pampoorickal changed the title Validate / Ignore Unknown Params Validate Params May 15, 2018
@brandonduff
Copy link
Contributor

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?
Copy link
Contributor

@brandonduff brandonduff Jul 18, 2018

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.

@shirish-pampoorickal
Copy link
Member Author

@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.

@brandonduff
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants