committee 4.0.0 → 4.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/committee.rb +3 -3
- data/lib/committee/drivers/open_api_2/driver.rb +0 -1
- data/lib/committee/errors.rb +12 -0
- data/lib/committee/middleware/request_validation.rb +4 -11
- data/lib/committee/middleware/response_validation.rb +7 -7
- data/lib/committee/request_unpacker.rb +46 -60
- data/lib/committee/schema_validator/hyper_schema.rb +41 -27
- data/lib/committee/schema_validator/open_api_3.rb +34 -21
- data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +8 -4
- data/lib/committee/schema_validator/open_api_3/router.rb +3 -1
- data/lib/committee/schema_validator/option.rb +22 -3
- data/lib/committee/test/methods.rb +27 -11
- data/lib/committee/test/schema_coverage.rb +101 -0
- data/lib/committee/utils.rb +28 -0
- data/lib/committee/validation_error.rb +3 -2
- data/test/bin/committee_stub_test.rb +5 -1
- data/test/committee_test.rb +1 -1
- data/test/middleware/base_test.rb +9 -3
- data/test/middleware/request_validation_open_api_3_test.rb +82 -6
- data/test/middleware/request_validation_test.rb +16 -0
- data/test/middleware/response_validation_open_api_3_test.rb +26 -2
- data/test/middleware/response_validation_test.rb +11 -0
- data/test/middleware/stub_test.rb +4 -0
- data/test/request_unpacker_test.rb +51 -110
- data/test/schema_validator/hyper_schema/router_test.rb +4 -0
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +14 -3
- data/test/schema_validator/open_api_3/request_validator_test.rb +3 -0
- data/test/schema_validator/open_api_3/response_validator_test.rb +12 -5
- data/test/test/methods_new_version_test.rb +16 -4
- data/test/test/methods_test.rb +151 -7
- data/test/test/schema_coverage_test.rb +216 -0
- data/test/test_helper.rb +20 -0
- metadata +41 -10
@@ -435,6 +435,19 @@ describe Committee::Middleware::RequestValidation do
|
|
435
435
|
assert_equal 200, last_response.status
|
436
436
|
end
|
437
437
|
|
438
|
+
it "corce form params" do
|
439
|
+
check_parameter = lambda { |env|
|
440
|
+
assert_equal 3, env['committee.params']['age']
|
441
|
+
assert_equal 3, env['committee.request_body_hash']['age']
|
442
|
+
[200, {}, []]
|
443
|
+
}
|
444
|
+
|
445
|
+
@app = new_rack_app_with_lambda(check_parameter, schema: open_api_2_form_schema, raise: true, allow_form_params: true, coerce_form_params: true)
|
446
|
+
header "Content-Type", "application/x-www-form-urlencoded"
|
447
|
+
post "/api/pets", "age=3&name=ab"
|
448
|
+
assert_equal 200, last_response.status
|
449
|
+
end
|
450
|
+
|
438
451
|
it "detects an invalid request for OpenAPI" do
|
439
452
|
@app = new_rack_app(schema: open_api_2_schema)
|
440
453
|
get "/api/pets?limit=foo", nil, { "HTTP_AUTH_TOKEN" => "xxx" }
|
@@ -519,6 +532,9 @@ describe Committee::Middleware::RequestValidation do
|
|
519
532
|
|
520
533
|
|
521
534
|
def new_rack_app_with_lambda(check_lambda, options = {})
|
535
|
+
# TODO: delete when 5.0.0 released because default value changed
|
536
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
537
|
+
|
522
538
|
Rack::Builder.new {
|
523
539
|
use Committee::Middleware::RequestValidation, options
|
524
540
|
run check_lambda
|
@@ -34,6 +34,14 @@ describe Committee::Middleware::ResponseValidation do
|
|
34
34
|
assert_equal 200, last_response.status
|
35
35
|
end
|
36
36
|
|
37
|
+
it "passes through a invalid json with parse_response_by_content_type option" do
|
38
|
+
@app = new_response_rack("csv response", { "Content-Type" => "test/csv"}, schema: open_api_3_schema, parse_response_by_content_type: true)
|
39
|
+
|
40
|
+
get "/csv"
|
41
|
+
|
42
|
+
assert_equal 200, last_response.status
|
43
|
+
end
|
44
|
+
|
37
45
|
it "passes through not definition" do
|
38
46
|
@app = new_response_rack(JSON.generate(CHARACTERS_RESPONSE), {}, schema: open_api_3_schema)
|
39
47
|
get "/no_data"
|
@@ -117,7 +125,7 @@ describe Committee::Middleware::ResponseValidation do
|
|
117
125
|
[
|
118
126
|
{ check_header: true, description: 'valid value', header: { 'integer' => 1 }, expected: { status: 200 } },
|
119
127
|
{ check_header: true, description: 'missing value', header: { 'integer' => nil }, expected: { error: 'headers/integer/schema does not allow null values' } },
|
120
|
-
{ check_header: true, description: 'invalid value', header: { 'integer' => 'x' }, expected: { error: 'headers/integer/schema expected integer, but received String: x' } },
|
128
|
+
{ check_header: true, description: 'invalid value', header: { 'integer' => 'x' }, expected: { error: 'headers/integer/schema expected integer, but received String: "x"' } },
|
121
129
|
|
122
130
|
{ check_header: false, description: 'valid value', header: { 'integer' => 1 }, expected: { status: 200 } },
|
123
131
|
{ check_header: false, description: 'missing value', header: { 'integer' => nil }, expected: { status: 200 } },
|
@@ -169,7 +177,7 @@ describe Committee::Middleware::ResponseValidation do
|
|
169
177
|
get "/characters"
|
170
178
|
end
|
171
179
|
|
172
|
-
assert_match(/but received String: 1/i, e.message)
|
180
|
+
assert_match(/but received String: \"1\"/i, e.message)
|
173
181
|
end
|
174
182
|
|
175
183
|
it "detects an invalid response status code with validate_success_only=true" do
|
@@ -207,9 +215,25 @@ describe Committee::Middleware::ResponseValidation do
|
|
207
215
|
end
|
208
216
|
end
|
209
217
|
|
218
|
+
it 'does not suppress application error' do
|
219
|
+
@app = Rack::Builder.new {
|
220
|
+
use Committee::Middleware::ResponseValidation, {schema: open_api_3_schema, raise: true}
|
221
|
+
run lambda { |_|
|
222
|
+
JSON.load('-') # invalid json
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
assert_raises(JSON::ParserError) do
|
227
|
+
get "/error", nil
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
210
231
|
private
|
211
232
|
|
212
233
|
def new_response_rack(response, headers = {}, options = {}, rack_options = {})
|
234
|
+
# TODO: delete when 5.0.0 released because default value changed
|
235
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
236
|
+
|
213
237
|
status = rack_options[:status] || 200
|
214
238
|
headers = {
|
215
239
|
"Content-Type" => "application/json"
|
@@ -15,6 +15,14 @@ describe Committee::Middleware::ResponseValidation do
|
|
15
15
|
assert_equal 200, last_response.status
|
16
16
|
end
|
17
17
|
|
18
|
+
# TODO: remove 5.0.0
|
19
|
+
it "passes through a valid response" do
|
20
|
+
# will show deprecated message
|
21
|
+
@app = new_rack_app(JSON.generate([ValidApp]), {}, schema: hyper_schema, strict: true)
|
22
|
+
get "/apps"
|
23
|
+
assert_equal 200, last_response.status
|
24
|
+
end
|
25
|
+
|
18
26
|
it "doesn't call error_handler (has a arg) when response is valid" do
|
19
27
|
called = false
|
20
28
|
pr = ->(_e) { called = true }
|
@@ -184,6 +192,9 @@ describe Committee::Middleware::ResponseValidation do
|
|
184
192
|
private
|
185
193
|
|
186
194
|
def new_rack_app(response, headers = {}, options = {})
|
195
|
+
# TODO: delete when 5.0.0 released because default value changed
|
196
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
197
|
+
|
187
198
|
headers = {
|
188
199
|
"Content-Type" => "application/json"
|
189
200
|
}.merge(headers)
|
@@ -112,6 +112,10 @@ describe Committee::Middleware::Stub do
|
|
112
112
|
def new_rack_app(options = {})
|
113
113
|
response = options.delete(:response)
|
114
114
|
suppress = options.delete(:suppress)
|
115
|
+
|
116
|
+
# TODO: delete when 5.0.0 released because default value changed
|
117
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
118
|
+
|
115
119
|
Rack::Builder.new {
|
116
120
|
use Committee::Middleware::Stub, options
|
117
121
|
run lambda { |env|
|
@@ -9,8 +9,18 @@ describe Committee::RequestUnpacker do
|
|
9
9
|
"rack.input" => StringIO.new('{"x":"y"}'),
|
10
10
|
}
|
11
11
|
request = Rack::Request.new(env)
|
12
|
-
|
13
|
-
assert_equal({ "x" => "y" },
|
12
|
+
unpacker = Committee::RequestUnpacker.new
|
13
|
+
assert_equal([{ "x" => "y" }, false], unpacker.unpack_request_params(request))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "unpacks JSON on Content-Type: application/vnd.api+json" do
|
17
|
+
env = {
|
18
|
+
"CONTENT_TYPE" => "application/vnd.api+json",
|
19
|
+
"rack.input" => StringIO.new('{"x":"y"}'),
|
20
|
+
}
|
21
|
+
request = Rack::Request.new(env)
|
22
|
+
unpacker = Committee::RequestUnpacker.new
|
23
|
+
assert_equal([{ "x" => "y" }, false], unpacker.unpack_request_params(request))
|
14
24
|
end
|
15
25
|
|
16
26
|
it "unpacks JSON on no Content-Type" do
|
@@ -18,8 +28,18 @@ describe Committee::RequestUnpacker do
|
|
18
28
|
"rack.input" => StringIO.new('{"x":"y"}'),
|
19
29
|
}
|
20
30
|
request = Rack::Request.new(env)
|
21
|
-
|
22
|
-
assert_equal({ "x" => "y" },
|
31
|
+
unpacker = Committee::RequestUnpacker.new
|
32
|
+
assert_equal([{ "x" => "y" }, false], unpacker.unpack_request_params(request))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "doesn't unpack JSON on application/x-ndjson" do
|
36
|
+
env = {
|
37
|
+
"CONTENT_TYPE" => "application/x-ndjson",
|
38
|
+
"rack.input" => StringIO.new('{"x":"y"}\n{"a":"b"}'),
|
39
|
+
}
|
40
|
+
request = Rack::Request.new(env)
|
41
|
+
unpacker = Committee::RequestUnpacker.new
|
42
|
+
assert_equal([{}, false], unpacker.unpack_request_params(request))
|
23
43
|
end
|
24
44
|
|
25
45
|
it "doesn't unpack JSON under other Content-Types" do
|
@@ -29,8 +49,8 @@ describe Committee::RequestUnpacker do
|
|
29
49
|
"rack.input" => StringIO.new('{"x":"y"}'),
|
30
50
|
}
|
31
51
|
request = Rack::Request.new(env)
|
32
|
-
|
33
|
-
assert_equal({},
|
52
|
+
unpacker = Committee::RequestUnpacker.new
|
53
|
+
assert_equal([{}, false], unpacker.unpack_request_params(request))
|
34
54
|
end
|
35
55
|
end
|
36
56
|
|
@@ -41,8 +61,8 @@ describe Committee::RequestUnpacker do
|
|
41
61
|
"rack.input" => StringIO.new('{"x":"y"}'),
|
42
62
|
}
|
43
63
|
request = Rack::Request.new(env)
|
44
|
-
|
45
|
-
assert_equal({ "x" => "y" },
|
64
|
+
unpacker = Committee::RequestUnpacker.new(optimistic_json: true)
|
65
|
+
assert_equal([{ "x" => "y" }, false], unpacker.unpack_request_params(request))
|
46
66
|
end
|
47
67
|
end
|
48
68
|
|
@@ -53,8 +73,8 @@ describe Committee::RequestUnpacker do
|
|
53
73
|
"rack.input" => StringIO.new('x=y&foo=42'),
|
54
74
|
}
|
55
75
|
request = Rack::Request.new(env)
|
56
|
-
|
57
|
-
assert_equal({},
|
76
|
+
unpacker = Committee::RequestUnpacker.new(optimistic_json: true)
|
77
|
+
assert_equal([{}, false], unpacker.unpack_request_params(request))
|
58
78
|
end
|
59
79
|
end
|
60
80
|
|
@@ -64,8 +84,8 @@ describe Committee::RequestUnpacker do
|
|
64
84
|
"rack.input" => StringIO.new(""),
|
65
85
|
}
|
66
86
|
request = Rack::Request.new(env)
|
67
|
-
|
68
|
-
assert_equal({},
|
87
|
+
unpacker = Committee::RequestUnpacker.new
|
88
|
+
assert_equal([{}, false], unpacker.unpack_request_params(request))
|
69
89
|
end
|
70
90
|
|
71
91
|
it "doesn't unpack form params" do
|
@@ -75,8 +95,8 @@ describe Committee::RequestUnpacker do
|
|
75
95
|
"rack.input" => StringIO.new("x=y"),
|
76
96
|
}
|
77
97
|
request = Rack::Request.new(env)
|
78
|
-
|
79
|
-
assert_equal({},
|
98
|
+
unpacker = Committee::RequestUnpacker.new
|
99
|
+
assert_equal([{}, false], unpacker.unpack_request_params(request))
|
80
100
|
end
|
81
101
|
end
|
82
102
|
|
@@ -87,87 +107,8 @@ describe Committee::RequestUnpacker do
|
|
87
107
|
"rack.input" => StringIO.new("x=y"),
|
88
108
|
}
|
89
109
|
request = Rack::Request.new(env)
|
90
|
-
|
91
|
-
assert_equal({ "x" => "y" },
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
it "coerces form params with coerce_form_params and a schema" do
|
96
|
-
%w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
|
97
|
-
env = {
|
98
|
-
"CONTENT_TYPE" => content_type,
|
99
|
-
"rack.input" => StringIO.new("x=1"),
|
100
|
-
}
|
101
|
-
request = Rack::Request.new(env)
|
102
|
-
|
103
|
-
router = hyper_schema.build_router({})
|
104
|
-
validator = router.build_schema_validator(request)
|
105
|
-
|
106
|
-
schema = JsonSchema::Schema.new
|
107
|
-
schema.properties = { "x" => JsonSchema::Schema.new }
|
108
|
-
schema.properties["x"].type = ["integer"]
|
109
|
-
|
110
|
-
link_class = Struct.new(:schema)
|
111
|
-
link_object = link_class.new(schema)
|
112
|
-
|
113
|
-
validator.instance_variable_set(:@link, link_object)
|
114
|
-
|
115
|
-
params, _ = Committee::RequestUnpacker.new(
|
116
|
-
request,
|
117
|
-
allow_form_params: true,
|
118
|
-
coerce_form_params: true,
|
119
|
-
schema_validator: validator,
|
120
|
-
).call
|
121
|
-
assert_equal({ "x" => 1 }, params)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
it "coerces form params with coerce_form_params and an OpenAPI3 schema" do
|
126
|
-
%w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
|
127
|
-
env = {
|
128
|
-
"CONTENT_TYPE" => content_type,
|
129
|
-
"rack.input" => StringIO.new("limit=20"),
|
130
|
-
"PATH_INFO" => "/characters",
|
131
|
-
"SCRIPT_NAME" => "",
|
132
|
-
"REQUEST_METHOD" => "GET",
|
133
|
-
}
|
134
|
-
request = Rack::Request.new(env)
|
135
|
-
|
136
|
-
router = open_api_3_schema.build_router({})
|
137
|
-
validator = router.build_schema_validator(request)
|
138
|
-
|
139
|
-
params, _ = Committee::RequestUnpacker.new(
|
140
|
-
request,
|
141
|
-
allow_form_params: true,
|
142
|
-
coerce_form_params: true,
|
143
|
-
schema_validator: validator,
|
144
|
-
).call
|
145
|
-
# openapi3 not support coerce in request unpacker
|
146
|
-
assert_equal({ "limit" => '20' }, params)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it "coerces error params with coerce_form_params and a OpenAPI3 schema" do
|
151
|
-
%w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
|
152
|
-
env = {
|
153
|
-
"CONTENT_TYPE" => content_type,
|
154
|
-
"rack.input" => StringIO.new("limit=twenty"),
|
155
|
-
"PATH_INFO" => "/characters",
|
156
|
-
"SCRIPT_NAME" => "",
|
157
|
-
"REQUEST_METHOD" => "GET",
|
158
|
-
}
|
159
|
-
request = Rack::Request.new(env)
|
160
|
-
|
161
|
-
router = open_api_3_schema.build_router({})
|
162
|
-
validator = router.build_schema_validator(request)
|
163
|
-
|
164
|
-
params, _ = Committee::RequestUnpacker.new(
|
165
|
-
request,
|
166
|
-
allow_form_params: true,
|
167
|
-
coerce_form_params: true,
|
168
|
-
schema_validator: validator,
|
169
|
-
).call
|
170
|
-
assert_equal({ "limit" => "twenty" }, params)
|
110
|
+
unpacker = Committee::RequestUnpacker.new(allow_form_params: true)
|
111
|
+
assert_equal([{ "x" => "y" }, true], unpacker.unpack_request_params(request))
|
171
112
|
end
|
172
113
|
end
|
173
114
|
|
@@ -179,8 +120,8 @@ describe Committee::RequestUnpacker do
|
|
179
120
|
"QUERY_STRING" => "a=b"
|
180
121
|
}
|
181
122
|
request = Rack::Request.new(env)
|
182
|
-
|
183
|
-
assert_equal({ "x" => "y",
|
123
|
+
unpacker = Committee::RequestUnpacker.new(allow_form_params: true, allow_query_params: true)
|
124
|
+
assert_equal([ { "x" => "y"}, true], unpacker.unpack_request_params(request))
|
184
125
|
end
|
185
126
|
end
|
186
127
|
|
@@ -190,8 +131,8 @@ describe Committee::RequestUnpacker do
|
|
190
131
|
"QUERY_STRING" => "a=b"
|
191
132
|
}
|
192
133
|
request = Rack::Request.new(env)
|
193
|
-
|
194
|
-
assert_equal({ "a" => "b" },
|
134
|
+
unpacker = Committee::RequestUnpacker.new(allow_query_params: true)
|
135
|
+
assert_equal({ "a" => "b" }, unpacker.unpack_query_params(request))
|
195
136
|
end
|
196
137
|
|
197
138
|
it "errors if JSON is not an object" do
|
@@ -201,7 +142,7 @@ describe Committee::RequestUnpacker do
|
|
201
142
|
}
|
202
143
|
request = Rack::Request.new(env)
|
203
144
|
assert_raises(Committee::BadRequest) do
|
204
|
-
Committee::RequestUnpacker.new(request)
|
145
|
+
Committee::RequestUnpacker.new.unpack_request_params(request)
|
205
146
|
end
|
206
147
|
end
|
207
148
|
|
@@ -211,8 +152,8 @@ describe Committee::RequestUnpacker do
|
|
211
152
|
"rack.input" => StringIO.new('{"x":"y"}'),
|
212
153
|
}
|
213
154
|
request = Rack::Request.new(env)
|
214
|
-
|
215
|
-
assert_equal({},
|
155
|
+
unpacker = Committee::RequestUnpacker.new
|
156
|
+
assert_equal([{}, false], unpacker.unpack_request_params(request))
|
216
157
|
end
|
217
158
|
|
218
159
|
# this is mostly here for line coverage
|
@@ -221,8 +162,8 @@ describe Committee::RequestUnpacker do
|
|
221
162
|
"rack.input" => StringIO.new('{"x":[]}'),
|
222
163
|
}
|
223
164
|
request = Rack::Request.new(env)
|
224
|
-
|
225
|
-
assert_equal({ "x" => [] },
|
165
|
+
unpacker = Committee::RequestUnpacker.new
|
166
|
+
assert_equal([{ "x" => [] }, false], unpacker.unpack_request_params(request))
|
226
167
|
end
|
227
168
|
|
228
169
|
it "unpacks http header" do
|
@@ -231,8 +172,8 @@ describe Committee::RequestUnpacker do
|
|
231
172
|
"rack.input" => StringIO.new(""),
|
232
173
|
}
|
233
174
|
request = Rack::Request.new(env)
|
234
|
-
|
235
|
-
assert_equal({ "FOO-BAR" => "some header value" },
|
175
|
+
unpacker = Committee::RequestUnpacker.new({ allow_header_params: true })
|
176
|
+
assert_equal({ "FOO-BAR" => "some header value" }, unpacker.unpack_headers(request))
|
236
177
|
end
|
237
178
|
|
238
179
|
it "includes request body when`use_get_body` is true" do
|
@@ -242,8 +183,8 @@ describe Committee::RequestUnpacker do
|
|
242
183
|
"QUERY_STRING"=>"data=value&x=aaa",
|
243
184
|
}
|
244
185
|
request = Rack::Request.new(env)
|
245
|
-
|
246
|
-
assert_equal({ '
|
186
|
+
unpacker = Committee::RequestUnpacker.new({ allow_query_params: true, allow_get_body: true })
|
187
|
+
assert_equal([{ 'x' => 1, 'y' => 2 }, false], unpacker.unpack_request_params(request))
|
247
188
|
end
|
248
189
|
|
249
190
|
it "doesn't include request body when `use_get_body` is false" do
|
@@ -253,7 +194,7 @@ describe Committee::RequestUnpacker do
|
|
253
194
|
"QUERY_STRING"=>"data=value&x=aaa",
|
254
195
|
}
|
255
196
|
request = Rack::Request.new(env)
|
256
|
-
|
257
|
-
assert_equal({ 'data' => 'value', 'x' => 'aaa' },
|
197
|
+
unpacker = Committee::RequestUnpacker.new({ allow_query_params: true, use_get_body: false })
|
198
|
+
assert_equal({ 'data' => 'value', 'x' => 'aaa' }, unpacker.unpack_query_params(request))
|
258
199
|
end
|
259
200
|
end
|
@@ -69,6 +69,8 @@ describe Committee::SchemaValidator::HyperSchema::Router do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def hyper_schema_router(options = {})
|
72
|
+
# TODO: delete when 5.0.0 released because default value changed
|
73
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
72
74
|
schema = Committee::Drivers::HyperSchema::Driver.new.parse(hyper_schema_data)
|
73
75
|
validator_option = Committee::SchemaValidator::Option.new(options, schema, :hyper_schema)
|
74
76
|
|
@@ -76,6 +78,8 @@ describe Committee::SchemaValidator::HyperSchema::Router do
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def open_api_2_router(options = {})
|
81
|
+
# TODO: delete when 5.0.0 released because default value changed
|
82
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
79
83
|
schema = Committee::Drivers::OpenAPI2::Driver.new.parse(open_api_2_data)
|
80
84
|
validator_option = Committee::SchemaValidator::Option.new(options, schema, :hyper_schema)
|
81
85
|
|
@@ -9,7 +9,12 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
9
9
|
before do
|
10
10
|
@path = '/validate'
|
11
11
|
@method = 'post'
|
12
|
-
|
12
|
+
|
13
|
+
# TODO: delete when 5.0.0 released because default value changed
|
14
|
+
options = {}
|
15
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
16
|
+
|
17
|
+
@validator_option = Committee::SchemaValidator::Option.new(options, open_api_3_schema, :open_api_3)
|
13
18
|
end
|
14
19
|
|
15
20
|
def operation_object
|
@@ -53,6 +58,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
53
58
|
}
|
54
59
|
|
55
60
|
assert_match(/expected string, but received Integer: 1/i, e.message)
|
61
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
56
62
|
end
|
57
63
|
|
58
64
|
it 'support put method' do
|
@@ -64,6 +70,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
64
70
|
}
|
65
71
|
|
66
72
|
assert_match(/expected string, but received Integer: 1/i, e.message)
|
73
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
67
74
|
end
|
68
75
|
|
69
76
|
it 'support patch method' do
|
@@ -74,7 +81,8 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
74
81
|
operation_object.validate_request_params({"integer" => "str"}, HEADER, @validator_option)
|
75
82
|
}
|
76
83
|
|
77
|
-
assert_match(/expected integer, but received String: str/i, e.message)
|
84
|
+
assert_match(/expected integer, but received String: "str"/i, e.message)
|
85
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
78
86
|
end
|
79
87
|
|
80
88
|
it 'unknown param' do
|
@@ -108,6 +116,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
108
116
|
}
|
109
117
|
|
110
118
|
assert_match(/missing required parameters: query_string/i, e.message)
|
119
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
111
120
|
end
|
112
121
|
|
113
122
|
it 'invalid type' do
|
@@ -120,6 +129,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
120
129
|
}
|
121
130
|
|
122
131
|
assert_match(/expected string, but received Integer: 1/i, e.message)
|
132
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
123
133
|
end
|
124
134
|
end
|
125
135
|
|
@@ -140,7 +150,8 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
140
150
|
operation_object.validate_request_params({"limit" => "a"}, HEADER, @validator_option)
|
141
151
|
}
|
142
152
|
|
143
|
-
assert_match(/expected integer, but received String: a/i, e.message)
|
153
|
+
assert_match(/expected integer, but received String: "a"/i, e.message)
|
154
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
144
155
|
end
|
145
156
|
end
|
146
157
|
|