Class: Tomograph::ApiBlueprint::Crafter::Yaml::Action
- Inherits:
-
Object
- Object
- Tomograph::ApiBlueprint::Crafter::Yaml::Action
- Defined in:
- lib/tomograph/api_blueprint/crafter/yaml/action.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #content_type ⇒ Object
-
#initialize(content, path, resource) ⇒ Action
constructor
A new instance of Action.
- #json_schema(actions) ⇒ Object
- #method ⇒ Object
- #request ⇒ Object
- #responses ⇒ Object
Constructor Details
#initialize(content, path, resource) ⇒ Action
Returns a new instance of Action.
8 9 10 11 12 |
# File 'lib/tomograph/api_blueprint/crafter/yaml/action.rb', line 8 def initialize(content, path, resource) @content = content @path = path @resource = resource end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/tomograph/api_blueprint/crafter/yaml/action.rb', line 14 def path @path end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
14 15 16 |
# File 'lib/tomograph/api_blueprint/crafter/yaml/action.rb', line 14 def resource @resource end |
Instance Method Details
#content_type ⇒ Object
20 21 22 23 24 25 |
# File 'lib/tomograph/api_blueprint/crafter/yaml/action.rb', line 20 def content_type 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 |
#json_schema(actions) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tomograph/api_blueprint/crafter/yaml/action.rb', line 34 def json_schema(actions) schema_node = actions.find do |action| action && action.fetch('element', nil) == 'asset' && action.fetch('attributes', {}) .fetch('contentType', {}) .fetch('content', nil) == '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 ⇒ Object
16 17 18 |
# File 'lib/tomograph/api_blueprint/crafter/yaml/action.rb', line 16 def method @method ||= @content.first['attributes']['method']['content'] end |
#request ⇒ Object
27 28 29 30 31 32 |
# File 'lib/tomograph/api_blueprint/crafter/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 ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tomograph/api_blueprint/crafter/yaml/action.rb', line 50 def responses return @responses if @responses @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' => content_type } end end |