lib/tomograph/api_blueprint/drafter_4/yaml/action.rb in tomograph-3.1.2 vs lib/tomograph/api_blueprint/drafter_4/yaml/action.rb in tomograph-3.1.3
- old
+ new
@@ -16,13 +16,13 @@
def method
@method ||= @content.first['attributes']['method']['content']
end
def content_type
- if @content.first['attributes'].has_key?('headers')
- @content.first['attributes']['headers']['content'][0]['content']['key']['content'] == 'Content-Type' ?
- @content.first['attributes']['headers']['content'][0]['content']['value']['content'] : nil
+ if @content.first['attributes'].key?('headers') &&
+ @content.first['attributes']['headers']['content'][0]['content']['key']['content'] == 'Content-Type'
+ @content.first['attributes']['headers']['content'][0]['content']['value']['content']
end
end
def request
return @request if @request
@@ -31,11 +31,12 @@
@request = json_schema(request_action['content'])
end
def json_schema(actions)
schema_node = actions.find do |action|
- action && action['element'] == 'asset' && action['attributes']['contentType']['content'] == 'application/schema+json'
+ action && action['element'] == 'asset' &&
+ action['attributes']['contentType']['content'] == 'application/schema+json'
end
return {} unless schema_node
JSON.parse(schema_node['content'])
rescue JSON::ParserError => e
@@ -48,14 +49,17 @@
@responses = @content.select do |response|
response['element'] == 'httpResponse' && response['attributes']
end
@responses = @responses.map do |response|
+ content_type = if response['attributes'].key?('headers')
+ response['attributes']['headers']['content'][0]['content']['value']['content']
+ end
+
{
'status' => response['attributes']['statusCode']['content'].to_s,
'body' => json_schema(response['content']),
- 'content-type' => response['attributes'].has_key?('headers') ?
- response['attributes']['headers']['content'][0]['content']['value']['content'] : nil
+ 'content-type' => content_type
}
end
end
end
end