diff --git a/lib/apipie/dsl_definition.rb b/lib/apipie/dsl_definition.rb index 3bda1fb9..3c19c759 100644 --- a/lib/apipie/dsl_definition.rb +++ b/lib/apipie/dsl_definition.rb @@ -488,19 +488,33 @@ def apipie_concern_subst(subst_hash) # param_names.each { |p| param p, String } # end # end - def apipie_update_params(methods, *args, &block) + def _apipie_update_params(method_desc, dsl_data) + params_ordered = dsl_data[:params].map do |args| + Apipie::ParamDescription.from_dsl_data(method_desc, args) + end + ParamDescription.merge(method_desc.params_ordered_self, params_ordered) + end + + def _apipie_update_meta(method_desc, dsl_data) + return unless dsl_data[:meta] && dsl_data[:meta].is_a?(Hash) + + method_desc.metadata ||= {} + method_desc.metadata.merge!(dsl_data[:meta]) + end + + def apipie_update_methods(methods, *args, &block) methods.each do |method| - method_description = Apipie.get_method_description(self, method) - unless method_description + method_desc = Apipie.get_method_description(self, method) + unless method_desc raise "Could not find method description for #{self}##{method}. Was the method defined?" end dsl_data = _apipie_eval_dsl(*args, &block) - params_ordered = dsl_data[:params].map do |args| - Apipie::ParamDescription.from_dsl_data(method_description, args) - end - ParamDescription.merge(method_description.params_ordered_self, params_ordered) + _apipie_update_params(method_desc, dsl_data) + _apipie_update_meta(method_desc, dsl_data) end end + # backwards compatibility + alias_method :apipie_update_params, :apipie_update_methods def _apipie_concern_subst @_apipie_concern_subst ||= {:controller_path => self.controller_path, @@ -550,7 +564,7 @@ def included(controller) controller._apipie_define_validators(description) end _apipie_concern_update_api_blocks.each do |(methods, block)| - controller.apipie_update_params(methods, &block) + controller.apipie_update_methods(methods, &block) end end diff --git a/lib/apipie/method_description.rb b/lib/apipie/method_description.rb index 5bbd3315..327015fc 100644 --- a/lib/apipie/method_description.rb +++ b/lib/apipie/method_description.rb @@ -17,7 +17,8 @@ def initialize(method, path, desc, options) end - attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :metadata, :headers, :show + attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :headers, :show + attr_accessor :metadata def initialize(method, resource, dsl_data) @method = method.to_s diff --git a/spec/controllers/extended_controller_spec.rb b/spec/controllers/extended_controller_spec.rb index b06691f1..d79c17bc 100644 --- a/spec/controllers/extended_controller_spec.rb +++ b/spec/controllers/extended_controller_spec.rb @@ -7,5 +7,8 @@ user_param = Apipie["extended#create"].params[:user] expect(user_param.validator.params_ordered.map(&:name)).to eq [:name, :password, :from_concern] end -end + it 'should include updated metadata' do + expect(Apipie['extended#create'].metadata).to eq metadata: 'data' + end +end diff --git a/spec/dummy/app/controllers/concerns/extending_concern.rb b/spec/dummy/app/controllers/concerns/extending_concern.rb index 195e2aeb..a207cf72 100644 --- a/spec/dummy/app/controllers/concerns/extending_concern.rb +++ b/spec/dummy/app/controllers/concerns/extending_concern.rb @@ -6,6 +6,7 @@ module ExtendingConcern param :user, Hash do param :from_concern, String, :desc => 'param from concern', :allow_nil => false end + meta metadata: 'data' end end end