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

Missing nested optional array transformed into hash with declared method #1847

Closed
hyunskang opened this issue Dec 14, 2018 · 2 comments
Closed
Labels

Comments

@hyunskang
Copy link

hyunskang commented Dec 14, 2018

grape v1.1.0
ruby v2.4.4

API definition:

params do
    requires :obj, type: Hash, allow_blank: false do
    requires :id, type: Integer, allow_blank: false
    optional :arr, type: Array, allow_blank: true do
      requires :k, type: String, allow_blank: false
      requires :v, type: String, allow_blank: false
    end
  end
end
put '/results' do
  present(declared(params))
end

Request body:

{ 
    "obj": { 
        "id": 1 
    } 
}

Response body:

{
    "obj": {
        "id": 1,
        "arr": {
            "k": null,
            "v": null
        }
    }
}

When nested array is missing from the request, declared transforms it into a Hash with nil values.
I would expect it to return nil or an empty array. It looks like there was an issue opened for it, but the specs written for it do not seem to be testing the issue. #1642

@hyunskang hyunskang changed the title Missing nested optional array transformed to hash with declared method Missing nested optional array transformed into hash with declared method Dec 14, 2018
@dblock dblock added the bug? label Dec 16, 2018
@dblock
Copy link
Member

dblock commented Dec 16, 2018

Makes sense, appreciate a PR with additional specs and maybe even a fix? :)

basjanssen pushed a commit to basjanssen/grape that referenced this issue Feb 28, 2020
Integers don't respond to the `empty?` method. It caused issue with optional
params as described in ruby-grape#1847.
@dnesteryuk
Copy link
Member

@kadotami fixed this issue in #2043 🎉

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

3 participants