Class: OpenApiParser::Specification::Root
- Inherits:
-
Object
- Object
- OpenApiParser::Specification::Root
- Defined in:
- lib/open_api_parser/specification/root.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #endpoint(path, request_method) ⇒ Object
-
#initialize(raw) ⇒ Root
constructor
A new instance of Root.
- #to_json ⇒ Object
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
#raw ⇒ Object (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_json ⇒ Object
29 30 31 |
# File 'lib/open_api_parser/specification/root.rb', line 29 def to_json JSON.generate(@raw) end |