-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathopenapi3_parser.rb
More file actions
50 lines (46 loc) · 2.15 KB
/
openapi3_parser.rb
File metadata and controls
50 lines (46 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
files = Dir.glob(File.join(__dir__, "openapi3_parser", "**", "*.rb"))
files.each { |file| require file }
module Openapi3Parser
# For a variety of inputs this will construct an OpenAPI document. For a
# String/File input it will try to determine if the input is JSON or YAML.
#
# @param [String, Hash, File] input Source for the OpenAPI document
# @param [Boolean] emit_warnings Whether to call Kernel.warn when
# warnings are output, best set to
# false when parsing specification
# files you've not authored
#
# @return [Document]
def self.load(input, emit_warnings: true)
Document.new(SourceInput::Raw.new(input), emit_warnings:)
end
# For a given string filename this will read the file and parse it as an
# OpenAPI document. It will try detect automatically whether the contents
# are JSON or YAML.
#
# @param [String] path Filename of the OpenAPI document
# @param [Boolean] emit_warnings Whether to call Kernel.warn when
# warnings are output, best set to
# false when parsing specification
# files you've not authored
#
# @return [Document]
def self.load_file(path, emit_warnings: true)
Document.new(SourceInput::File.new(path), emit_warnings:)
end
# For a given string URL this will request the resource and parse it as an
# OpenAPI document. It will try detect automatically whether the contents
# are JSON or YAML.
#
# @param [String] url URL of the OpenAPI document
# @param [Boolean] emit_warnings Whether to call Kernel.warn when
# warnings are output, best set to
# false when parsing specification
# files you've not authored
#
# @return [Document]
def self.load_url(url, emit_warnings: true)
Document.new(SourceInput::Url.new(url.to_s), emit_warnings:)
end
end