openapi3_parser 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -3
- data/CHANGELOG.md +7 -1
- data/README.md +102 -15
- data/lib/openapi3_parser/document.rb +14 -14
- data/lib/openapi3_parser/document/reference_registry.rb +72 -0
- data/lib/openapi3_parser/node/array.rb +10 -2
- data/lib/openapi3_parser/node/components.rb +9 -9
- data/lib/openapi3_parser/node/contact.rb +3 -3
- data/lib/openapi3_parser/node/context.rb +129 -0
- data/lib/openapi3_parser/node/discriminator.rb +2 -2
- data/lib/openapi3_parser/node/encoding.rb +5 -5
- data/lib/openapi3_parser/node/example.rb +4 -4
- data/lib/openapi3_parser/node/external_documentation.rb +2 -2
- data/lib/openapi3_parser/node/info.rb +6 -6
- data/lib/openapi3_parser/node/license.rb +2 -2
- data/lib/openapi3_parser/node/link.rb +6 -6
- data/lib/openapi3_parser/node/map.rb +8 -4
- data/lib/openapi3_parser/node/media_type.rb +5 -5
- data/lib/openapi3_parser/node/oauth_flow.rb +4 -4
- data/lib/openapi3_parser/node/oauth_flows.rb +4 -4
- data/lib/openapi3_parser/node/object.rb +8 -4
- data/lib/openapi3_parser/node/openapi.rb +8 -8
- data/lib/openapi3_parser/node/operation.rb +12 -12
- data/lib/openapi3_parser/node/parameter.rb +2 -2
- data/lib/openapi3_parser/node/parameter_like.rb +11 -11
- data/lib/openapi3_parser/node/path_item.rb +12 -12
- data/lib/openapi3_parser/node/placeholder.rb +34 -0
- data/lib/openapi3_parser/node/request_body.rb +3 -3
- data/lib/openapi3_parser/node/response.rb +4 -4
- data/lib/openapi3_parser/node/responses.rb +1 -1
- data/lib/openapi3_parser/node/schema.rb +36 -36
- data/lib/openapi3_parser/node/security_scheme.rb +8 -8
- data/lib/openapi3_parser/node/server.rb +3 -3
- data/lib/openapi3_parser/node/server_variable.rb +3 -3
- data/lib/openapi3_parser/node/tag.rb +3 -3
- data/lib/openapi3_parser/node/xml.rb +5 -5
- data/lib/openapi3_parser/node_factory/array.rb +15 -13
- data/lib/openapi3_parser/node_factory/callback.rb +2 -2
- data/lib/openapi3_parser/node_factory/context.rb +111 -0
- data/lib/openapi3_parser/node_factory/field.rb +5 -7
- data/lib/openapi3_parser/node_factory/fields/reference.rb +43 -24
- data/lib/openapi3_parser/node_factory/link.rb +1 -1
- data/lib/openapi3_parser/node_factory/map.rb +14 -12
- data/lib/openapi3_parser/node_factory/object.rb +9 -5
- data/lib/openapi3_parser/node_factory/object_factory/node_builder.rb +21 -28
- data/lib/openapi3_parser/node_factory/optional_reference.rb +4 -0
- data/lib/openapi3_parser/node_factory/parameter_like.rb +0 -2
- data/lib/openapi3_parser/node_factory/path_item.rb +7 -4
- data/lib/openapi3_parser/node_factory/paths.rb +2 -2
- data/lib/openapi3_parser/node_factory/reference.rb +17 -10
- data/lib/openapi3_parser/node_factory/responses.rb +2 -2
- data/lib/openapi3_parser/node_factory/security_requirement.rb +2 -2
- data/lib/openapi3_parser/source.rb +27 -24
- data/lib/openapi3_parser/{context → source}/location.rb +13 -1
- data/lib/openapi3_parser/{context → source}/pointer.rb +2 -2
- data/lib/openapi3_parser/source/resolved_reference.rb +67 -0
- data/lib/openapi3_parser/validators/duplicate_parameters.rb +8 -4
- data/lib/openapi3_parser/validators/reference.rb +3 -3
- data/lib/openapi3_parser/version.rb +1 -1
- data/openapi3_parser.gemspec +1 -1
- metadata +11 -10
- data/lib/openapi3_parser/context.rb +0 -162
- data/lib/openapi3_parser/document/reference_register.rb +0 -48
- data/lib/openapi3_parser/node_factory/recursive_pointer.rb +0 -17
- data/lib/openapi3_parser/source/reference_resolver.rb +0 -82
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Openapi3Parser
|
4
|
+
module Node
|
5
|
+
# This class is used to specify the data and source information for a
|
6
|
+
# Node, for every node there is a different context to represent it's
|
7
|
+
# place within the document.
|
8
|
+
#
|
9
|
+
# @attr_reader [Any] input The raw data that was
|
10
|
+
# used to build the
|
11
|
+
# node
|
12
|
+
# @attr_reader [Source::Location] document_location The location in the
|
13
|
+
# root source of this
|
14
|
+
# node
|
15
|
+
# @attr_reader [Source::Location] source_location The location in a
|
16
|
+
# source file of this
|
17
|
+
class Context
|
18
|
+
# Create a context for the root of a document
|
19
|
+
#
|
20
|
+
# @param [NodeFactory::Context] factory_context
|
21
|
+
# @return [Node::Context]
|
22
|
+
def self.root(factory_context)
|
23
|
+
location = Source::Location.new(factory_context.source, [])
|
24
|
+
new(factory_context.input,
|
25
|
+
document_location: location,
|
26
|
+
source_location: factory_context.source_location)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create a context for the child of a previous context
|
30
|
+
#
|
31
|
+
# @param [Node::Context] parent_context
|
32
|
+
# @param [String] field
|
33
|
+
# @param [NodeFactory::Context] factory_context
|
34
|
+
# @return [Node::Context]
|
35
|
+
def self.next_field(parent_context, field, factory_context)
|
36
|
+
document_location = Source::Location.next_field(
|
37
|
+
parent_context.document_location,
|
38
|
+
field
|
39
|
+
)
|
40
|
+
|
41
|
+
new(factory_context.input,
|
42
|
+
document_location: document_location,
|
43
|
+
source_location: factory_context.source_location)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Create a context for a the a field that is the result of a reference
|
47
|
+
#
|
48
|
+
# @param [Node::Context] current_context
|
49
|
+
# @param [NodeFactory::Context] reference_factory_context
|
50
|
+
# @return [Node::Context]
|
51
|
+
def self.resolved_reference(current_context, reference_factory_context)
|
52
|
+
new(reference_factory_context.input,
|
53
|
+
document_location: current_context.document_location,
|
54
|
+
source_location: reference_factory_context.source_location)
|
55
|
+
end
|
56
|
+
|
57
|
+
attr_reader :input, :document_location, :source_location
|
58
|
+
|
59
|
+
# @param input
|
60
|
+
# @param [Source::Location] document_location
|
61
|
+
# @param [Source::Location] source_location
|
62
|
+
def initialize(input, document_location:, source_location:)
|
63
|
+
@input = input
|
64
|
+
@document_location = document_location
|
65
|
+
@source_location = source_location
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [Boolean]
|
69
|
+
def ==(other)
|
70
|
+
input == other.input &&
|
71
|
+
document_location == other.document_location &&
|
72
|
+
source_location == other.source_location
|
73
|
+
end
|
74
|
+
|
75
|
+
# The OpenAPI document associated with this context
|
76
|
+
#
|
77
|
+
# @return [Document]
|
78
|
+
def document
|
79
|
+
document_location.source.document
|
80
|
+
end
|
81
|
+
|
82
|
+
# The source file used to provide the data for this node
|
83
|
+
#
|
84
|
+
# @return [Source]
|
85
|
+
def source
|
86
|
+
source_location.source
|
87
|
+
end
|
88
|
+
|
89
|
+
# @return [String]
|
90
|
+
def inspect
|
91
|
+
%{#{self.class.name}(document_location: #{document_location}, } +
|
92
|
+
%{source_location: #{source_location})}
|
93
|
+
end
|
94
|
+
|
95
|
+
# A string representing the location of the node
|
96
|
+
#
|
97
|
+
# @return [String]
|
98
|
+
def location_summary
|
99
|
+
summary = document_location.to_s
|
100
|
+
|
101
|
+
if document_location != source_location
|
102
|
+
summary += " (#{source_location})"
|
103
|
+
end
|
104
|
+
|
105
|
+
summary
|
106
|
+
end
|
107
|
+
|
108
|
+
# (see #location_summary)
|
109
|
+
def to_s
|
110
|
+
location_summary
|
111
|
+
end
|
112
|
+
|
113
|
+
# Used to return the data at this document location with all references
|
114
|
+
# resolved and optional fields populated with defaults
|
115
|
+
#
|
116
|
+
# @return [Any]
|
117
|
+
def resolved_input
|
118
|
+
document.resolved_input_at(document_location.pointer)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Return the node for this context
|
122
|
+
#
|
123
|
+
# @return [Node::Object, Node::Map, Node::Array]
|
124
|
+
def node
|
125
|
+
document.node_at(document_location.pointer)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -8,12 +8,12 @@ module Openapi3Parser
|
|
8
8
|
class Discriminator < Node::Object
|
9
9
|
# @return [String]
|
10
10
|
def property_name
|
11
|
-
|
11
|
+
self["propertyName"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [Map<String, String>]
|
15
15
|
def mapping
|
16
|
-
|
16
|
+
self["mapping"]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -8,27 +8,27 @@ module Openapi3Parser
|
|
8
8
|
class Encoding < Node::Object
|
9
9
|
# @return [String, nil]
|
10
10
|
def content_type
|
11
|
-
|
11
|
+
self["contentType"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [Map<String, Header>]
|
15
15
|
def headers
|
16
|
-
|
16
|
+
self["headers"]
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [String, nil]
|
20
20
|
def style
|
21
|
-
|
21
|
+
self["style"]
|
22
22
|
end
|
23
23
|
|
24
24
|
# @return [Boolean]
|
25
25
|
def explode?
|
26
|
-
|
26
|
+
self["explode"]
|
27
27
|
end
|
28
28
|
|
29
29
|
# @return [Boolean]
|
30
30
|
def allow_reserved?
|
31
|
-
|
31
|
+
self["allowReserved"]
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -8,12 +8,12 @@ module Openapi3Parser
|
|
8
8
|
class Example < Node::Object
|
9
9
|
# @return [String, nil]
|
10
10
|
def summary
|
11
|
-
|
11
|
+
self["summary"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [String, nil]
|
15
15
|
def description
|
16
|
-
|
16
|
+
self["description"]
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [String, nil]
|
@@ -23,12 +23,12 @@ module Openapi3Parser
|
|
23
23
|
|
24
24
|
# @return [Object]
|
25
25
|
def value
|
26
|
-
|
26
|
+
self["value"]
|
27
27
|
end
|
28
28
|
|
29
29
|
# @return [String, nil]
|
30
30
|
def external_value
|
31
|
-
|
31
|
+
self["externalValue"]
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -8,7 +8,7 @@ module Openapi3Parser
|
|
8
8
|
class ExternalDocumentation < Node::Object
|
9
9
|
# @return [String, nil]
|
10
10
|
def description
|
11
|
-
|
11
|
+
self["description"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [String, nil]
|
@@ -18,7 +18,7 @@ module Openapi3Parser
|
|
18
18
|
|
19
19
|
# @return [String]
|
20
20
|
def url
|
21
|
-
|
21
|
+
self["url"]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -8,12 +8,12 @@ module Openapi3Parser
|
|
8
8
|
class Info < Node::Object
|
9
9
|
# @return [String]
|
10
10
|
def title
|
11
|
-
|
11
|
+
self["title"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [String, nil]
|
15
15
|
def description
|
16
|
-
|
16
|
+
self["description"]
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [String, nil]
|
@@ -23,22 +23,22 @@ module Openapi3Parser
|
|
23
23
|
|
24
24
|
# @return [String, nil]
|
25
25
|
def terms_of_service
|
26
|
-
|
26
|
+
self["termsOfService"]
|
27
27
|
end
|
28
28
|
|
29
29
|
# @return [Contact, nil]
|
30
30
|
def contact
|
31
|
-
|
31
|
+
self["contact"]
|
32
32
|
end
|
33
33
|
|
34
34
|
# @return [License, nil]
|
35
35
|
def license
|
36
|
-
|
36
|
+
self["license"]
|
37
37
|
end
|
38
38
|
|
39
39
|
# @return [String]
|
40
40
|
def version
|
41
|
-
|
41
|
+
self["version"]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -8,27 +8,27 @@ module Openapi3Parser
|
|
8
8
|
class Link < Node::Object
|
9
9
|
# @return [String, nil]
|
10
10
|
def operation_ref
|
11
|
-
|
11
|
+
self["operationRef"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [String, nil]
|
15
15
|
def operation_id
|
16
|
-
|
16
|
+
self["operationId"]
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [Map<String, Parameter>]
|
20
20
|
def parameters
|
21
|
-
|
21
|
+
self["parameters"]
|
22
22
|
end
|
23
23
|
|
24
24
|
# @return [Any]
|
25
25
|
def request_body
|
26
|
-
|
26
|
+
self["requestBody"]
|
27
27
|
end
|
28
28
|
|
29
29
|
# @return [String, nil]
|
30
30
|
def description
|
31
|
-
|
31
|
+
self["description"]
|
32
32
|
end
|
33
33
|
|
34
34
|
# @return [String, nil]
|
@@ -38,7 +38,7 @@ module Openapi3Parser
|
|
38
38
|
|
39
39
|
# @return [Server, nil]
|
40
40
|
def server
|
41
|
-
|
41
|
+
self["server"]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -8,7 +8,7 @@ module Openapi3Parser
|
|
8
8
|
extend Forwardable
|
9
9
|
include Enumerable
|
10
10
|
|
11
|
-
def_delegators :node_data, :
|
11
|
+
def_delegators :node_data, :keys, :empty?
|
12
12
|
attr_reader :node_data, :node_context
|
13
13
|
|
14
14
|
def initialize(data, context)
|
@@ -32,7 +32,7 @@ module Openapi3Parser
|
|
32
32
|
#
|
33
33
|
# @return anything
|
34
34
|
def [](value)
|
35
|
-
node_data[value.to_s]
|
35
|
+
Placeholder.resolve(node_data[value.to_s])
|
36
36
|
end
|
37
37
|
|
38
38
|
# Look up an extension provided for this map, doesn't need a prefix of
|
@@ -45,11 +45,15 @@ module Openapi3Parser
|
|
45
45
|
#
|
46
46
|
# @return [Hash, Array, Numeric, String, true, false, nil]
|
47
47
|
def extension(value)
|
48
|
-
|
48
|
+
self["x-#{value}"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def each
|
52
|
+
node_data.each_key { |key| yield(self[key]) }
|
49
53
|
end
|
50
54
|
|
51
55
|
# Used to access a node relative to this node
|
52
|
-
# @param [
|
56
|
+
# @param [Source::Pointer, ::Array, ::String] pointer_like
|
53
57
|
# @return anything
|
54
58
|
def node_at(pointer_like)
|
55
59
|
current_pointer = node_context.document_location.pointer
|
@@ -8,22 +8,22 @@ module Openapi3Parser
|
|
8
8
|
class MediaType < Node::Object
|
9
9
|
# @return [Schema, nil]
|
10
10
|
def schema
|
11
|
-
|
11
|
+
self["schema"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [Any]
|
15
15
|
def example
|
16
|
-
|
16
|
+
self["example"]
|
17
17
|
end
|
18
18
|
|
19
|
-
# @return [Map<String, Example
|
19
|
+
# @return [Map<String, Example>, nil]
|
20
20
|
def examples
|
21
|
-
|
21
|
+
self["examples"]
|
22
22
|
end
|
23
23
|
|
24
24
|
# @return [Map<String, Encoding>]
|
25
25
|
def encoding
|
26
|
-
|
26
|
+
self["encoding"]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -8,22 +8,22 @@ module Openapi3Parser
|
|
8
8
|
class OauthFlow < Node::Object
|
9
9
|
# @return [String, nil]
|
10
10
|
def authorization_url
|
11
|
-
|
11
|
+
self["authorizationUrl"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [String, nil]
|
15
15
|
def token_url
|
16
|
-
|
16
|
+
self["tokenUrl"]
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [String, nil]
|
20
20
|
def refresh_url
|
21
|
-
|
21
|
+
self["refreshUrl"]
|
22
22
|
end
|
23
23
|
|
24
24
|
# @return [Map<String, String>]
|
25
25
|
def scopes
|
26
|
-
|
26
|
+
self["scopes"]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -8,22 +8,22 @@ module Openapi3Parser
|
|
8
8
|
class OauthFlows < Node::Object
|
9
9
|
# @return [OauthFlow, nil]
|
10
10
|
def implicit
|
11
|
-
|
11
|
+
self["implicit"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [OauthFlow, nil]
|
15
15
|
def password
|
16
|
-
|
16
|
+
self["password"]
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [OauthFlow, nil]
|
20
20
|
def client_credentials
|
21
|
-
|
21
|
+
self["clientCredentials"]
|
22
22
|
end
|
23
23
|
|
24
24
|
# @return [OauthFlow, nil]
|
25
25
|
def authorization_code
|
26
|
-
|
26
|
+
self["authorizationCode"]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -8,7 +8,7 @@ module Openapi3Parser
|
|
8
8
|
extend Forwardable
|
9
9
|
include Enumerable
|
10
10
|
|
11
|
-
def_delegators :node_data, :
|
11
|
+
def_delegators :node_data, :keys, :empty?
|
12
12
|
attr_reader :node_data, :node_context
|
13
13
|
|
14
14
|
def initialize(data, context)
|
@@ -32,7 +32,7 @@ module Openapi3Parser
|
|
32
32
|
#
|
33
33
|
# @return anything
|
34
34
|
def [](value)
|
35
|
-
node_data[value.to_s]
|
35
|
+
Placeholder.resolve(node_data[value.to_s])
|
36
36
|
end
|
37
37
|
|
38
38
|
# Look up an extension provided for this object, doesn't need a prefix of
|
@@ -45,7 +45,11 @@ module Openapi3Parser
|
|
45
45
|
#
|
46
46
|
# @return [Hash, Array, Numeric, String, true, false, nil]
|
47
47
|
def extension(value)
|
48
|
-
|
48
|
+
self["x-#{value}"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def each
|
52
|
+
node_data.each_key { |key| yield(self[key]) }
|
49
53
|
end
|
50
54
|
|
51
55
|
# Used to render fields that can be in markdown syntax into HTML
|
@@ -64,7 +68,7 @@ module Openapi3Parser
|
|
64
68
|
# @example Jumping way down the tree
|
65
69
|
# obj.node_at("#properties/Field/type")
|
66
70
|
#
|
67
|
-
# @param [
|
71
|
+
# @param [Source::Pointer, ::Array, ::String] pointer_like
|
68
72
|
# @return anything
|
69
73
|
def node_at(pointer_like)
|
70
74
|
current_pointer = node_context.document_location.pointer
|