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

Validing array but checking for hash? #49

Open
jberry opened this issue Sep 12, 2016 · 1 comment
Open

Validing array but checking for hash? #49

jberry opened this issue Sep 12, 2016 · 1 comment

Comments

@jberry
Copy link

jberry commented Sep 12, 2016

In lib/apipie_bindings/action.rb validate function, we have

if param_description.expected_type == :array
    value.each.with_index do |item, i|
        errors += validate(param_description.params, item, add_to_path(path, param_description.name, i))
    end
end

But when it's calling itself (the validate function), and the first line in that function is:

return [ErrorData.new(:invalid_type, path, 'Hash')] unless values.respond_to?(:keys)

Maybe I'm missing something (sure possible), but isn't that taking a value we're expecting to be an array, and checking against if it's a hash and returning 'it's not a hash!' error, even when its NOT supposed to be a hash? At least, that seems to be what I'm running into; bypassing this validation check and my call works fine.

@mbacovsky
Copy link
Contributor

Hello @jberry, sorry for not responding sooner. The validation looks correct. If the parameter is of type :array we validate the individual items one by one and the individual items are supposed to be hashes. E.g.

{
  :name => 'Bob',
  :emails => [
     {
        :address => '[email protected]'
     },
     {
        :address => '[email protected]'
     }
  ]
}

Perhaps your data use different format, could you attach your data sample and API description of it. The excerpt containing the array should be enough.

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

No branches or pull requests

2 participants