Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [#2546](https://github.com/ruby-grape/grape/pull/2546): Fix middleware with keywords - [@ericproulx](https://github.com/ericproulx).
* [#2547](https://github.com/ruby-grape/grape/pull/2547): Remove jsonapi related code - [@ericproulx](https://github.com/ericproulx).
* [#2548](https://github.com/ruby-grape/grape/pull/2548): Formatting from header acts like versioning from header - [@ericproulx](https://github.com/ericproulx).
* [#2552](https://github.com/ruby-grape/grape/pull/2552): Fix declared params optional array - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

### 2.3.0 (2025-02-08)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def declared_hash_attr(passed_params, options, declared_param, params_nested_pat
else
# If it is not a Hash then it does not have children.
# Find its value or set it to nil.
return unless options[:include_missing] || passed_params.key?(declared_param)
return unless options[:include_missing] || passed_params.try(:key?, declared_param)

rename_path = params_nested_path + [declared_param.to_s]
renamed_param_name = renamed_params[rename_path]
Expand Down
22 changes: 22 additions & 0 deletions spec/grape/endpoint/declared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -856,4 +856,26 @@
end
end
end

describe 'optional_array' do
subject { last_response }

let(:app) do
Class.new(Grape::API) do
params do
requires :z, type: Array do
optional :a, type: Integer
end
end

post do
declared(params, include_missing: false)
end
end
end

before { post '/', { z: [] } }

it { is_expected.to be_successful }
end
end