Class: OpenApiParser::Specification::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/open_api_parser/specification/root.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Root

Returns a new instance of Root.



6
7
8
# File 'lib/open_api_parser/specification/root.rb', line 6

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



4
5
6
# File 'lib/open_api_parser/specification/root.rb', line 4

def raw
  @raw
end

Instance Method Details

#endpoint(path, request_method) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/open_api_parser/specification/root.rb', line 10

def endpoint(path, request_method)
  uri = URI.parse(path)
  requested_path = uri.path.gsub(/\..+\z/, "")

  path_details = @raw["paths"].detect do |path_name, path|
    requested_path =~ to_pattern(path_name)
  end
  return nil if path_details.nil?

  path = path_details.last

  method_details = path.detect do |method, schema|
    method.to_s == request_method.downcase
  end
  return nil if method_details.nil?

  Endpoint.new(path_details.first, method_details.first, method_details.last)
end

#to_jsonObject



29
30
31
# File 'lib/open_api_parser/specification/root.rb', line 29

def to_json
  JSON.generate(@raw)
end