openapi3_parser 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b49ddc5e4db7f288ea2c27f4cbdd40642b86b037
|
4
|
+
data.tar.gz: 3c391e226bf011a8e1c4b726201ea82b594b1112
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bb0981638b6f39307638fafa63a2cb184eb09117063cdba579d350e3fc369f433646c73f7d324ada7a06e947d69550be601ca2c8fda89297470de9c9360c0da
|
7
|
+
data.tar.gz: c9867350e4f9253ee0b18d1d97a9a4b67bf1cb6b7081957fe650caad86e915ff9956941be6a18ffdfad800d0fd5fd562a801e7a6d9e8bb5ed37d608c921e879e
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# 0.5.1
|
2
|
+
|
3
|
+
- Bugfix for allowing maps to have extension like field names
|
4
|
+
|
5
|
+
# 0.5.0
|
2
6
|
|
3
7
|
- Support for recursive references - fixes: https://github.com/kevindew/openapi3_parser/issues/4
|
4
8
|
- `node_at` method on nodes and document to allow looking up nodes by string
|
@@ -12,7 +12,7 @@ module Openapi3Parser
|
|
12
12
|
module NodeFactory
|
13
13
|
class Map
|
14
14
|
attr_reader :allow_extensions, :context, :data, :default,
|
15
|
-
:
|
15
|
+
:value_input_type, :value_factory,
|
16
16
|
:validation
|
17
17
|
|
18
18
|
# rubocop:disable Metrics/ParameterLists
|
@@ -20,7 +20,6 @@ module Openapi3Parser
|
|
20
20
|
context,
|
21
21
|
allow_extensions: false,
|
22
22
|
default: {},
|
23
|
-
key_input_type: String,
|
24
23
|
value_input_type: nil,
|
25
24
|
value_factory: nil,
|
26
25
|
validate: nil
|
@@ -28,7 +27,6 @@ module Openapi3Parser
|
|
28
27
|
@context = context
|
29
28
|
@allow_extensions = allow_extensions
|
30
29
|
@default = default
|
31
|
-
@key_input_type = key_input_type
|
32
30
|
@value_input_type = value_input_type
|
33
31
|
@value_factory = value_factory
|
34
32
|
@validation = validate
|
@@ -77,7 +75,7 @@ module Openapi3Parser
|
|
77
75
|
|
78
76
|
def process_data(data)
|
79
77
|
data.each_with_object({}) do |(key, value), memo|
|
80
|
-
memo[key] = if EXTENSION_REGEX =~ key || !value_factory
|
78
|
+
memo[key] = if EXTENSION_REGEX =~ key.to_s || !value_factory
|
81
79
|
value
|
82
80
|
else
|
83
81
|
next_context = Context.next_field(context, key)
|
@@ -136,7 +134,6 @@ module Openapi3Parser
|
|
136
134
|
return default_value if factory.nil_input?
|
137
135
|
|
138
136
|
TypeChecker.raise_on_invalid_type(factory.context, type: ::Hash)
|
139
|
-
check_unexpected_fields(raise_on_invalid: true)
|
140
137
|
check_keys(raise_on_invalid: true)
|
141
138
|
check_values(raise_on_invalid: true)
|
142
139
|
validate(raise_on_invalid: true)
|
@@ -153,7 +150,6 @@ module Openapi3Parser
|
|
153
150
|
attr_reader :factory, :validatable
|
154
151
|
|
155
152
|
def collate_errors
|
156
|
-
check_unexpected_fields(raise_on_invalid: false)
|
157
153
|
check_keys(raise_on_invalid: false)
|
158
154
|
check_values(raise_on_invalid: false)
|
159
155
|
validate(raise_on_invalid: false)
|
@@ -171,24 +167,13 @@ module Openapi3Parser
|
|
171
167
|
end
|
172
168
|
end
|
173
169
|
|
174
|
-
def check_unexpected_fields(raise_on_invalid: false)
|
175
|
-
Validators::UnexpectedFields.call(
|
176
|
-
validatable,
|
177
|
-
allowed_fields: nil,
|
178
|
-
raise_on_invalid: raise_on_invalid,
|
179
|
-
allow_extensions: factory.allow_extensions
|
180
|
-
)
|
181
|
-
end
|
182
|
-
|
183
170
|
def check_keys(raise_on_invalid: false)
|
184
|
-
return unless factory.key_input_type
|
185
|
-
|
186
171
|
if raise_on_invalid
|
187
172
|
TypeChecker.raise_on_invalid_keys(factory.context,
|
188
|
-
type:
|
173
|
+
type: ::String)
|
189
174
|
else
|
190
175
|
TypeChecker.validate_keys(validatable,
|
191
|
-
type:
|
176
|
+
type: ::String,
|
192
177
|
context: factory.context)
|
193
178
|
end
|
194
179
|
end
|
@@ -197,6 +182,8 @@ module Openapi3Parser
|
|
197
182
|
return unless factory.value_input_type
|
198
183
|
|
199
184
|
factory.context.input.keys.each do |key|
|
185
|
+
next if factory.allow_extensions && key.to_s =~ EXTENSION_REGEX
|
186
|
+
|
200
187
|
check_field_type(
|
201
188
|
Context.next_field(factory.context, key), raise_on_invalid
|
202
189
|
)
|
@@ -14,8 +14,8 @@ module Openapi3Parser
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(validatable,
|
17
|
+
allowed_fields:,
|
17
18
|
allow_extensions: true,
|
18
|
-
allowed_fields: nil,
|
19
19
|
raise_on_invalid: true)
|
20
20
|
fields = unexpected_fields(validatable.input,
|
21
21
|
allowed_fields,
|
@@ -37,15 +37,9 @@ module Openapi3Parser
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def unexpected_fields(input, allowed_fields, allow_extensions)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
extra_keys.reject { |key| key =~ NodeFactory::EXTENSION_REGEX }
|
44
|
-
elsif !allow_extensions
|
45
|
-
input.keys.select { |key| key =~ NodeFactory::EXTENSION_REGEX }
|
46
|
-
else
|
47
|
-
[]
|
48
|
-
end
|
40
|
+
extra_keys = input.keys - allowed_fields
|
41
|
+
return extra_keys unless allow_extensions
|
42
|
+
extra_keys.reject { |key| key =~ NodeFactory::EXTENSION_REGEX }
|
49
43
|
end
|
50
44
|
end
|
51
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi3_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Dew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commonmarker
|