diff --git a/lib/apipie/method_description.rb b/lib/apipie/method_description.rb index 43946045..0eb3d7b7 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 083d6c25..98fc3bf4 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