diff --git a/lib/grape/dsl/desc.rb b/lib/grape/dsl/desc.rb index f83eb8b00..2d3155026 100644 --- a/lib/grape/dsl/desc.rb +++ b/lib/grape/dsl/desc.rb @@ -70,33 +70,23 @@ module Desc # # ... # end # - def desc(description, options = {}, &config_block) - if config_block - endpoint_configuration = if defined?(configuration) - # When the instance is mounted - the configuration is executed on mount time - if configuration.respond_to?(:evaluate) - configuration.evaluate - # Within `given` or `mounted blocks` the configuration is already evaluated - elsif configuration.is_a?(Hash) - configuration - end - end - endpoint_configuration ||= {} - config_class = desc_container(endpoint_configuration) + def desc(description, options = nil, &config_block) + opts = + if config_block + desc_container(endpoint_configuration).then do |config_class| + config_class.configure do + description(description) + end - config_class.configure do - description description + config_class.configure(&config_block) + config_class.settings + end + else + options&.merge(description: description) || { description: description } end - config_class.configure(&config_block) - Grape.deprecator.warn('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') if options.any? - options = config_class.settings - else - options = options.merge(description: description) - end - - namespace_setting :description, options - route_setting :description, options + namespace_setting :description, opts + route_setting :description, opts end # Returns an object which configures itself via an instance-context DSL. @@ -116,6 +106,19 @@ def config_context.failure(*args) end end end + + private + + def endpoint_configuration + return {} unless defined?(configuration) + + if configuration.respond_to?(:evaluate) + configuration.evaluate + # Within `given` or `mounted blocks` the configuration is already evaluated + elsif configuration.is_a?(Hash) + configuration + end + end end end end diff --git a/spec/grape/dsl/desc_spec.rb b/spec/grape/dsl/desc_spec.rb index fa3ae7f9e..aa2aa4c33 100644 --- a/spec/grape/dsl/desc_spec.rb +++ b/spec/grape/dsl/desc_spec.rb @@ -81,18 +81,5 @@ expect(subject.namespace_setting(:description)).to eq(expected_options) expect(subject.route_setting(:description)).to eq(expected_options) end - - it 'can be set with options and a block' do - expect(Grape.deprecator).to receive(:warn).with('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') - - desc_text = 'The description' - detail_text = 'more details' - options = { message: 'none' } - subject.desc desc_text, options do - detail detail_text - end - expect(subject.namespace_setting(:description)).to eq(description: desc_text, detail: detail_text) - expect(subject.route_setting(:description)).to eq(description: desc_text, detail: detail_text) - end end end