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

Validator fails if number is passed instead of object #1860

Closed
marvinthepa opened this issue Feb 4, 2019 · 3 comments
Closed

Validator fails if number is passed instead of object #1860

marvinthepa opened this issue Feb 4, 2019 · 3 comments
Labels

Comments

@marvinthepa
Copy link

undefined method `empty?' for 1:Fixnum: grape-1.0.2/lib/grape/validations/validators/base.rb:41:in `block in validate!'

This happens for something like this:

        params do
          optional :foos, :type => Array do
            optional :bar, :type => String
          end
        end

and then POSTing something like this:

{ "foos": [1] }

Setting requires :bar (instead of optional) fixes this.

While it is arguable that allowing empty objects does not make too much sense, who knows what users might want?

The problem is here:

next if !@scope.required? && resource_params.empty?

It probably makes sense to check if resource_params is actually a hash in this case.

@dblock
Copy link
Member

dblock commented Feb 4, 2019

Looks like a legit bug, please PR a fix.

@dblock dblock added the bug? label Feb 4, 2019
@marvinthepa
Copy link
Author

I will try. Might take me some time to get around it, though.

@dblock
Copy link
Member

dblock commented Dec 23, 2019

Closed via #1947 (comment)

@dblock dblock closed this as completed Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants