committee 4.4.0 → 5.0.0.beta1

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/committee/drivers/open_api_2/driver.rb +1 -1
  3. data/lib/committee/drivers/open_api_2/parameter_schema_builder.rb +1 -1
  4. data/lib/committee/drivers.rb +21 -9
  5. data/lib/committee/middleware/base.rb +5 -4
  6. data/lib/committee/middleware/request_validation.rb +1 -8
  7. data/lib/committee/middleware/response_validation.rb +13 -14
  8. data/lib/committee/request_unpacker.rb +1 -1
  9. data/lib/committee/schema_validator/hyper_schema/response_validator.rb +1 -1
  10. data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +32 -33
  11. data/lib/committee/schema_validator/open_api_3/request_validator.rb +2 -2
  12. data/lib/committee/schema_validator/open_api_3.rb +28 -15
  13. data/lib/committee/schema_validator/option.rb +5 -13
  14. data/lib/committee/test/methods.rb +2 -7
  15. data/lib/committee/version.rb +5 -0
  16. data/lib/committee.rb +9 -2
  17. data/test/committee_test.rb +28 -2
  18. data/test/drivers/open_api_3/driver_test.rb +1 -1
  19. data/test/drivers_test.rb +20 -7
  20. data/test/middleware/base_test.rb +6 -13
  21. data/test/middleware/request_validation_open_api_3_test.rb +117 -41
  22. data/test/middleware/request_validation_test.rb +1 -28
  23. data/test/middleware/response_validation_open_api_3_test.rb +46 -3
  24. data/test/middleware/response_validation_test.rb +6 -25
  25. data/test/schema_validator/hyper_schema/response_validator_test.rb +10 -0
  26. data/test/schema_validator/hyper_schema/string_params_coercer_test.rb +1 -1
  27. data/test/schema_validator/open_api_3/operation_wrapper_test.rb +55 -11
  28. data/test/schema_validator/open_api_3/request_validator_test.rb +10 -0
  29. data/test/schema_validator/open_api_3/response_validator_test.rb +14 -0
  30. data/test/test/methods_new_version_test.rb +1 -1
  31. data/test/test/methods_test.rb +11 -31
  32. data/test/test_helper.rb +11 -3
  33. metadata +14 -19
@@ -102,21 +102,14 @@ describe Committee::Middleware::Base do
102
102
  end
103
103
 
104
104
  describe 'initialize option' do
105
- it "schema_path option with hyper-schema" do
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)
108
- assert_kind_of Committee::Drivers::HyperSchema::Schema, b.instance_variable_get(:@schema)
105
+ it "accepts OpenAPI3 parser config of strict_reference_validation and raises" do
106
+ assert_raises(OpenAPIParser::MissingReferenceError) do
107
+ Committee::Middleware::Base.new(nil, schema_path: open_api_3_invalid_reference_path, strict_reference_validation: true)
108
+ end
109
109
  end
110
110
 
111
- it "schema_path option with OpenAPI2" do
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)
114
- assert_kind_of Committee::Drivers::OpenAPI2::Schema, b.instance_variable_get(:@schema)
115
- end
116
-
117
- it "schema_path option with OpenAPI3" do
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)
111
+ it "does not raise by default even with invalid reference OpenAPI3 specification" do
112
+ b = Committee::Middleware::Base.new(nil, schema_path: open_api_3_invalid_reference_path, strict_reference_validation: false)
120
113
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, b.instance_variable_get(:@schema)
121
114
  end
122
115
  end
@@ -34,12 +34,12 @@ describe Committee::Middleware::RequestValidation do
34
34
  params = { "datetime_string" => "2016-04-01T16:00:00.000+09:00" }
35
35
 
36
36
  check_parameter = lambda { |env|
37
- assert_equal DateTime, env['committee.query_hash']["datetime_string"].class
37
+ assert_equal DateTime, env['test.query_hash']["datetime_string"].class
38
38
  assert_equal String, env['rack.request.query_hash']["datetime_string"].class
39
39
  [200, {}, []]
40
40
  }
41
41
 
42
- @app = new_rack_app_with_lambda(check_parameter, schema: open_api_3_schema, coerce_date_times: true, query_hash_key: "committee.query_hash")
42
+ @app = new_rack_app_with_lambda(check_parameter, schema: open_api_3_schema, coerce_date_times: true, query_hash_key: "test.query_hash")
43
43
 
44
44
  get "/string_params_coercer", params
45
45
  assert_equal 200, last_response.status
@@ -49,7 +49,7 @@ describe Committee::Middleware::RequestValidation do
49
49
  params = { "datetime_string" => "2016-04-01T16:00:00.000+09:00" }
50
50
 
51
51
  check_parameter = lambda { |env|
52
- assert_equal nil, env['committee.query_hash']
52
+ assert_nil env['committee.query_hash']
53
53
  assert_equal DateTime, env['rack.request.query_hash']["datetime_string"].class
54
54
  [200, {}, []]
55
55
  }
@@ -65,7 +65,7 @@ describe Committee::Middleware::RequestValidation do
65
65
 
66
66
  @app = new_rack_app(schema: open_api_3_schema, allow_get_body: true)
67
67
 
68
- get "/get_endpoint_with_requered_parameter", { no_problem: true }, { input: params.to_json }
68
+ get "/get_endpoint_with_required_parameter", { no_problem: true }, { input: params.to_json }
69
69
  assert_equal 200, last_response.status
70
70
  end
71
71
 
@@ -74,7 +74,7 @@ describe Committee::Middleware::RequestValidation do
74
74
 
75
75
  @app = new_rack_app(schema: open_api_3_schema, allow_get_body: false)
76
76
 
77
- get "/get_endpoint_with_requered_parameter", { no_problem: true }, { input: params.to_json }
77
+ get "/get_endpoint_with_required_parameter", { no_problem: true }, { input: params.to_json }
78
78
  assert_equal 400, last_response.status
79
79
  end
80
80
 
@@ -170,8 +170,7 @@ describe Committee::Middleware::RequestValidation do
170
170
  }
171
171
 
172
172
  check_parameter = lambda { |env|
173
- # hash = env["committee.query_hash"] # 5.0.x-
174
- hash = env["rack.request.query_hash"]
173
+ hash = env["committee.query_hash"]
175
174
  assert_equal DateTime, hash['nested_array'].first['update_time'].class
176
175
  assert_equal 1, hash['nested_array'].first['per_page']
177
176
 
@@ -377,8 +376,7 @@ describe Committee::Middleware::RequestValidation do
377
376
 
378
377
  it "passes through a valid request for OpenAPI3" do
379
378
  check_parameter = lambda { |env|
380
- # assert_equal 3, env['committee.query_hash']['limit'] #5.0.x-
381
- assert_equal 3, env['rack.request.query_hash']['limit'] #5.0.x-
379
+ assert_equal 3, env['committee.query_hash']['limit'] #5.0.x-
382
380
  [200, {}, []]
383
381
  }
384
382
 
@@ -412,43 +410,121 @@ describe Committee::Middleware::RequestValidation do
412
410
  get "/coerce_path_params/1"
413
411
  end
414
412
 
415
- it "corce string and save path hash" do
416
- @app = new_rack_app_with_lambda(lambda do |env|
417
- assert_equal env['committee.params']['integer'], 21
418
- assert_equal env['committee.params'][:integer], 21
419
- assert_equal env['committee.path_hash']['integer'], 21
420
- assert_equal env['committee.path_hash'][:integer], 21
421
- [204, {}, []]
422
- end, schema: open_api_3_schema)
413
+ describe "overwrite same parameter (old rule)" do
414
+ # (high priority) path_hash_key -> request_body_hash -> query_param
415
+ it "set query parameter to committee.params and query hash" do
416
+ @app = new_rack_app_with_lambda(lambda do |env|
417
+ assert_equal env['committee.params']['integer'], 42
418
+ assert_equal env['committee.params'][:integer], 42
419
+ assert_equal env['committee.query_hash']['integer'], 42
420
+ #assert_equal env['rack.request.query_hash'][:integer], 42 # this isn't hash indifferent hash because we use rack.request.query_hash
421
+ [204, {}, []]
422
+ end, schema: open_api_3_schema, parameter_overwite_by_rails_rule: false)
423
+
424
+ header "Content-Type", "application/json"
425
+ post '/overwrite_same_parameter?integer=42'
426
+ assert_equal 204, last_response.status
427
+ end
423
428
 
424
- header "Content-Type", "application/json"
425
- post '/parameter_option_test/21'
426
- assert_equal 204, last_response.status
429
+ it "request body precedence over query parameter" do
430
+ @app = new_rack_app_with_lambda(lambda do |env|
431
+ assert_equal env['committee.params']['integer'], 21
432
+ assert_equal env['committee.params'][:integer], 21
433
+ assert_equal env['committee.request_body_hash']['integer'], 21
434
+ assert_equal env['committee.request_body_hash'][:integer], 21
435
+ assert_equal env['committee.query_hash']['integer'], 42
436
+ [204, {}, []]
437
+ end, schema: open_api_3_schema, parameter_overwite_by_rails_rule: false)
438
+
439
+ params = {integer: 21}
440
+
441
+ header "Content-Type", "application/json"
442
+ post '/overwrite_same_parameter?integer=42', JSON.generate(params)
443
+ assert_equal 204, last_response.status
444
+ end
445
+
446
+ it "path parameter precedence over request body" do
447
+ @app = new_rack_app_with_lambda(lambda do |env|
448
+ assert_equal env['committee.params']['integer'], 84
449
+ assert_equal env['committee.params'][:integer], 84
450
+ assert_equal env['committee.path_hash']['integer'], 84
451
+ assert_equal env['committee.path_hash'][:integer], 84
452
+ assert_equal env['committee.request_body_hash']['integer'], 21
453
+ assert_equal env['committee.request_body_hash'][:integer], 21
454
+ assert_equal env['committee.query_hash']['integer'], 84 # we can't use query_parameter :(
455
+ #assert_equal env['rack.request.query_hash'][:integer], 21 # this isn't hash indifferent hash because we use rack.request.query_hash
456
+ [204, {}, []]
457
+ end, schema: open_api_3_schema, parameter_overwite_by_rails_rule: false)
458
+
459
+ params = {integer: 21}
460
+
461
+ header "Content-Type", "application/json"
462
+ post '/overwrite_same_parameter/84?integer=42', JSON.generate(params)
463
+ assert_equal 204, last_response.status
464
+ end
427
465
  end
428
466
 
429
- it "corce string and save request body hash" do
430
- @app = new_rack_app_with_lambda(lambda do |env|
431
- assert_equal env['committee.params']['integer'], 21 # use path parameter
432
- assert_equal env['committee.params'][:integer], 21
433
- assert_equal env['committee.request_body_hash']['integer'], 42
434
- assert_equal env['committee.request_body_hash'][:integer], 42
435
- [204, {}, []]
436
- end, schema: open_api_3_schema)
467
+ describe "overwrite same parameter (new rule and seme to Rails)" do
468
+ # (high priority) path_hash_key -> query_param -> request_body_hash
469
+ it "set request body to committee.params and query hash" do
470
+ @app = new_rack_app_with_lambda(lambda do |env|
471
+ assert_equal env['committee.params']['integer'], 21
472
+ assert_equal env['committee.params'][:integer], 21
473
+ assert_equal env['committee.request_body_hash']['integer'], 21
474
+ assert_equal env['committee.request_body_hash'][:integer], 21
475
+ [204, {}, []]
476
+ end, schema: open_api_3_schema)
437
477
 
438
- params = {integer: 42}
478
+ params = {integer: 21}
439
479
 
440
- header "Content-Type", "application/json"
441
- post '/parameter_option_test/21', JSON.generate(params)
442
- assert_equal 204, last_response.status
480
+ header "Content-Type", "application/json"
481
+ post '/overwrite_same_parameter', JSON.generate(params)
482
+ assert_equal 204, last_response.status
483
+ end
484
+
485
+ it "query parameter precedence over request body" do
486
+ @app = new_rack_app_with_lambda(lambda do |env|
487
+ assert_equal env['committee.params']['integer'], 42
488
+ assert_equal env['committee.params'][:integer], 42
489
+ assert_equal env['committee.request_body_hash']['integer'], 21
490
+ assert_equal env['committee.request_body_hash'][:integer], 21
491
+ assert_equal env['committee.query_hash']['integer'], 42
492
+ [204, {}, []]
493
+ end, schema: open_api_3_schema)
494
+
495
+ params = {integer: 21}
496
+
497
+ header "Content-Type", "application/json"
498
+ post '/overwrite_same_parameter?integer=42', JSON.generate(params)
499
+ assert_equal 204, last_response.status
500
+ end
501
+
502
+ it "path path parameter precedence over query parameter" do
503
+ @app = new_rack_app_with_lambda(lambda do |env|
504
+ assert_equal env['committee.params']['integer'], 84
505
+ assert_equal env['committee.params'][:integer], 84
506
+ assert_equal env['committee.request_body_hash']['integer'], 21
507
+ assert_equal env['committee.request_body_hash'][:integer], 21
508
+ assert_equal env['committee.query_hash']['integer'], 84 # we can't use query_parameter :(
509
+ assert_equal env['committee.path_hash']['integer'], 84
510
+ assert_equal env['committee.path_hash'][:integer], 84
511
+ [204, {}, []]
512
+ end, schema: open_api_3_schema)
513
+
514
+ params = {integer: 21}
515
+
516
+ header "Content-Type", "application/json"
517
+ post '/overwrite_same_parameter/84?integer=42', JSON.generate(params)
518
+ assert_equal 204, last_response.status
519
+ end
443
520
  end
444
521
 
445
522
  it "unpacker test" do
446
523
  @app = new_rack_app_with_lambda(lambda do |env|
447
- assert_equal env['committee.params']['integer'], 42
448
- assert_equal env['committee.params'][:integer], 42
449
- # overwrite by request body...
450
- assert_equal env['rack.request.query_hash']['integer'], 42
451
- # assert_equal env['rack.request.query_hash'][:integer], 42
524
+ assert_equal '21', env['committee.params']['integer'] # query parameter has precedence
525
+ assert_equal '21', env['committee.params'][:integer]
526
+ assert_equal '21', env['rack.request.query_hash']['integer']
527
+ assert_equal 42, env['committee.request_body_hash']['integer']
452
528
  [204, {}, []]
453
529
  end, schema: open_api_3_schema, raise: true)
454
530
 
@@ -461,11 +537,11 @@ describe Committee::Middleware::RequestValidation do
461
537
  @app = new_rack_app(schema: open_api_3_schema)
462
538
 
463
539
  e = assert_raises(RuntimeError) {
464
- head "/characters", {}
540
+ custom_request('TRACE', "/characters")
465
541
  }
466
542
 
467
- assert_equal 'Committee OpenAPI3 not support head method', e.message
468
- end
543
+ assert_equal 'Committee OpenAPI3 not support trace method', e.message
544
+ end
469
545
 
470
546
  describe 'check header' do
471
547
  [
@@ -482,7 +558,7 @@ describe Committee::Middleware::RequestValidation do
482
558
  value = h[:value]
483
559
  expected = h[:expected]
484
560
  describe "when #{check_header}" do
485
- %w(get post put patch delete).each do |method|
561
+ %w(get post put patch delete options).each do |method|
486
562
  describe method do
487
563
  describe description do
488
564
  it (expected[:error].nil? ? 'should pass' : 'should fail') do
@@ -306,21 +306,6 @@ describe Committee::Middleware::RequestValidation do
306
306
  assert_equal 200, last_response.status
307
307
  end
308
308
 
309
- it "calls error_handler (has a arg) when request is invalid" do
310
- called_err = nil
311
- pr = ->(e) { called_err = e }
312
- @app = new_rack_app(schema: hyper_schema, error_handler: pr)
313
- header "Content-Type", "application/json"
314
- params = {
315
- "name" => 1
316
- }
317
- _, err = capture_io do
318
- post "/apps", JSON.generate(params)
319
- end
320
- assert_kind_of Committee::InvalidRequest, called_err
321
- assert_match(/\[DEPRECATION\]/i, err)
322
- end
323
-
324
309
  it "calls error_handler (has two args) when request is invalid" do
325
310
  called_err = nil
326
311
  pr = ->(e, _env) { called_err = e }
@@ -341,18 +326,6 @@ describe Committee::Middleware::RequestValidation do
341
326
  assert_match(/valid json/i, last_response.body)
342
327
  end
343
328
 
344
- it "calls error_handler (has a arg) when it rescues JSON errors" do
345
- called_err = nil
346
- pr = ->(e) { called_err = e }
347
- @app = new_rack_app(schema: hyper_schema, error_handler: pr)
348
- header "Content-Type", "application/json"
349
- _, err = capture_io do
350
- post "/apps", "{x:y}"
351
- end
352
- assert_kind_of JSON::ParserError, called_err
353
- assert_match(/\[DEPRECATION\]/i, err)
354
- end
355
-
356
329
  it "calls error_handler (has two args) when it rescues JSON errors" do
357
330
  called_err = nil
358
331
  pr = ->(e, _env) { called_err = e }
@@ -435,7 +408,7 @@ describe Committee::Middleware::RequestValidation do
435
408
  assert_equal 200, last_response.status
436
409
  end
437
410
 
438
- it "corce form params" do
411
+ it "coerce form params" do
439
412
  check_parameter = lambda { |env|
440
413
  assert_equal 3, env['committee.params']['age']
441
414
  assert_equal 3, env['committee.request_body_hash']['age']
@@ -64,6 +64,12 @@ describe Committee::Middleware::ResponseValidation do
64
64
  assert_equal 204, last_response.status
65
65
  end
66
66
 
67
+ it "passes through a 304 (not modified) response" do
68
+ @app = new_response_rack("", {}, {schema: open_api_3_schema}, {status: 304})
69
+ post "/validate"
70
+ assert_equal 304, last_response.status
71
+ end
72
+
67
73
  it "passes through a valid response with prefix" do
68
74
  @app = new_response_rack(JSON.generate(CHARACTERS_RESPONSE), {}, schema: open_api_3_schema, prefix: "/v1")
69
75
  get "/v1/characters"
@@ -86,7 +92,7 @@ describe Committee::Middleware::ResponseValidation do
86
92
  end
87
93
  end
88
94
 
89
- it "not parameter requset" do
95
+ it "not parameter request" do
90
96
  @app = new_response_rack({integer: '1'}.to_json, {}, schema: open_api_3_schema, raise: true)
91
97
 
92
98
  assert_raises(Committee::InvalidResponse) do
@@ -136,7 +142,7 @@ describe Committee::Middleware::ResponseValidation do
136
142
  header = h[:header]
137
143
  expected = h[:expected]
138
144
  describe "when #{check_header}" do
139
- %w(get post put patch delete).each do |method|
145
+ %w(get post put patch delete options).each do |method|
140
146
  describe method do
141
147
  describe description do
142
148
  if expected[:error].nil?
@@ -228,6 +234,42 @@ describe Committee::Middleware::ResponseValidation do
228
234
  end
229
235
  end
230
236
 
237
+ it "strict and invalid status" do
238
+ @app = new_response_rack(JSON.generate(CHARACTERS_RESPONSE), {}, {schema: open_api_3_schema, strict: true}, {status: 201})
239
+ get "/characters"
240
+ assert_equal 500, last_response.status
241
+ end
242
+
243
+ it "strict and invalid status with raise" do
244
+ @app = new_response_rack(JSON.generate(CHARACTERS_RESPONSE), {}, {schema: open_api_3_schema, strict: true, raise: true}, {status: 201})
245
+
246
+ assert_raises(Committee::InvalidResponse) do
247
+ get "/characters"
248
+ end
249
+ end
250
+
251
+ it "strict and invalid content type" do
252
+ @app = new_response_rack("abc",
253
+ {},
254
+ {schema: open_api_3_schema, strict: true},
255
+ {content_type: 'application/text'}
256
+ )
257
+ get "/characters"
258
+ assert_equal 500, last_response.status
259
+ end
260
+
261
+ it "strict and invalid content type with raise" do
262
+ @app = new_response_rack("abc",
263
+ {},
264
+ {schema: open_api_3_schema, strict: true, raise: true},
265
+ {content_type: 'application/text'}
266
+ )
267
+
268
+ assert_raises(Committee::InvalidResponse) do
269
+ get "/characters"
270
+ end
271
+ end
272
+
231
273
  private
232
274
 
233
275
  def new_response_rack(response, headers = {}, options = {}, rack_options = {})
@@ -235,8 +277,9 @@ describe Committee::Middleware::ResponseValidation do
235
277
  options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
236
278
 
237
279
  status = rack_options[:status] || 200
280
+ content_type = rack_options[:content_type] || "application/json"
238
281
  headers = {
239
- "Content-Type" => "application/json"
282
+ "Content-Type" => content_type
240
283
  }.merge(headers)
241
284
  Rack::Builder.new {
242
285
  use Committee::Middleware::ResponseValidation, options
@@ -85,6 +85,12 @@ describe Committee::Middleware::ResponseValidation do
85
85
  assert_equal 204, last_response.status
86
86
  end
87
87
 
88
+ it "passes through a 304 (not modified) response" do
89
+ @app = new_rack_app("", {}, app_status: 304, schema: hyper_schema)
90
+ get "/apps"
91
+ assert_equal 304, last_response.status
92
+ end
93
+
88
94
  it "skip validation when 4xx" do
89
95
  @app = new_rack_app("[{x:y}]", {}, schema: hyper_schema, validate_success_only: true, app_status: 400)
90
96
  get "/apps"
@@ -99,17 +105,6 @@ describe Committee::Middleware::ResponseValidation do
99
105
  assert_match(/valid json/i, last_response.body)
100
106
  end
101
107
 
102
- it "calls error_handler (has a arg) when it rescues JSON errors" do
103
- called_err = nil
104
- pr = ->(e) { called_err = e }
105
- @app = new_rack_app("[{x:y}]", {}, schema: hyper_schema, error_handler: pr)
106
- _, err = capture_io do
107
- get "/apps"
108
- end
109
- assert_kind_of JSON::ParserError, called_err
110
- assert_match(/\[DEPRECATION\]/i, err)
111
- end
112
-
113
108
  it "calls error_handler (has two args) when it rescues JSON errors" do
114
109
  called_err = nil
115
110
  pr = ->(e, _env) { called_err = e }
@@ -132,20 +127,6 @@ describe Committee::Middleware::ResponseValidation do
132
127
  end
133
128
  end
134
129
 
135
- it "calls error_handler (has a arg) when it rescues JSON errors" do
136
- called_err = nil
137
- pr = ->(e) { called_err = e }
138
- @app = new_rack_app("[{x:y}]", {}, raise: true, schema: hyper_schema, error_handler: pr)
139
- assert_raises(Committee::InvalidResponse) do
140
- _, err = capture_io do
141
- get "/apps"
142
- end
143
-
144
- assert_kind_of JSON::ParserError, called_err
145
- assert_match(/\[DEPRECATION\]/i, err)
146
- end
147
- end
148
-
149
130
  it "calls error_handler (has two args) when it rescues JSON errors" do
150
131
  called_err = nil
151
132
  pr = ->(e, _env) { called_err = e }
@@ -38,6 +38,11 @@ describe Committee::SchemaValidator::HyperSchema::ResponseValidator do
38
38
  call
39
39
  end
40
40
 
41
+ it "passes through a 304 Not Modified response" do
42
+ @status, @headers, @data = 304, {}, nil
43
+ call
44
+ end
45
+
41
46
  it "passes through a valid list response for for rel instances links" do
42
47
  @link = @list_link
43
48
 
@@ -91,6 +96,11 @@ describe Committee::SchemaValidator::HyperSchema::ResponseValidator do
91
96
  call
92
97
  end
93
98
 
99
+ it "allows no Content-Type for 304 Not Modified" do
100
+ @status, @headers = 304, {}
101
+ call
102
+ end
103
+
94
104
  it "raises errors generated by json_schema" do
95
105
  @data.merge!("name" => "%@!")
96
106
  e = assert_raises(Committee::InvalidResponse) { call }
@@ -11,7 +11,7 @@ describe Committee::SchemaValidator::HyperSchema::StringParamsCoercer do
11
11
  end
12
12
 
13
13
  it "doesn't coerce params not in the schema" do
14
- check_convert("onwer", "admin", "admin")
14
+ check_convert("owner", "admin", "admin")
15
15
  end
16
16
 
17
17
  it "skips values for string param" do
@@ -32,12 +32,15 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
32
32
  ]
33
33
 
34
34
  it 'correct data' do
35
- operation_object.validate_request_params(SCHEMA_PROPERTIES_PAIR.to_h, HEADER, @validator_option)
35
+ operation_object.validate_request_params({}, {}, SCHEMA_PROPERTIES_PAIR.to_h, HEADER, @validator_option)
36
36
  assert true
37
37
  end
38
38
 
39
39
  it 'correct object data' do
40
- operation_object.validate_request_params({
40
+ operation_object.validate_request_params(
41
+ {},
42
+ {},
43
+ {
41
44
  "object_1" =>
42
45
  {
43
46
  "string_1" => nil,
@@ -54,7 +57,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
54
57
 
55
58
  it 'invalid params' do
56
59
  e = assert_raises(Committee::InvalidRequest) {
57
- operation_object.validate_request_params({"string" => 1}, HEADER, @validator_option)
60
+ operation_object.validate_request_params({}, {}, {"string" => 1}, HEADER, @validator_option)
58
61
  }
59
62
 
60
63
  assert_match(/expected string, but received Integer: 1/i, e.message)
@@ -63,10 +66,10 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
63
66
 
64
67
  it 'support put method' do
65
68
  @method = "put"
66
- operation_object.validate_request_params({"string" => "str"}, HEADER, @validator_option)
69
+ operation_object.validate_request_params({}, {}, {"string" => "str"}, HEADER, @validator_option)
67
70
 
68
71
  e = assert_raises(Committee::InvalidRequest) {
69
- operation_object.validate_request_params({"string" => 1}, HEADER, @validator_option)
72
+ operation_object.validate_request_params({}, {}, {"string" => 1}, HEADER, @validator_option)
70
73
  }
71
74
 
72
75
  assert_match(/expected string, but received Integer: 1/i, e.message)
@@ -75,10 +78,10 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
75
78
 
76
79
  it 'support patch method' do
77
80
  @method = "patch"
78
- operation_object.validate_request_params({"integer" => 1}, HEADER, @validator_option)
81
+ operation_object.validate_request_params({}, {}, {"integer" => 1}, HEADER, @validator_option)
79
82
 
80
83
  e = assert_raises(Committee::InvalidRequest) {
81
- operation_object.validate_request_params({"integer" => "str"}, HEADER, @validator_option)
84
+ operation_object.validate_request_params({}, {}, {"integer" => "str"}, HEADER, @validator_option)
82
85
  }
83
86
 
84
87
  assert_match(/expected integer, but received String: "str"/i, e.message)
@@ -86,7 +89,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
86
89
  end
87
90
 
88
91
  it 'unknown param' do
89
- operation_object.validate_request_params({"unknown" => 1}, HEADER, @validator_option)
92
+ operation_object.validate_request_params({}, {}, {"unknown" => 1}, HEADER, @validator_option)
90
93
  end
91
94
 
92
95
  describe 'support get method' do
@@ -96,13 +99,17 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
96
99
 
97
100
  it 'correct' do
98
101
  operation_object.validate_request_params(
102
+ {},
99
103
  {"query_string" => "query", "query_integer_list" => [1, 2]},
104
+ {},
100
105
  HEADER,
101
106
  @validator_option
102
107
  )
103
108
 
104
109
  operation_object.validate_request_params(
110
+ {},
105
111
  {"query_string" => "query", "query_integer_list" => [1, 2], "optional_integer" => 1},
112
+ {},
106
113
  HEADER,
107
114
  @validator_option
108
115
  )
@@ -112,7 +119,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
112
119
 
113
120
  it 'not exist required' do
114
121
  e = assert_raises(Committee::InvalidRequest) {
115
- operation_object.validate_request_params({"query_integer_list" => [1, 2]}, HEADER, @validator_option)
122
+ operation_object.validate_request_params({}, {"query_integer_list" => [1, 2]}, {}, HEADER, @validator_option)
116
123
  }
117
124
 
118
125
  assert_match(/missing required parameters: query_string/i, e.message)
@@ -122,7 +129,9 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
122
129
  it 'invalid type' do
123
130
  e = assert_raises(Committee::InvalidRequest) {
124
131
  operation_object.validate_request_params(
132
+ {},
125
133
  {"query_string" => 1, "query_integer_list" => [1, 2], "optional_integer" => 1},
134
+ {},
126
135
  HEADER,
127
136
  @validator_option
128
137
  )
@@ -140,14 +149,14 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
140
149
  end
141
150
 
142
151
  it 'correct' do
143
- operation_object.validate_request_params({"limit" => "1"}, HEADER, @validator_option)
152
+ operation_object.validate_request_params({}, {"limit" => "1"}, {}, HEADER, @validator_option)
144
153
 
145
154
  assert true
146
155
  end
147
156
 
148
157
  it 'invalid type' do
149
158
  e = assert_raises(Committee::InvalidRequest) {
150
- operation_object.validate_request_params({"limit" => "a"}, HEADER, @validator_option)
159
+ operation_object.validate_request_params({}, {"limit" => "a"}, {}, HEADER, @validator_option)
151
160
  }
152
161
 
153
162
  assert_match(/expected integer, but received String: "a"/i, e.message)
@@ -155,6 +164,41 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
155
164
  end
156
165
  end
157
166
 
167
+ describe 'support head method' do
168
+ before do
169
+ @path = '/characters'
170
+ @method = 'head'
171
+ end
172
+
173
+ it 'correct' do
174
+ operation_object.validate_request_params({}, {"limit" => "1"}, {}, HEADER, @validator_option)
175
+
176
+ assert true
177
+ end
178
+
179
+ it 'invalid type' do
180
+ e = assert_raises(Committee::InvalidRequest) {
181
+ operation_object.validate_request_params({}, {"limit" => "a"}, {}, HEADER, @validator_option)
182
+ }
183
+
184
+ assert_match(/expected integer, but received String: "a"/i, e.message)
185
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
186
+ end
187
+ end
188
+
189
+ it 'support options method' do
190
+ @method = "options"
191
+ operation_object.validate_request_params({}, {}, {"integer" => 1}, HEADER, @validator_option)
192
+
193
+ e = assert_raises(Committee::InvalidRequest) {
194
+ operation_object.validate_request_params({}, {}, {"integer" => "str"}, HEADER, @validator_option)
195
+ }
196
+
197
+ assert_match(/expected integer, but received String: "str"/i, e.message)
198
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
199
+ end
200
+
201
+
158
202
  describe '#content_types' do
159
203
  it 'returns supported content types' do
160
204
  @path = '/validate_content_types'
@@ -71,6 +71,16 @@ describe Committee::SchemaValidator::OpenAPI3::RequestValidator do
71
71
  assert_equal 200, last_response.status
72
72
  end
73
73
 
74
+ it "does not mix up parameters and requestBody" do
75
+ @app = new_rack_app(check_content_type: true, schema: open_api_3_schema)
76
+ params = {
77
+ "last_name" => "Skywalker"
78
+ }
79
+ header "Content-Type", "application/json"
80
+ post "/additional_properties?first_name=Luke", JSON.generate(params)
81
+ assert_equal 200, last_response.status
82
+ end
83
+
74
84
  def new_rack_app(options = {})
75
85
  # TODO: delete when 5.0.0 released because default value changed
76
86
  options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil