Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intelligently pick which old example to copy from #474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/apipie/method_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 = []
Expand Down
3 changes: 1 addition & 2 deletions lib/apipie/resource_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down