committee 3.3.0 → 4.3.0
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 +2 -3
- data/lib/committee/drivers.rb +5 -5
- data/lib/committee/errors.rb +12 -0
- data/lib/committee/middleware/request_validation.rb +4 -8
- data/lib/committee/middleware/response_validation.rb +3 -7
- data/lib/committee/request_unpacker.rb +1 -1
- data/lib/committee/schema_validator/hyper_schema.rb +8 -1
- data/lib/committee/schema_validator/open_api_3.rb +8 -1
- 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 +8 -1
- data/lib/committee/test/methods.rb +17 -8
- data/lib/committee/test/schema_coverage.rb +101 -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 +24 -6
- data/test/middleware/request_validation_test.rb +7 -1
- data/test/middleware/response_validation_open_api_3_test.rb +48 -2
- data/test/middleware/response_validation_test.rb +7 -1
- data/test/middleware/stub_test.rb +4 -0
- data/test/request_unpacker_test.rb +32 -3
- data/test/schema_validator/hyper_schema/router_test.rb +4 -0
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +15 -7
- 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 +3 -0
- data/test/test/methods_test.rb +145 -3
- data/test/test/schema_coverage_test.rb +216 -0
- data/test/test_helper.rb +9 -1
- metadata +8 -6
data/test/committee_test.rb
CHANGED
@@ -103,17 +103,20 @@ describe Committee::Middleware::Base do
|
|
103
103
|
|
104
104
|
describe 'initialize option' do
|
105
105
|
it "schema_path option with hyper-schema" do
|
106
|
-
|
106
|
+
# TODO: delete when 5.0.0 released because default value changed
|
107
|
+
b = Committee::Middleware::Base.new(nil, schema_path: hyper_schema_schema_path, parse_response_by_content_type: false)
|
107
108
|
assert_kind_of Committee::Drivers::HyperSchema::Schema, b.instance_variable_get(:@schema)
|
108
109
|
end
|
109
110
|
|
110
111
|
it "schema_path option with OpenAPI2" do
|
111
|
-
|
112
|
+
# TODO: delete when 5.0.0 released because default value changed
|
113
|
+
b = Committee::Middleware::Base.new(nil, schema_path: open_api_2_schema_path, parse_response_by_content_type: false)
|
112
114
|
assert_kind_of Committee::Drivers::OpenAPI2::Schema, b.instance_variable_get(:@schema)
|
113
115
|
end
|
114
116
|
|
115
117
|
it "schema_path option with OpenAPI3" do
|
116
|
-
|
118
|
+
# TODO: delete when 5.0.0 released because default value changed
|
119
|
+
b = Committee::Middleware::Base.new(nil, schema_path: open_api_3_schema_path, parse_response_by_content_type: false)
|
117
120
|
assert_kind_of Committee::Drivers::OpenAPI3::Schema, b.instance_variable_get(:@schema)
|
118
121
|
end
|
119
122
|
end
|
@@ -121,6 +124,9 @@ describe Committee::Middleware::Base do
|
|
121
124
|
private
|
122
125
|
|
123
126
|
def new_rack_app(options = {})
|
127
|
+
# TODO: delete when 5.0.0 released because default value changed
|
128
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
129
|
+
|
124
130
|
Rack::Builder.new {
|
125
131
|
use Committee::Middleware::RequestValidation, options
|
126
132
|
run lambda { |_|
|
@@ -249,8 +249,7 @@ describe Committee::Middleware::RequestValidation do
|
|
249
249
|
}
|
250
250
|
post "/characters", JSON.generate(params)
|
251
251
|
assert_equal 400, last_response.status
|
252
|
-
|
253
|
-
assert_match(/expected string, but received #{1.class}:/i, last_response.body)
|
252
|
+
assert_match(/expected string, but received Integer:/i, last_response.body)
|
254
253
|
end
|
255
254
|
|
256
255
|
it "rescues JSON errors" do
|
@@ -279,8 +278,7 @@ describe Committee::Middleware::RequestValidation do
|
|
279
278
|
header "Content-Type", "application/json"
|
280
279
|
post "/v1/characters", JSON.generate(params)
|
281
280
|
assert_equal 400, last_response.status
|
282
|
-
|
283
|
-
assert_match(/expected string, but received #{1.class}: /i, last_response.body)
|
281
|
+
assert_match(/expected string, but received Integer: /i, last_response.body)
|
284
282
|
end
|
285
283
|
|
286
284
|
it "ignores paths outside the prefix" do
|
@@ -415,7 +413,11 @@ describe Committee::Middleware::RequestValidation do
|
|
415
413
|
{ check_header: false, description: 'valid value', value: 1, expected: { status: 200 } },
|
416
414
|
{ check_header: false, description: 'missing value', value: nil, expected: { status: 200 } },
|
417
415
|
{ check_header: false, description: 'invalid value', value: 'x', expected: { status: 200 } },
|
418
|
-
].each do |
|
416
|
+
].each do |h|
|
417
|
+
check_header = h[:check_header]
|
418
|
+
description = h[:description]
|
419
|
+
value = h[:value]
|
420
|
+
expected = h[:expected]
|
419
421
|
describe "when #{check_header}" do
|
420
422
|
%w(get post put patch delete).each do |method|
|
421
423
|
describe method do
|
@@ -441,7 +443,10 @@ describe Committee::Middleware::RequestValidation do
|
|
441
443
|
{ description: 'when not specified, includes everything', accept_request_filter: nil, expected: { status: 400 } },
|
442
444
|
{ description: 'when predicate matches, performs validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/c') }, expected: { status: 400 } },
|
443
445
|
{ description: 'when predicate does not match, skips validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/x') }, expected: { status: 200 } },
|
444
|
-
].each do |
|
446
|
+
].each do |h|
|
447
|
+
description = h[:description]
|
448
|
+
accept_request_filter = h[:accept_request_filter]
|
449
|
+
expected = h[:expected]
|
445
450
|
it description do
|
446
451
|
@app = new_rack_app(prefix: '/v1', schema: open_api_3_schema, accept_request_filter: accept_request_filter)
|
447
452
|
|
@@ -452,6 +457,16 @@ describe Committee::Middleware::RequestValidation do
|
|
452
457
|
end
|
453
458
|
end
|
454
459
|
|
460
|
+
it 'does not suppress application error' do
|
461
|
+
@app = new_rack_app_with_lambda(lambda { |_|
|
462
|
+
JSON.load('-') # invalid json
|
463
|
+
}, schema: open_api_3_schema, raise: true)
|
464
|
+
|
465
|
+
assert_raises(JSON::ParserError) do
|
466
|
+
get "/error", nil
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
455
470
|
private
|
456
471
|
|
457
472
|
def new_rack_app(options = {})
|
@@ -461,6 +476,9 @@ describe Committee::Middleware::RequestValidation do
|
|
461
476
|
end
|
462
477
|
|
463
478
|
def new_rack_app_with_lambda(check_lambda, options = {})
|
479
|
+
# TODO: delete when 5.0.0 released because default value changed
|
480
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
481
|
+
|
464
482
|
Rack::Builder.new {
|
465
483
|
use Committee::Middleware::RequestValidation, options
|
466
484
|
run check_lambda
|
@@ -495,7 +495,10 @@ describe Committee::Middleware::RequestValidation do
|
|
495
495
|
{ description: 'when not specified, includes everything', accept_request_filter: nil, expected: { status: 400 } },
|
496
496
|
{ description: 'when predicate matches, performs validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/a') }, expected: { status: 400 } },
|
497
497
|
{ description: 'when predicate does not match, skips validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/x') }, expected: { status: 200 } },
|
498
|
-
].each do |
|
498
|
+
].each do |h|
|
499
|
+
description = h[:description]
|
500
|
+
accept_request_filter = h[:accept_request_filter]
|
501
|
+
expected = h[:expected]
|
499
502
|
it description do
|
500
503
|
@app = new_rack_app(prefix: '/v1', schema: hyper_schema, accept_request_filter: accept_request_filter)
|
501
504
|
|
@@ -516,6 +519,9 @@ describe Committee::Middleware::RequestValidation do
|
|
516
519
|
|
517
520
|
|
518
521
|
def new_rack_app_with_lambda(check_lambda, options = {})
|
522
|
+
# TODO: delete when 5.0.0 released because default value changed
|
523
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
524
|
+
|
519
525
|
Rack::Builder.new {
|
520
526
|
use Committee::Middleware::RequestValidation, options
|
521
527
|
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"
|
@@ -99,6 +107,20 @@ describe Committee::Middleware::ResponseValidation do
|
|
99
107
|
assert_match(/valid JSON/i, last_response.body)
|
100
108
|
end
|
101
109
|
|
110
|
+
describe "remote schema $ref" do
|
111
|
+
it "passes through a valid response" do
|
112
|
+
@app = new_response_rack(JSON.generate({ "sample" => "value" }), {}, schema: open_api_3_schema)
|
113
|
+
get "/ref-sample"
|
114
|
+
assert_equal 200, last_response.status
|
115
|
+
end
|
116
|
+
|
117
|
+
it "detects a invalid response" do
|
118
|
+
@app = new_response_rack("{}", {}, schema: open_api_3_schema)
|
119
|
+
get "/ref-sample"
|
120
|
+
assert_equal 500, last_response.status
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
102
124
|
describe 'check header' do
|
103
125
|
[
|
104
126
|
{ check_header: true, description: 'valid value', header: { 'integer' => 1 }, expected: { status: 200 } },
|
@@ -108,7 +130,11 @@ describe Committee::Middleware::ResponseValidation do
|
|
108
130
|
{ check_header: false, description: 'valid value', header: { 'integer' => 1 }, expected: { status: 200 } },
|
109
131
|
{ check_header: false, description: 'missing value', header: { 'integer' => nil }, expected: { status: 200 } },
|
110
132
|
{ check_header: false, description: 'invalid value', header: { 'integer' => 'x' }, expected: { status: 200 } },
|
111
|
-
].each do |
|
133
|
+
].each do |h|
|
134
|
+
check_header = h[:check_header]
|
135
|
+
description = h[:description]
|
136
|
+
header = h[:header]
|
137
|
+
expected = h[:expected]
|
112
138
|
describe "when #{check_header}" do
|
113
139
|
%w(get post put patch delete).each do |method|
|
114
140
|
describe method do
|
@@ -174,7 +200,11 @@ describe Committee::Middleware::ResponseValidation do
|
|
174
200
|
{ description: 'when not specified, includes everything', accept_request_filter: nil, expected: { status: 500 } },
|
175
201
|
{ description: 'when predicate matches, performs validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/c') }, expected: { status: 500 } },
|
176
202
|
{ description: 'when predicate does not match, skips validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/x') }, expected: { status: 200 } },
|
177
|
-
].each do |
|
203
|
+
].each do |h|
|
204
|
+
description = h[:description]
|
205
|
+
accept_request_filter = h[:accept_request_filter]
|
206
|
+
expected = h[:expected]
|
207
|
+
|
178
208
|
it description do
|
179
209
|
@app = new_response_rack('not_json', {}, schema: open_api_3_schema, prefix: '/v1', accept_request_filter: accept_request_filter)
|
180
210
|
|
@@ -185,9 +215,25 @@ describe Committee::Middleware::ResponseValidation do
|
|
185
215
|
end
|
186
216
|
end
|
187
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
|
+
|
188
231
|
private
|
189
232
|
|
190
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
|
+
|
191
237
|
status = rack_options[:status] || 200
|
192
238
|
headers = {
|
193
239
|
"Content-Type" => "application/json"
|
@@ -167,7 +167,10 @@ describe Committee::Middleware::ResponseValidation do
|
|
167
167
|
{ description: 'when not specified, includes everything', accept_request_filter: nil, expected: { status: 500 } },
|
168
168
|
{ description: 'when predicate matches, performs validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/a') }, expected: { status: 500 } },
|
169
169
|
{ description: 'when predicate does not match, skips validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/x') }, expected: { status: 200 } },
|
170
|
-
].each do |
|
170
|
+
].each do |h|
|
171
|
+
description = h[:description]
|
172
|
+
accept_request_filter = h[:accept_request_filter]
|
173
|
+
expected = h[:expected]
|
171
174
|
it description do
|
172
175
|
@app = new_rack_app('not_json', {}, schema: hyper_schema, prefix: '/v1', accept_request_filter: accept_request_filter)
|
173
176
|
|
@@ -181,6 +184,9 @@ describe Committee::Middleware::ResponseValidation do
|
|
181
184
|
private
|
182
185
|
|
183
186
|
def new_rack_app(response, headers = {}, options = {})
|
187
|
+
# TODO: delete when 5.0.0 released because default value changed
|
188
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
189
|
+
|
184
190
|
headers = {
|
185
191
|
"Content-Type" => "application/json"
|
186
192
|
}.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|
|
@@ -13,6 +13,16 @@ describe Committee::RequestUnpacker do
|
|
13
13
|
assert_equal({ "x" => "y" }, params)
|
14
14
|
end
|
15
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
|
+
params, _ = Committee::RequestUnpacker.new(request).call
|
23
|
+
assert_equal({ "x" => "y" }, params)
|
24
|
+
end
|
25
|
+
|
16
26
|
it "unpacks JSON on no Content-Type" do
|
17
27
|
env = {
|
18
28
|
"rack.input" => StringIO.new('{"x":"y"}'),
|
@@ -22,6 +32,16 @@ describe Committee::RequestUnpacker do
|
|
22
32
|
assert_equal({ "x" => "y" }, params)
|
23
33
|
end
|
24
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
|
+
params, _ = Committee::RequestUnpacker.new(request).call
|
42
|
+
assert_equal({}, params)
|
43
|
+
end
|
44
|
+
|
25
45
|
it "doesn't unpack JSON under other Content-Types" do
|
26
46
|
%w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
|
27
47
|
env = {
|
@@ -100,7 +120,10 @@ describe Committee::RequestUnpacker do
|
|
100
120
|
}
|
101
121
|
request = Rack::Request.new(env)
|
102
122
|
|
103
|
-
|
123
|
+
options = {}
|
124
|
+
# TODO: delete when 5.0.0 released because default value changed
|
125
|
+
options[:parse_response_by_content_type] = false
|
126
|
+
router = hyper_schema.build_router(options)
|
104
127
|
validator = router.build_schema_validator(request)
|
105
128
|
|
106
129
|
schema = JsonSchema::Schema.new
|
@@ -133,7 +156,10 @@ describe Committee::RequestUnpacker do
|
|
133
156
|
}
|
134
157
|
request = Rack::Request.new(env)
|
135
158
|
|
136
|
-
|
159
|
+
options = {}
|
160
|
+
# TODO: delete when 5.0.0 released because default value changed
|
161
|
+
options[:parse_response_by_content_type] = false
|
162
|
+
router = open_api_3_schema.build_router(options)
|
137
163
|
validator = router.build_schema_validator(request)
|
138
164
|
|
139
165
|
params, _ = Committee::RequestUnpacker.new(
|
@@ -158,7 +184,10 @@ describe Committee::RequestUnpacker do
|
|
158
184
|
}
|
159
185
|
request = Rack::Request.new(env)
|
160
186
|
|
161
|
-
|
187
|
+
options = {}
|
188
|
+
# TODO: delete when 5.0.0 released because default value changed
|
189
|
+
options[:parse_response_by_content_type] = false
|
190
|
+
router = open_api_3_schema.build_router(options)
|
162
191
|
validator = router.build_schema_validator(request)
|
163
192
|
|
164
193
|
params, _ = Committee::RequestUnpacker.new(
|
@@ -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
|
@@ -52,8 +57,8 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
52
57
|
operation_object.validate_request_params({"string" => 1}, HEADER, @validator_option)
|
53
58
|
}
|
54
59
|
|
55
|
-
|
56
|
-
|
60
|
+
assert_match(/expected string, but received Integer: 1/i, e.message)
|
61
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
57
62
|
end
|
58
63
|
|
59
64
|
it 'support put method' do
|
@@ -64,8 +69,8 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
64
69
|
operation_object.validate_request_params({"string" => 1}, HEADER, @validator_option)
|
65
70
|
}
|
66
71
|
|
67
|
-
|
68
|
-
|
72
|
+
assert_match(/expected string, but received Integer: 1/i, e.message)
|
73
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
69
74
|
end
|
70
75
|
|
71
76
|
it 'support patch method' do
|
@@ -77,6 +82,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
77
82
|
}
|
78
83
|
|
79
84
|
assert_match(/expected integer, but received String: str/i, e.message)
|
85
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
80
86
|
end
|
81
87
|
|
82
88
|
it 'unknown param' do
|
@@ -110,6 +116,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
110
116
|
}
|
111
117
|
|
112
118
|
assert_match(/missing required parameters: query_string/i, e.message)
|
119
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
113
120
|
end
|
114
121
|
|
115
122
|
it 'invalid type' do
|
@@ -121,8 +128,8 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
121
128
|
)
|
122
129
|
}
|
123
130
|
|
124
|
-
|
125
|
-
|
131
|
+
assert_match(/expected string, but received Integer: 1/i, e.message)
|
132
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
126
133
|
end
|
127
134
|
end
|
128
135
|
|
@@ -144,6 +151,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
144
151
|
}
|
145
152
|
|
146
153
|
assert_match(/expected integer, but received String: a/i, e.message)
|
154
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
@@ -72,6 +72,9 @@ describe Committee::SchemaValidator::OpenAPI3::RequestValidator do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def new_rack_app(options = {})
|
75
|
+
# TODO: delete when 5.0.0 released because default value changed
|
76
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
77
|
+
|
75
78
|
Rack::Builder.new {
|
76
79
|
use Committee::Middleware::RequestValidation, options
|
77
80
|
run lambda { |_|
|
@@ -12,7 +12,12 @@ describe Committee::SchemaValidator::OpenAPI3::ResponseValidator do
|
|
12
12
|
|
13
13
|
@path = '/validate'
|
14
14
|
@method = 'post'
|
15
|
-
|
15
|
+
|
16
|
+
# TODO: delete when 5.0.0 released because default value changed
|
17
|
+
options = {}
|
18
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
19
|
+
|
20
|
+
@validator_option = Committee::SchemaValidator::Option.new(options, open_api_3_schema, :open_api_3)
|
16
21
|
end
|
17
22
|
|
18
23
|
it "passes through a valid response" do
|
@@ -29,11 +34,12 @@ describe Committee::SchemaValidator::OpenAPI3::ResponseValidator do
|
|
29
34
|
call_response_validator
|
30
35
|
end
|
31
36
|
|
32
|
-
it "
|
37
|
+
it "raises InvalidResponse when a valid response with no registered body with strict option" do
|
33
38
|
@headers = { "Content-Type" => "application/xml" }
|
34
|
-
assert_raises(Committee::InvalidResponse) {
|
39
|
+
e = assert_raises(Committee::InvalidResponse) {
|
35
40
|
call_response_validator(true)
|
36
41
|
}
|
42
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
37
43
|
end
|
38
44
|
|
39
45
|
it "passes through a valid response with no Content-Type" do
|
@@ -41,11 +47,12 @@ describe Committee::SchemaValidator::OpenAPI3::ResponseValidator do
|
|
41
47
|
call_response_validator
|
42
48
|
end
|
43
49
|
|
44
|
-
it "
|
50
|
+
it "raises InvalidResponse when a valid response with no Content-Type headers with strict option" do
|
45
51
|
@headers = {}
|
46
|
-
assert_raises(Committee::InvalidResponse) {
|
52
|
+
e = assert_raises(Committee::InvalidResponse) {
|
47
53
|
call_response_validator(true)
|
48
54
|
}
|
55
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
49
56
|
end
|
50
57
|
|
51
58
|
it "passes through a valid list response" do
|