Skip to content

do not collect params in route settings #2229

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

Merged
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 @@ -8,6 +8,7 @@

* [#2222](https://github.com/ruby-grape/grape/pull/2222): Autoload types and validators - [@ericproulx](https://github.com/ericproulx).
* [#2232](https://github.com/ruby-grape/grape/pull/2232): Fix kwargs support in shared params definition - [@dm1try](https://github.com/dm1try).
* [#2229](https://github.com/ruby-grape/grape/pull/2229): Do not collect params in route settings - [@dnesteryuk](https://github.com/dnesteryuk).
* Your contribution here.

### 1.6.2 (2021/12/30)
Expand Down
1 change: 1 addition & 0 deletions benchmark/nested_params.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require 'grape'
require 'benchmark/ips'

Expand Down
15 changes: 0 additions & 15 deletions lib/grape/dsl/desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,6 @@ def desc(description, options = {}, &config_block)
route_setting :description, options
end

def description_field(field, value = nil)
description = route_setting(:description)
if value
description ||= route_setting(:description, {})
description[field] = value
elsif description
description[field]
end
end

def unset_description_field(field)
description = route_setting(:description)
description&.delete(field)
end

# Returns an object which configures itself via an instance-context DSL.
def desc_container(endpoint_configuration)
Module.new do
Expand Down
9 changes: 1 addition & 8 deletions lib/grape/dsl/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def reset_validations!
unset_namespace_stackable :declared_params
unset_namespace_stackable :validations
unset_namespace_stackable :params
unset_description_field :params
end

# Opens a root-level ParamsScope, defining parameter coercions and
Expand All @@ -41,14 +40,8 @@ def params(&block)
end

def document_attribute(names, opts)
setting = description_field(:params)
setting ||= description_field(:params, {})
Array(names).each do |name|
full_name = name[:full_name].to_s
setting[full_name] ||= {}
setting[full_name].merge!(opts)

namespace_stackable(:params, full_name => opts)
namespace_stackable(:params, name[:full_name].to_s => opts)
end
end
end
Expand Down
5 changes: 0 additions & 5 deletions spec/grape/dsl/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ class Dummy
expect(subject.namespace_stackable(:params)).to eq []
end

it 'resets documentation params' do
expect(subject.route_setting(:description)[:params]).to be_nil
end

it 'does not reset documentation description' do
expect(subject.route_setting(:description)[:description]).to eq 'lol'
end
Expand All @@ -62,7 +58,6 @@ class Dummy

it 'creates a param documentation' do
expect(subject.namespace_stackable(:params)).to eq(['xxx' => { foo: 'bar' }])
expect(subject.route_setting(:description)).to eq(params: { 'xxx' => { foo: 'bar' } })
end
end
end
Expand Down