Extracting out APIMetadata from Formatter

This commit is contained in:
Garima Singh
2016-08-12 08:21:41 +08:00
parent 4c533caf68
commit 9c250cffe1
4 changed files with 180 additions and 34 deletions

View File

@@ -0,0 +1,46 @@
module SwaggerRails::RSpec
class APIMetadata
def initialize metadata
@metadata = metadata
end
def response_example?
@metadata.has_key?(:response_code)
end
def swagger_doc
@metadata[:swagger_doc]
end
def swagger_data
{
paths: {
@metadata[:path_template] => {
@metadata[:http_verb] => operation_metadata
}
}
}
end
private
def operation_metadata
{
tags: [find_root_of(@metadata)[:description]],
summary: @metadata[:summary],
description: @metadata[:operation_description],
consumes: @metadata[:consumes],
produces: @metadata[:produces],
parameters: @metadata[:parameters],
responses: { @metadata[:response_code] => @metadata[:response] }
}
end
def find_root_of(node)
parent = node[:parent_example_group]
parent.nil? ? node : find_root_of(parent)
end
end
end