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



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

def initialize(reference)
  @given_reference = reference
end

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


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

def absolute?
  uri.absolute?
end

#fragmentString?

Returns:

  • (String, nil)


35
36
37
# File 'lib/openapi3_parser/source/reference.rb', line 35

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



49
50
51
52
53
# File 'lib/openapi3_parser/source/reference.rb', line 49

def json_pointer
  @json_pointer ||= (fragment || "").split("/").drop(1).map do |field|
    CGI.unescape(field.gsub("+", "%20"))
  end
end

#only_fragment?Boolean

Returns:

  • (Boolean)


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

def only_fragment?
  resource_uri.to_s == ""
end

#resource_uriURI

Returns:

  • (URI)


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

def resource_uri
  uri_without_fragment
end

#to_sObject



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

def to_s
  given_reference.to_s
end