Class: Openapi3Parser::SourceInput

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/source_input.rb,
lib/openapi3_parser/source_input/raw.rb,
lib/openapi3_parser/source_input/url.rb,
lib/openapi3_parser/source_input/file.rb,
lib/openapi3_parser/source_input/resolve_next.rb,
lib/openapi3_parser/source_input/string_parser.rb

Overview

An abstract class which is used to provide a foundation for classes that represent the different means of input an OpenAPI document can have. It is used to represent the underlying source of the data which is used as a source within an OpenAPI document.

Direct Known Subclasses

File, Raw, Url

Defined Under Namespace

Classes: File, Raw, ResolveNext, StringParser, Url

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSourceInput

Returns a new instance of SourceInput.


23
24
25
26
27
28
29
# File 'lib/openapi3_parser/source_input.rb', line 23

def initialize
  return if access_error

  @contents = parse_contents
rescue ::StandardError => e
  @parse_error = Error::UnparsableInput.new(e.message)
end

Instance Attribute Details

#access_errorError::InaccessibleInput? (readonly)

Returns the current value of access_error.

Returns:


20
21
22
# File 'lib/openapi3_parser/source_input.rb', line 20

def access_error
  @access_error
end

#parse_errorError::UnparsableInput? (readonly)

Returns the current value of parse_error.

Returns:


20
21
22
# File 'lib/openapi3_parser/source_input.rb', line 20

def parse_error
  @parse_error
end

Instance Method Details

#==(_other) ⇒ Object

Used to determine whether a different instance of SourceInput is the same file/data


45
# File 'lib/openapi3_parser/source_input.rb', line 45

def ==(_other); end

#available?Boolean

Indicates that the data within this input is suitable (i.e. can parse underlying JSON or YAML) for trying to use as part of a Document

Returns:

  • (Boolean)

33
34
35
# File 'lib/openapi3_parser/source_input.rb', line 33

def available?
  access_error.nil? && parse_error.nil?
end

#contentsObject

The parsed data from the input

Returns:

  • Object

Raises:


53
54
55
56
57
58
# File 'lib/openapi3_parser/source_input.rb', line 53

def contents
  raise access_error if access_error
  raise parse_error if parse_error

  @contents
end

#relative_to(_source_input) ⇒ String

The relative path, if possible, for this source_input compared to a different one. Defaults to empty string and should be specialised in subclasses

Returns:

  • (String)

65
66
67
# File 'lib/openapi3_parser/source_input.rb', line 65

def relative_to(_source_input)
  ""
end

#resolve_next(_reference) ⇒ Object

For a given reference use the context of the current SourceInput to determine which file is required for the reference. This allows references to use relative file paths because we can combine them witt the current SourceInput location to determine the next one


41
# File 'lib/openapi3_parser/source_input.rb', line 41

def resolve_next(_reference); end