Skip to content

Commit

Permalink
Merge 72fa88d into 9e68e46
Browse files Browse the repository at this point in the history
  • Loading branch information
numbata committed Apr 25, 2024
2 parents 9e68e46 + 72fa88d commit 2140ff0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Features

* [#2432](https://github.com/ruby-grape/grape/pull/2432): Deep merge for group parameter attributes - [@numbata](https://github.com/numbata).
* [#2419](https://github.com/ruby-grape/grape/pull/2419): Add the `contract` DSL - [@dgutov](https://github.com/dgutov).
* [#2371](https://github.com/ruby-grape/grape/pull/2371): Use a param value as the `default` value of other param - [@jcagarcia](https://github.com/jcagarcia).
* [#2377](https://github.com/ruby-grape/grape/pull/2377): Allow to use instance variables values inside `rescue_from` - [@jcagarcia](https://github.com/jcagarcia).
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def requires(*attrs, &block)

opts = attrs.extract_options!.clone
opts[:presence] = { value: true, message: opts[:message] }
opts = @group.merge(opts) if instance_variable_defined?(:@group) && @group
opts = @group.deep_merge(opts) if instance_variable_defined?(:@group) && @group

if opts[:using]
require_required_and_optional_fields(attrs.first, opts)
Expand All @@ -149,7 +149,7 @@ def optional(*attrs, &block)

opts = attrs.extract_options!.clone
type = opts[:type]
opts = @group.merge(opts) if instance_variable_defined?(:@group) && @group
opts = @group.deep_merge(opts) if instance_variable_defined?(:@group) && @group

# check type for optional parameter group
if attrs && block
Expand Down
7 changes: 7 additions & 0 deletions spec/grape/dsl/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def extract_message_option(attrs)
expect(subject.validate_attributes_reader).to eq([[:id], { type: Integer, desc: 'Identity.' }])
expect(subject.push_declared_params_reader).to eq([:id])
end

it 'merges the group attributes' do
subject.with(documentation: { in: 'body' }) { subject.optional :vault, documentation: { default: 33 } }

expect(subject.validate_attributes_reader).to eq([[:vault], { documentation: { in: 'body', default: 33 } }])
expect(subject.push_declared_params_reader).to eq([:vault])
end
end

describe '#mutually_exclusive' do
Expand Down

0 comments on commit 2140ff0

Please sign in to comment.