grape icon indicating copy to clipboard operation
grape copied to clipboard

Params: optional arrays within hashes/JSON objects broken

Open dleavitt opened this issue 5 years ago • 5 comments

See failing tests below for more specifics.

To reproduce In a params block, define an array param within a Hash or JSON param:

params do
  optional :data, type: Hash do
    optional :array, type: Array do
      optional :name, type: String
    end
  end
end

When the request body looks like this: { data: {} } I'd expect that calling declared(params) within the route would return something like this: { data: { array: [] } } or maybe this: { data: {} }

What's actually returned is this: { data: { array: { name: nil } } }

A hash rather than an array.

dleavitt avatar Feb 28 '20 03:02 dleavitt

1 Warning
:warning: Unless you’re refactoring existing code, please update CHANGELOG.md.
1 Message
:book: We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!

Here's an example of a CHANGELOG.md entry:

* [#2001](https://github.com/ruby-grape/grape/pull/2001): Params: optional arrays within hashes/json objects broken - [@dleavitt](https://github.com/dleavitt).

Generated by :no_entry_sign: danger

grape-bot avatar Feb 28 '20 03:02 grape-bot

Makes sense, thanks for the test!

myxoh avatar Mar 04 '20 11:03 myxoh

@dleavitt now that we have a test (thanks), try fixing it?

dblock avatar Mar 04 '20 14:03 dblock