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.
24 25 26 |
# File 'lib/openapi3_parser/source/reference.rb', line 24 def initialize(reference) @given_reference = reference end |
Instance Method Details
#absolute? ⇒ Boolean
46 47 48 |
# File 'lib/openapi3_parser/source/reference.rb', line 46 def absolute? uri.absolute? end |
#fragment ⇒ String?
37 38 39 |
# File 'lib/openapi3_parser/source/reference.rb', line 37 def fragment uri.fragment end |
#json_pointer ⇒ ::Array
Returns an array of strings of the components in the fragment.
51 52 53 54 55 |
# File 'lib/openapi3_parser/source/reference.rb', line 51 def json_pointer @json_pointer ||= (fragment || "").split("/").drop(1).map do |field| CGI.unescape(field.gsub("+", "%20")) end end |
#only_fragment? ⇒ Boolean
32 33 34 |
# File 'lib/openapi3_parser/source/reference.rb', line 32 def only_fragment? resource_uri.to_s == "" end |
#resource_uri ⇒ URI
42 43 44 |
# File 'lib/openapi3_parser/source/reference.rb', line 42 def resource_uri uri_without_fragment end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/openapi3_parser/source/reference.rb', line 28 def to_s given_reference.to_s end |