class Openapi3Parser::Source::Reference
An object which represents a reference that can be indicated in a OpenAPI file. Given a string reference it can be used to answer key questions that aid in resolving the reference
e.g. r = Openapi3Parser::Source::Reference.new
(“test.yaml#/path/to/item”)
r.only_fragment?
> false¶ ↑
r.rsource_uri
> “test.yaml”¶ ↑
Attributes
given_reference[R]
Public Class Methods
new(reference)
click to toggle source
@param [String] reference reference from an OpenAPI file
# File lib/openapi3_parser/source/reference.rb, line 21 def initialize(reference) @given_reference = reference end
Public Instance Methods
absolute?()
click to toggle source
# File lib/openapi3_parser/source/reference.rb, line 43 def absolute? uri.absolute? end
fragment()
click to toggle source
@return [String, nil]
# File lib/openapi3_parser/source/reference.rb, line 34 def fragment uri.fragment end
json_pointer()
click to toggle source
@return [::Array] an array of strings of the components in the fragment
# File lib/openapi3_parser/source/reference.rb, line 48 def json_pointer @json_pointer ||= (fragment || "").split("/").drop(1).map do |field| CGI.unescape(field.gsub("+", "%20")) end end
only_fragment?()
click to toggle source
# File lib/openapi3_parser/source/reference.rb, line 29 def only_fragment? resource_uri.to_s == "" end
resource_uri()
click to toggle source
@return [URI]
# File lib/openapi3_parser/source/reference.rb, line 39 def resource_uri uri_without_fragment end
to_s()
click to toggle source
# File lib/openapi3_parser/source/reference.rb, line 25 def to_s given_reference.to_s end
Private Instance Methods
uri()
click to toggle source
# File lib/openapi3_parser/source/reference.rb, line 58 def uri @uri = URI.parse(given_reference) end
uri_without_fragment()
click to toggle source
# File lib/openapi3_parser/source/reference.rb, line 62 def uri_without_fragment @uri_without_fragment ||= uri.dup.tap { |u| u.fragment = nil } end