Sha256: d190e492c20e2087b6249d8ade4634c46ace55a8ee540a80027a6bc429602322

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

require 'tomograph/tomogram/action'

module Tomograph
  module ApiBlueprint
    class Yaml
      class Action
        def initialize(content, path, resource)
          @content = content
          @path = path
          @resource = resource
        end

        attr_reader :path, :resource

        def method
          @method ||= @content.first['attributes']['method']
        end

        def request
          return @request if @request

          request_action = @content.find { |el| el['element'] == 'httpRequest' }
          @request = json_schema(request_action['content'])
        end

        def json_schema(actions)
          schema_node = actions.find do |action|
            action && action['element'] == 'asset' && action['attributes']['contentType'] == 'application/schema+json'
          end
          return {} unless schema_node

          MultiJson.load(schema_node['content'])
        rescue MultiJson::ParseError => e
          puts "[Tomograph] Error while parsing #{e}. skipping..."
          {}
        end

        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'],
              'body' => json_schema(response['content'])
            }
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tomograph-2.0.1 lib/tomograph/api_blueprint/yaml/action.rb
tomograph-2.0.0 lib/tomograph/api_blueprint/yaml/action.rb
tomograph-1.2.0 lib/tomograph/api_blueprint/yaml/action.rb
tomograph-1.1.0 lib/tomograph/api_blueprint/yaml/action.rb