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

Make the type in group of required params required (#722) #886

Merged
merged 1 commit into from
Jan 26, 2015

Conversation

jrichter1
Copy link
Contributor

Made it so groups with required params will demand a type to be set to Array or Hash, errors otherwise (made a new exception for that).
Covered with some tests, also had to modify several existing tests to support this.

@@ -33,4 +33,5 @@ en:
at_least_one: 'are missing, at least one parameter must be provided'
exactly_one: 'are missing, exactly one parameter must be provided'
all_or_none: 'provide all or none of parameters'
invalid_group_type: 'group of required parameters must have a specified type of Array or Hash, type provided: %{group_type}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to have the type provided in the message, typically error messages should be fixed, and potentially additional data should indicate the source. I would make this just group of required parameters must be Array or Hash.

@dblock
Copy link
Member

dblock commented Jan 11, 2015

Can you please elaborate why this change for required and not optional params? I don't see the difference.

This needs CHANGELOG, either way..

@jrichter1
Copy link
Contributor Author

There is no specific reasoning behind this, other than what I understood from the issue. It seemed to me that it is specifically targeted at required param groups.
If you tell me to change it for optional as well, then I shall do so.

@dblock
Copy link
Member

dblock commented Jan 12, 2015

Lets step back (and I re-read everything, I realize I totally contradicted myself :)): #722 says that we want an error when the type is not provided so that people aren't confused. Try to do that, but I do think it should be for any group, not just a required group. I think it should raise a clear MissingGroupTypeError (feel free to suggest a different name) in the case the type is missing and it should raise an explicit UnsupportedGroupTypeError in the case the type is not Hash or Array. What do you think?

@jrichter1
Copy link
Contributor Author

Sounds good to me, I'll get to it then.

@jrichter1
Copy link
Contributor Author

So I finally got to take a stab at it, what do you think?

# check type for optional parameter group
if attrs && block_given?
fail Grape::Exceptions::MissingGroupTypeError.new if type.nil?
fail Grape::Exceptions::UnsupportedGroupTypeError.new if type != Array && type != Hash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more idiomatic to say [Hash, Array].include?(type), more future-proof.

@dblock
Copy link
Member

dblock commented Jan 25, 2015

I like it, squash the commits, see my minor comment and lets merge this.

@jrichter1
Copy link
Contributor Author

Done and done. Cheers!

@dblock
Copy link
Member

dblock commented Jan 26, 2015

I forgot something, this needs a section in UPGRADING, please. Sorry about that.

@jrichter1
Copy link
Contributor Author

Should be updated now

dblock added a commit that referenced this pull request Jan 26, 2015
Make the type in group of required params required (#722)
@dblock dblock merged commit 89591f2 into ruby-grape:master Jan 26, 2015
@dblock
Copy link
Member

dblock commented Jan 26, 2015

Merged.

@DavidHooper
Copy link

The README.md needs updating to reflect this change.

@dblock
Copy link
Member

dblock commented Nov 11, 2015

Right, @jrichter1 could you please do that?

namusyaka added a commit that referenced this pull request Mar 21, 2017
namusyaka added a commit that referenced this pull request Mar 21, 2017
dblock added a commit that referenced this pull request Mar 21, 2017
fix missing type specification in docs, ref #886
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