diff --git a/grape.gemspec b/grape.gemspec index 3ea7193b77..87b7a89336 100644 --- a/grape.gemspec +++ b/grape.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| } s.add_runtime_dependency 'activesupport', '>= 6' + s.add_runtime_dependency 'actionpack', '>= 6' s.add_runtime_dependency 'builder' s.add_runtime_dependency 'dry-types', '>= 1.1' s.add_runtime_dependency 'mustermann-grape', '~> 1.1.0' diff --git a/lib/grape.rb b/lib/grape.rb index 6d4d90e1cc..1aafe955f2 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -110,6 +110,7 @@ module Extensions eager_autoload do autoload :Hash end + module ActiveSupport extend ::ActiveSupport::Autoload eager_autoload do @@ -117,6 +118,13 @@ module ActiveSupport end end + module ActionController + extend ::ActiveSupport::Autoload + eager_autoload do + autoload :Parameters + end + end + module Hashie extend ::ActiveSupport::Autoload eager_autoload do diff --git a/lib/grape/extensions/action_controller/parameters.rb b/lib/grape/extensions/action_controller/parameters.rb new file mode 100644 index 0000000000..3763068b65 --- /dev/null +++ b/lib/grape/extensions/action_controller/parameters.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Grape + module Extensions + module ActionController + class Parameters + module ParamBuilder + extend ::ActiveSupport::Concern + + included do + namespace_inheritable(:build_params_with, Grape::Extensions::ActionController::Parameters::ParamBuilder) + end + + def params_builder + Grape::Extensions::ActionController::Parameters::ParamBuilder + end + + def build_params + ::ActionController::Parameters.new(rack_params).tap do |params| + params.deep_merge!(grape_routing_args) if env.key?(Grape::Env::GRAPE_ROUTING_ARGS) + end + end + end + end + end + end +end