Class: Vigia::Adapters::Raml

Inherits:
Vigia::Adapter show all
Defined in:
lib/vigia/adapters/raml.rb

Instance Attribute Summary collapse

Attributes inherited from Vigia::Adapter

#source_file, #structure

Instance Method Summary collapse

Methods inherited from Vigia::Adapter

instance, #required_payload?, setup_adapter, template, #with_payload?

Instance Attribute Details

#ramlObject (readonly)

Returns the value of attribute raml.



5
6
7
# File 'lib/vigia/adapters/raml.rb', line 5

def raml
  @raml
end

Instance Method Details

#expected_headers(body) ⇒ Object



68
69
70
71
72
73
# File 'lib/vigia/adapters/raml.rb', line 68

def expected_headers(body)
  compile_headers(body.parent.headers).tap do |headers|
    # Dont add content_type header if response is 204 (nil response)
    headers.merge!(content_type: body.media_type) unless body.parent.name == 204 or headers.key?(:content_type)
  end
end

#parameters_for(method) ⇒ Object



55
56
57
# File 'lib/vigia/adapters/raml.rb', line 55

def parameters_for(method)
  format_parameters(method.query_parameters) + format_parameters(method.parent.uri_parameters)
end

#payload_for(method, body) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vigia/adapters/raml.rb', line 75

def payload_for(method, body)
  return unless with_payload?(method.name)

  payload = request_body_for(method, body)

  case
  when required_payload?(method.name) && payload.nil?
    raise(
      "An example body cannot be found for method #{ method.name } #{ method.parent.resource_path }"
    )
  when payload.nil?
    nil
  else
    payload.example || payload.schema.value
  end
end

#request_headers(body) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/vigia/adapters/raml.rb', line 59

def request_headers(body)
  method = body.parent.parent
  compile_headers(method.headers).tap do |headers|
    return unless with_payload?(method.name)
    return if     request_body_for(method, body).name == '*/*'
    headers.merge!(content_type: request_body_for(method, body).name)
  end
end

#resource_uri_template(method) ⇒ Object



50
51
52
53
# File 'lib/vigia/adapters/raml.rb', line 50

def resource_uri_template(method)
  uri_template  = method.parent.resource_path
  uri_template += query_parameters(method)
end