Module: Liminal::Openapi::Verification::Document

Defined in:
lib/liminal/openapi/verification/document.rb

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Object

rubocop:enable Naming/PredicateMethod



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/liminal/openapi/verification/document.rb', line 26

def load(path)
  document = Psych.safe_load(
    File.read(path.to_s),
    permitted_classes: [Date, Time],
    aliases: true
  )
  return document if document.is_a?(Hash)

  raise InvalidDocumentError.new(path.to_s, "document root must be an object")
rescue InvalidDocumentError
  raise
rescue StandardError => e
  raise InvalidDocumentError.new(path.to_s, e.message)
end

.validate!(path) ⇒ Object

rubocop:disable Naming/PredicateMethod



10
11
12
13
14
# File 'lib/liminal/openapi/verification/document.rb', line 10

def validate!(path)
  normalized_path, document = parse(path)
  validate_document!(normalized_path, document)
  true
end

.validate_bundled!(path) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/liminal/openapi/verification/document.rb', line 16

def validate_bundled!(path)
  normalized_path, document = parse(path)
  sources = document.reference_sources.to_a.map(&:relative_to_root).sort
  raise ExternalReferenceError.new(normalized_path, sources) unless sources.empty?

  validate_document!(normalized_path, document)
  true
end