Class: Openapi3Parser::Source::Reference
- Inherits:
-
Object
- Object
- Openapi3Parser::Source::Reference
- Defined in:
- lib/openapi3_parser/source/reference.rb
Overview
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”
Instance Method Summary collapse
- #absolute? ⇒ Boolean
- #fragment ⇒ String?
-
#initialize(reference) ⇒ Reference
constructor
A new instance of Reference.
-
#json_pointer ⇒ ::Array
An array of strings of the components in the fragment.
- #only_fragment? ⇒ Boolean
- #resource_uri ⇒ URI
- #to_s ⇒ Object
Constructor Details
#initialize(reference) ⇒ Reference
Returns a new instance of Reference.
21 22 23 |
# File 'lib/openapi3_parser/source/reference.rb', line 21 def initialize(reference) @given_reference = reference end |
Instance Method Details
#absolute? ⇒ Boolean
43 44 45 |
# File 'lib/openapi3_parser/source/reference.rb', line 43 def absolute? uri.absolute? end |
#fragment ⇒ String?
34 35 36 |
# File 'lib/openapi3_parser/source/reference.rb', line 34 def fragment uri.fragment end |
#json_pointer ⇒ ::Array
Returns an array of strings of the components in the fragment.
48 49 50 51 52 |
# 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? ⇒ Boolean
29 30 31 |
# File 'lib/openapi3_parser/source/reference.rb', line 29 def only_fragment? resource_uri.to_s == "" end |
#resource_uri ⇒ URI
39 40 41 |
# File 'lib/openapi3_parser/source/reference.rb', line 39 def resource_uri uri_without_fragment end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/openapi3_parser/source/reference.rb', line 25 def to_s given_reference.to_s end |