lib/apipie/method_description.rb in apipie-rails-0.0.8 vs lib/apipie/method_description.rb in apipie-rails-0.0.9
- old
+ new
@@ -21,18 +21,19 @@
return path
end
end
- attr_reader :errors, :full_description, :method, :resource, :apis, :examples, :see
+ attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats
def initialize(method, resource, app)
@method = method
@resource = resource
@apis = app.get_api_args
@see = app.get_see
+ @formats = app.get_formats
desc = app.get_description || ''
@full_description = Apipie.markup_to_html(desc)
@errors = app.get_errors
@params_ordered = app.get_params
@@ -70,10 +71,23 @@
merge_params(all_params, @params_ordered)
all_params.find_all(&:validator)
end
+ def errors
+ return @merged_errors if @merged_errors
+ @merged_errors = []
+ if @resource
+ # exclude overwritten parent errors
+ @merged_errors = @resource._errors_ordered.find_all do |err|
+ !@errors.any? { |e| e.code == err.code }
+ end
+ end
+ @merged_errors.concat(@errors)
+ return @merged_errors
+ end
+
def doc_url
Apipie.full_url("#{@resource._id}/#{@method}")
end
def method_apis_to_json
@@ -98,16 +112,21 @@
def see
@see
end
+ def formats
+ @formats || @resource._formats
+ end
+
def to_json
{
:doc_url => doc_url,
:name => @method,
:apis => method_apis_to_json,
+ :formats => formats,
:full_description => @full_description,
- :errors => @errors,
+ :errors => errors.map(&:to_json),
:params => params_ordered.map(&:to_json).flatten,
:examples => @examples,
:see => @see,
:see_url => see_url
}