lib/tomograph/openapi/openapi3.rb in tomograph-3.2.1 vs lib/tomograph/openapi/openapi3.rb in tomograph-3.2.4
- old
+ new
@@ -12,11 +12,11 @@
@tomogram ||= @documentation['paths'].each_with_object([]) do |(path, action_definition), result|
action_definition.keys.each do |method|
result.push(Tomograph::Tomogram::Action.new(
path: "#{@prefix}#{path}",
method: method.upcase,
- content_type: '',
+ content_type: action_definition[method]['requestBody'] && action_definition[method]['requestBody']['content'].keys[0] == 'application/json' ? action_definition[method]['requestBody']['content'].keys[0] : '',
requests: [],
responses: responses(action_definition[method]['responses']),
resource: ''
))
end
@@ -55,11 +55,15 @@
}
end
end
def schema(sche)
- defi = @documentation['components']['schemas']
+ if @documentation['components']
+ defi = @documentation['components']['schemas']
+ elsif @documentation['definitions']
+ defi = @documentation['definitions']
+ end
if sche.keys.include?('$ref')
sche.merge!('components' => {})
sche['components'].merge!('schemas' => {})
sche['components']['schemas'].merge!({ sche['$ref'][21..-1] => defi[sche['$ref'][21..-1]] })
@@ -89,10 +93,10 @@
elsif sche.to_s.include?('$ref')
res = sche.merge('definitions' => {})
keys = sche.to_s.split('"').find_all { |word| word.include?('definitions') }
keys.each do |key|
- res['definitions'].merge!({ key[21..-1] => defi[key[21..-1]] })
+ res['definitions'].merge!({ key.split('/')[-1] => defi[key.split('/')[-1]] })
end
res
else
sche
end