class Tomograph::ApiBlueprint::Drafter4::Yaml::Action

Attributes

path[R]
resource[R]

Public Class Methods

new(content, path, resource) click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml/action.rb, line 8
def initialize(content, path, resource)
  @content = content
  @path = path
  @resource = resource
end

Public Instance Methods

content_type() click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml/action.rb, line 20
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
  end
end
json_schema(actions) click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml/action.rb, line 34
def json_schema(actions)
  schema_node = actions.find do |action|
    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
  puts "[Tomograph] Error while parsing #{e}. skipping..."
  {}
end
method() click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml/action.rb, line 16
def method
  @method ||= @content.first['attributes']['method']['content']
end
request() click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml/action.rb, line 27
def request
  return @request if @request

  request_action = @content.find { |el| el['element'] == 'httpRequest' }
  @request = json_schema(request_action['content'])
end
responses() click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml/action.rb, line 46
def responses
  return @responses if @responses

  @responses = @content.select do |response|
    response['element'] == 'httpResponse' && response['attributes']
  end
  @responses = @responses.map do |response|
    {
      '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
    }
  end
end