Skip to content

Validation updates: call before before validation / added param value when raising ValidationError #239

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

Merged
merged 5 commits into from
Sep 6, 2012

Conversation

adamgotterer
Copy link
Contributor

This is an update to #221

  • Updated README to have better Validation documentation
  • Changed order of operations so that endpoint calls before before validating params
  • Added param value when raising ValidationError
  • Added .swo file to .gitignore (saw one sneak in)

@adamgotterer
Copy link
Contributor Author

@schmurfy maybe you can add a section about coercion with virtus? I wasn't able to find a list of the supported types.

@schmurfy
Copy link
Contributor

schmurfy commented Sep 6, 2012

Why running before block before the validation is applied ?
You will deal with different data in the before block and in the endpoint block,really weird.

I would prefer a lot adding another method like "before_validation" or something like that and keep the current one untouched.

As for the supported Virtus types I don't have a closed list either but pretty much all the basic ruby types should be supported.

@adamgotterer
Copy link
Contributor Author

I'm okay adding a before_validation method if people think it would be useful?

You asked why I want to run the block before validation. Things like adding headers, authenticating or transforming/creating some piece of information are really bizarre to run after validation. But would definitely be solved in a before_validation. Also want to make sure this is fully backwards compatible. before ran literally before everything pre-validation.

@schmurfy
Copy link
Contributor

schmurfy commented Sep 6, 2012

If you don't define any validation nothing will be done in the validation step so we remain fully compatible :)
If someone wants to add validations then he/she will have to adapt the code which seems perfectly reasonable for me.

@dblock
Copy link
Member

dblock commented Sep 6, 2012

I am with @schmurfy, I'm merging this. Feel free to make a PR that introduces a before_validation callback.

dblock added a commit that referenced this pull request Sep 6, 2012
Validation updates: call `before` before validation / added param value when raising ValidationError
@dblock dblock merged commit e5b9422 into ruby-grape:master Sep 6, 2012
@schmurfy
Copy link
Contributor

schmurfy commented Sep 6, 2012

by merging this the before block is now run before the validation, since we agree with me I am not sure this is what you wanted to do.

@dblock
Copy link
Member

dblock commented Sep 6, 2012

@schmurfy I think it's correct, because before means "before anything", so there should be a before_validation, an after_validation and the before block is now in the right place.

@schmurfy
Copy link
Contributor

schmurfy commented Sep 6, 2012

I am really not sure having before run before anything else is the expected behavior but going with a before_validation and after_validation would definitely remove any doubts on what to expects.

@adamgotterer
Copy link
Contributor Author

I'm happy to add the additional method. Right now its just a matter of verbiage. Our options are before / after_validation or before_validation / before. They will both do the same thing.

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

Successfully merging this pull request may close these issues.

3 participants