From 00f15e9a0ad66af66ba30d2ab8d271da33b94aac Mon Sep 17 00:00:00 2001 From: Chu Date: Thu, 7 Jul 2016 10:45:13 -0400 Subject: [PATCH] Similar to params, resource headers shown in methods. --- lib/apipie/method_description.rb | 19 +++++++++++++++++++ lib/apipie/resource_description.rb | 3 +-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/apipie/method_description.rb b/lib/apipie/method_description.rb index 439460452..0eb3d7b7e 100644 --- a/lib/apipie/method_description.rb +++ b/lib/apipie/method_description.rb @@ -49,6 +49,7 @@ def initialize(method, resource, dsl_data) end @params_ordered = ParamDescription.unify(@params_ordered) @headers = dsl_data[:headers] + @headers = all_headers @show = if dsl_data.has_key? :show dsl_data[:show] @@ -81,6 +82,24 @@ def params_ordered all_params.find_all(&:validator) end + def all_headers + all_headers = [] + parent = Apipie.get_resource_description(@resource.controller.superclass) + # get params from parent resource description + [parent, @resource].compact.each do |resource| + resource_headers = resource._headers + merge_headers(all_headers, resource_headers) + end + + merge_headers(all_headers, @headers) + end + + def merge_headers(headers, new_headers) + new_header_names = Set.new(new_headers.map{ |h| h[:name] }) + headers.delete_if { |h| new_header_names.include?(h[:name]) } + headers.concat(new_headers) + end + def errors return @merged_errors if @merged_errors @merged_errors = [] diff --git a/lib/apipie/resource_description.rb b/lib/apipie/resource_description.rb index 083d6c254..98fc3bf45 100644 --- a/lib/apipie/resource_description.rb +++ b/lib/apipie/resource_description.rb @@ -108,8 +108,7 @@ def to_json(method_name = nil, lang = nil) :version => _version, :formats => @_formats, :metadata => @_metadata, - :methods => methods, - :headers => _headers + :methods => methods } end