Class: Openapi3Parser::Source::Reference

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(reference) ⇒ Reference

Returns a new instance of Reference.

Parameters:

  • reference (String)

    reference from an OpenAPI file



21
22
23
# File 'lib/openapi3_parser/source/reference.rb', line 21

def initialize(reference)
  @given_reference = reference
end

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/openapi3_parser/source/reference.rb', line 43

def absolute?
  uri.absolute?
end

#fragmentString?

Returns:

  • (String, nil)


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.

Returns:

  • (::Array)

    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

Returns:

  • (Boolean)


29
30
31
# File 'lib/openapi3_parser/source/reference.rb', line 29

def only_fragment?
  resource_uri.to_s == ""
end

#resource_uriURI

Returns:

  • (URI)


39
40
41
# File 'lib/openapi3_parser/source/reference.rb', line 39

def resource_uri
  uri_without_fragment
end

#to_sObject



25
26
27
# File 'lib/openapi3_parser/source/reference.rb', line 25

def to_s
  given_reference.to_s
end