class OpenAPIRest::ApiDocParser
Api doc parser based on OpenAPI 2.0 specs
Attributes
document[R]
method[R]
Public Class Methods
new(openapi_path)
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 9 def initialize(openapi_path) @document = OpenAPIRest::ApiDoc.document @route = openapi_path[:path] @method = openapi_path[:method] @method = 'patch' if @method == 'put' end
Public Instance Methods
[](key)
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 101 def [](key) @current_step = @current_step.fetch(key, {}) self end
base_path()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 36 def base_path document.fetch('basePath', {}) end
definitions()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 16 def definitions @current_step = document.fetch('definitions', {}) self end
find(key)
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 31 def find(key) @current_step = @current_step.fetch(key, {}) self end
find_parameters()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 67 def find_parameters return if @current_step['parameters'].nil? params = {} ref_params = [] @current_step['parameters'].each do |parameter| next if parameter['in'] == 'path' if parameter['in'] == 'query' || parameter['in'] == 'body' params[parameter['name']] = parameter['name'] next end if !parameter['$ref'].nil? && parameter['$ref'].include?('#/parameters/') param = parameter['$ref'].gsub('#/parameters/', '') ref_params << document.fetch('parameters', {}).fetch(param, {}) end end if ref_params.length > 0 params.merge!(ref_params.compact.map { |param| param.fetch('schema', {}).fetch('properties', {}) }.first) end params end
find_path()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 40 def find_path paths.find(@route.sub(base_path, '')).find(method) end
keys()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 97 def keys @current_step.keys end
parameters()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 21 def parameters @current_step = document.fetch('parameters', {}) self end
paths()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 26 def paths @current_step = document.fetch('paths', {}) self end
properties()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 44 def properties @current_step = @current_step.fetch('properties', {}) self end
responses()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 92 def responses @current_step = @current_step.fetch('responses', {}) self end
schema()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 49 def schema @current_step = @current_step.fetch('schema', {}) if !@current_step['$ref'].nil? if @current_step['$ref'].include?('#/definitions/') str = @current_step['$ref'].gsub('#/definitions/', '') return definitions.find(str) end elsif !@current_step['items'].nil? if @current_step['items']['$ref'].include?('#/definitions/') str = @current_step['items']['$ref'].gsub('#/definitions/', '') return definitions.find(str) end end self end
to_s()
click to toggle source
# File lib/openapi_rest/api_doc_parser.rb, line 106 def to_s @current_step end