Class: RSpec::Rails::Swagger::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/rails/swagger/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Document

Returns a new instance of Document.



7
8
9
# File 'lib/rspec/rails/swagger/document.rb', line 7

def initialize(data)
  @data = data.deep_symbolize_keys
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/rspec/rails/swagger/document.rb', line 5

def data
  @data
end

Instance Method Details

#[](value) ⇒ Object



11
12
13
# File 'lib/rspec/rails/swagger/document.rb', line 11

def [](value)
  data[value]
end

#resolve_ref(ref) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rspec/rails/swagger/document.rb', line 15

def resolve_ref(ref)
  unless %r{#/(?<location>parameters|definitions)/(?<name>.+)} =~ ref
    raise ArgumentError, "Invalid reference: #{ref}"
  end

  result = data.fetch(location.to_sym, {})[name.to_sym]
  raise ArgumentError, "Reference value does not exist: #{ref}" unless result

  if location == 'parameters'
    result.merge(name: name)
  end

  result
end