Method: OpenapiFirst.load

Defined in:
lib/openapi_first.rb

.load(filepath_or_definition, only: nil) ⇒ Definition

Load and dereference an OpenAPI spec file or return the Definition if it’s already loaded

Parameters:

  • filepath_or_definition (String, Definition)

    The path to the file or a Definition object

Returns:

Raises:



59
60
61
62
63
64
65
66
67
68
# File 'lib/openapi_first.rb', line 59

def self.load(filepath_or_definition, only: nil, &)
  return filepath_or_definition if filepath_or_definition.is_a?(Definition)
  return self[filepath_or_definition] if filepath_or_definition.is_a?(Symbol)

  filepath = filepath_or_definition
  raise FileNotFoundError, "File not found: #{filepath}" unless File.exist?(filepath)

  contents = FileLoader.load(filepath)
  parse(contents, only:, filepath:, &)
end