From d52e1fcff675b79735cfcf9872eebf5c7684358e Mon Sep 17 00:00:00 2001 From: Dmitriy Nesteryuk Date: Tue, 4 Jan 2022 17:29:52 +0200 Subject: [PATCH] do not collect params in route settings --- CHANGELOG.md | 1 + benchmark/nested_params.rb | 1 + lib/grape/dsl/desc.rb | 15 --------------- lib/grape/dsl/validations.rb | 9 +-------- spec/grape/dsl/validations_spec.rb | 5 ----- 5 files changed, 3 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fb291f76a..3fecadadce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/benchmark/nested_params.rb b/benchmark/nested_params.rb index 2523939b8e..f7cf0798ce 100644 --- a/benchmark/nested_params.rb +++ b/benchmark/nested_params.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'grape' require 'benchmark/ips' diff --git a/lib/grape/dsl/desc.rb b/lib/grape/dsl/desc.rb index ab19bfd056..b606639e81 100644 --- a/lib/grape/dsl/desc.rb +++ b/lib/grape/dsl/desc.rb @@ -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 diff --git a/lib/grape/dsl/validations.rb b/lib/grape/dsl/validations.rb index 9f61052451..a150ac7f3e 100644 --- a/lib/grape/dsl/validations.rb +++ b/lib/grape/dsl/validations.rb @@ -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 @@ -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 diff --git a/spec/grape/dsl/validations_spec.rb b/spec/grape/dsl/validations_spec.rb index 08b951d65d..d70385b1c3 100644 --- a/spec/grape/dsl/validations_spec.rb +++ b/spec/grape/dsl/validations_spec.rb @@ -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 @@ -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