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



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

def initialize(reference)
  @given_reference = reference
end

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/openapi3_parser/source/reference.rb', line 46

def absolute?
  uri.absolute?
end

#fragmentString?

Returns:

  • (String, nil)


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.

Returns:

  • (::Array)

    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

Returns:

  • (Boolean)


32
33
34
# File 'lib/openapi3_parser/source/reference.rb', line 32

def only_fragment?
  resource_uri.to_s == ""
end

#resource_uriURI

Returns:

  • (URI)


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

def resource_uri
  uri_without_fragment
end

#to_sObject



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

def to_s
  given_reference.to_s
end