committee 3.0.0.alpha → 3.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/lib/committee/drivers/hyper_schema.rb +8 -2
  3. data/lib/committee/drivers/open_api_2.rb +7 -2
  4. data/lib/committee/drivers/open_api_3.rb +9 -4
  5. data/lib/committee/drivers.rb +46 -0
  6. data/lib/committee/middleware/base.rb +9 -11
  7. data/lib/committee/middleware/response_validation.rb +8 -5
  8. data/lib/committee/request_unpacker.rb +4 -1
  9. data/lib/committee/{parameter_coercer.rb → schema_validator/hyper_schema/parameter_coercer.rb} +1 -2
  10. data/lib/committee/schema_validator/hyper_schema/request_validator.rb +1 -5
  11. data/lib/committee/schema_validator/hyper_schema/response_validator.rb +3 -9
  12. data/lib/committee/schema_validator/hyper_schema/router.rb +1 -1
  13. data/lib/committee/schema_validator/hyper_schema.rb +5 -4
  14. data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +46 -19
  15. data/lib/committee/schema_validator/open_api_3/request_validator.rb +14 -4
  16. data/lib/committee/schema_validator/open_api_3/response_validator.rb +9 -20
  17. data/lib/committee/schema_validator/open_api_3/router.rb +15 -4
  18. data/lib/committee/schema_validator/open_api_3.rb +14 -5
  19. data/lib/committee/schema_validator/option.rb +2 -5
  20. data/lib/committee/schema_validator/schema_validator.rb +15 -0
  21. data/lib/committee/test/methods.rb +3 -5
  22. data/lib/committee.rb +3 -1
  23. data/test/drivers/open_api_3_test.rb +2 -1
  24. data/test/drivers_test.rb +69 -0
  25. data/test/middleware/base_test.rb +20 -5
  26. data/test/middleware/request_validation_open_api_3_test.rb +136 -259
  27. data/test/middleware/request_validation_test.rb +18 -3
  28. data/test/middleware/response_validation_open_api_3_test.rb +83 -16
  29. data/test/middleware/response_validation_test.rb +19 -7
  30. data/test/middleware/stub_test.rb +1 -1
  31. data/test/{parameter_coercer_test.rb → schema_validator/hyper_schema/parameter_coercer_test.rb} +3 -3
  32. data/test/schema_validator/hyper_schema/router_test.rb +6 -0
  33. data/test/schema_validator/open_api_3/operation_wrapper_test.rb +29 -13
  34. data/test/schema_validator/open_api_3/request_validator_test.rb +31 -132
  35. data/test/schema_validator/open_api_3/response_validator_test.rb +19 -5
  36. data/test/test/methods_new_version_test.rb +19 -3
  37. data/test/test/methods_test.rb +15 -8
  38. data/test/test_helper.rb +15 -16
  39. metadata +8 -7
@@ -7,53 +7,8 @@ describe Committee::Middleware::RequestValidation do
7
7
  @app
8
8
  end
9
9
 
10
- ARRAY_PROPERTY = [
11
- {
12
- "update_time" => "2016-04-01T16:00:00.000+09:00",
13
- "per_page" => 1,
14
- "nested_coercer_object" => {
15
- "update_time" => "2016-04-01T16:00:00.000+09:00",
16
- "threshold" => 1.5
17
- },
18
- "nested_no_coercer_object" => {
19
- "per_page" => 1,
20
- "threshold" => 1.5
21
- },
22
- "nested_coercer_array" => [
23
- {
24
- "update_time" => "2016-04-01T16:00:00.000+09:00",
25
- "threshold" => 1.5
26
- }
27
- ],
28
- "nested_no_coercer_array" => [
29
- {
30
- "per_page" => 1,
31
- "threshold" => 1.5
32
- }
33
- ],
34
- "integer_array" => [
35
- 1, 2, 3
36
- ],
37
- "datetime_array" => [
38
- "2016-04-01T16:00:00.000+09:00",
39
- "2016-04-01T17:00:00.000+09:00",
40
- "2016-04-01T18:00:00.000+09:00"
41
- ]
42
- },
43
- {
44
- "update_time" => "2016-04-01T16:00:00.000+09:00",
45
- "per_page" => 1,
46
- "threshold" => 1.5
47
- },
48
- {
49
- "threshold" => 1.5,
50
- "per_page" => 1
51
- }
52
- ]
53
-
54
-
55
10
  it "OpenAPI3 pass through a valid request" do
56
- @app = new_rack_app(open_api_3: open_api_3_schema)
11
+ @app = new_rack_app(schema: open_api_3_schema)
57
12
  params = {
58
13
  "string_post_1" => "cloudnasium"
59
14
  }
@@ -68,7 +23,7 @@ describe Committee::Middleware::RequestValidation do
68
23
  [200, {integer: 1}, []]
69
24
  }
70
25
 
71
- @app = new_rack_app_with_lambda(check_parameter_string, open_api_3: open_api_3_schema)
26
+ @app = new_rack_app_with_lambda(check_parameter_string, schema: open_api_3_schema)
72
27
 
73
28
  put "/validate_no_parameter", {no_schema: 'no'}
74
29
  end
@@ -81,7 +36,7 @@ describe Committee::Middleware::RequestValidation do
81
36
  [200, {}, []]
82
37
  }
83
38
 
84
- @app = new_rack_app_with_lambda(check_parameter, open_api_3: open_api_3_schema, coerce_date_times: true)
39
+ @app = new_rack_app_with_lambda(check_parameter, schema: open_api_3_schema, coerce_date_times: true)
85
40
 
86
41
  get "/string_params_coercer", params
87
42
  assert_equal 200, last_response.status
@@ -132,26 +87,24 @@ describe Committee::Middleware::RequestValidation do
132
87
  [200, {}, []]
133
88
  }
134
89
 
135
- @app = new_rack_app_with_lambda(check_parameter, open_api_3: open_api_3_schema, coerce_date_times: true, coerce_recursive: true)
90
+ @app = new_rack_app_with_lambda(check_parameter, schema: open_api_3_schema, coerce_date_times: true, coerce_recursive: true)
136
91
 
137
- post "/string_params_coercer", params
92
+ header "Content-Type", "application/json"
93
+ post "/string_params_coercer", JSON.generate(params)
138
94
 
139
95
  assert_equal 200, last_response.status
140
96
  end
141
97
 
142
- # TODO: support date-time object format check
143
- =begin
144
98
  it "passes given an invalid datetime string with coerce_date_times enabled" do
145
- @app = new_rack_app(open_api_3: open_api_3_schema, coerce_date_times: true)
99
+ @app = new_rack_app(schema: open_api_3_schema, coerce_date_times: true)
146
100
  params = {
147
101
  "datetime_string" => "invalid_datetime_format"
148
102
  }
149
- get "/string_params_coercer", JSON.generate(params)
103
+ get "/string_params_coercer", params
150
104
 
151
105
  assert_equal 400, last_response.status
152
- assert_match(/invalid request/i, last_response.body)
106
+ assert_match(/invalid_datetime/i, last_response.body)
153
107
  end
154
- =end
155
108
 
156
109
  it "passes a nested object with recursive option" do
157
110
  params = {
@@ -175,136 +128,84 @@ describe Committee::Middleware::RequestValidation do
175
128
  coerce_query_params: true,
176
129
  coerce_recursive: true,
177
130
  coerce_date_times: true,
178
- open_api_3: open_api_3_schema)
131
+ schema: open_api_3_schema)
179
132
 
180
133
  get "/string_params_coercer", params
181
134
 
182
135
  assert_equal 200, last_response.status
183
136
  end
184
137
 
185
- =begin
186
- it "passes a nested object with coerce_recursive default(true)" do
187
- key_name = "update_time"
188
- params = {
189
- key_name => "2016-04-01T16:00:00.000+09:00",
190
- "query" => "cloudnasium",
191
- "array_property" => ARRAY_PROPERTY
192
- }
193
-
194
- @app = new_rack_app(coerce_query_params: true, coerce_date_times: true, schema: hyper_schema)
195
-
196
- get "/search/apps", params
197
- assert_equal 200, last_response.status # schema expect integer but we don't convert string to integer, so 400
198
- end
199
-
200
- it "passes given a nested datetime and with coerce_recursive=true and coerce_date_times=true on POST endpoint" do
201
- key_name = "update_time"
202
- params = {
203
- key_name => "2016-04-01T16:00:00.000+09:00",
204
- "array_property" => ARRAY_PROPERTY
205
- }
206
-
207
- check_parameter = lambda { |env|
208
- hash = env['committee.params']
209
- assert_equal DateTime, hash['array_property'].first['update_time'].class
210
- assert_equal 1, hash['array_property'].first['per_page']
211
- assert_equal DateTime, hash['array_property'].first['nested_coercer_object']['update_time'].class
212
- assert_equal 1, hash['array_property'].first['nested_no_coercer_object']['per_page']
213
- assert_equal 2, hash['array_property'].first['integer_array'][1]
214
- assert_equal DateTime, hash['array_property'].first['datetime_array'][0].class
215
- assert_equal DateTime, env['committee.params'][key_name].class
216
- [200, {}, []]
217
- }
218
-
219
- @app = new_rack_app_with_lambda(check_parameter, coerce_date_times: true, coerce_recursive: true, schema: hyper_schema)
220
-
221
- header "Content-Type", "application/json"
222
- post "/apps", JSON.generate(params)
223
- assert_equal 200, last_response.status
224
- end
225
-
226
138
  it "passes given a nested datetime and with coerce_recursive=true and coerce_date_times=true on POST endpoint" do
227
- key_name = "update_time"
228
139
  params = {
229
- key_name => "2016-04-01T16:00:00.000+09:00",
230
- "array_property" => ARRAY_PROPERTY
231
- }
232
-
233
- check_parameter = lambda { |env|
234
- hash = env['committee.params']
235
- assert_equal String, hash['array_property'].first['update_time'].class
236
- assert_equal 1, hash['array_property'].first['per_page']
237
- assert_equal String, hash['array_property'].first['nested_coercer_object']['update_time'].class
238
- assert_equal 1, hash['array_property'].first['nested_no_coercer_object']['per_page']
239
- assert_equal 2, hash['array_property'].first['integer_array'][1]
240
- assert_equal String, hash['array_property'].first['datetime_array'][0].class
241
- assert_equal String, env['committee.params'][key_name].class
242
- [200, {}, []]
243
- }
244
-
245
- @app = new_rack_app_with_lambda(check_parameter, schema: hyper_schema)
246
-
247
- header "Content-Type", "application/json"
248
- post "/apps", JSON.generate(params)
249
- assert_equal 200, last_response.status
250
- end
251
-
252
- it "passes given a nested datetime and with coerce_recursive=false and coerce_date_times=true on POST endpoint" do
253
- key_name = "update_time"
254
- params = {
255
- key_name => "2016-04-01T16:00:00.000+09:00",
256
- "array_property" => ARRAY_PROPERTY
257
- }
258
-
259
- check_parameter = lambda { |env|
260
- hash = env['committee.params']
261
- assert_equal String, hash['array_property'].first['update_time'].class
262
- assert_equal 1, hash['array_property'].first['per_page']
263
- assert_equal String, hash['array_property'].first['nested_coercer_object']['update_time'].class
264
- assert_equal 1, hash['array_property'].first['nested_no_coercer_object']['per_page']
265
- assert_equal 2, hash['array_property'].first['integer_array'][1]
266
- assert_equal String, hash['array_property'].first['datetime_array'][0].class
267
- assert_equal DateTime, env['committee.params'][key_name].class
268
- [200, {}, []]
269
- }
270
-
271
- @app = new_rack_app_with_lambda(check_parameter, coerce_date_times: true, coerce_recursive: false, schema: hyper_schema)
272
-
273
- header "Content-Type", "application/json"
274
- post "/apps", JSON.generate(params)
275
- assert_equal 200, last_response.status
276
- end
277
-
278
-
279
- it "OpenAPI3 passes given a nested datetime and with coerce_recursive=false and coerce_date_times=false on POST endpoint" do
280
- key_name = "update_time"
281
- params = {
282
- key_name => "2016-04-01T16:00:00.000+09:00",
283
- "array_property" => ARRAY_PROPERTY
140
+ "nested_array" => [
141
+ {
142
+ "update_time" => "2016-04-01T16:00:00.000+09:00",
143
+ "per_page" => 1,
144
+ "nested_coercer_object" => {
145
+ "update_time" => "2016-04-01T16:00:00.000+09:00",
146
+ "threshold" => 1.5
147
+ },
148
+ "nested_no_coercer_object" => {
149
+ "per_page" => 1,
150
+ "threshold" => 1.5
151
+ },
152
+ "nested_coercer_array" => [
153
+ {
154
+ "update_time" => "2016-04-01T16:00:00.000+09:00",
155
+ "threshold" => 1.5
156
+ }
157
+ ],
158
+ "nested_no_coercer_array" => [
159
+ {
160
+ "per_page" => 1,
161
+ "threshold" => 1.5
162
+ }
163
+ ],
164
+ "integer_array" => [
165
+ 1, 2, 3
166
+ ],
167
+ "datetime_array" => [
168
+ "2016-04-01T16:00:00.000+09:00",
169
+ "2016-04-01T17:00:00.000+09:00",
170
+ "2016-04-01T18:00:00.000+09:00"
171
+ ]
172
+ },
173
+ {
174
+ "update_time" => "2016-04-01T16:00:00.000+09:00",
175
+ "per_page" => 1,
176
+ "threshold" => 1.5
177
+ },
178
+ {
179
+ "threshold" => 1.5,
180
+ "per_page" => 1
181
+ }
182
+ ]
284
183
  }
285
184
 
286
185
  check_parameter = lambda { |env|
287
186
  hash = env['committee.params']
288
- assert_equal String, hash['array_property'].first['update_time'].class
289
- assert_equal 1, hash['array_property'].first['per_page']
290
- assert_equal String, hash['array_property'].first['nested_coercer_object']['update_time'].class
291
- assert_equal 1, hash['array_property'].first['nested_no_coercer_object']['per_page']
292
- assert_equal 2, hash['array_property'].first['integer_array'][1]
293
- assert_equal String, hash['array_property'].first['datetime_array'][0].class
294
- assert_equal String, env['committee.params'][key_name].class
187
+ array = hash['nested_array']
188
+
189
+ assert_equal DateTime, array.first['update_time'].class
190
+ assert_equal 1, array.first['per_page']
191
+ assert_equal DateTime, array.first['nested_coercer_object']['update_time'].class
192
+ assert_equal 1, array.first['nested_no_coercer_object']['per_page']
193
+ assert_equal 2, array.first['integer_array'][1]
194
+ assert_equal DateTime, array.first['datetime_array'][0].class
295
195
  [200, {}, []]
296
196
  }
297
197
 
298
- @app = new_rack_app_with_lambda(check_parameter, open_api_3: open_api_3_schema)
198
+ @app = new_rack_app_with_lambda(check_parameter,
199
+ coerce_date_times: true,
200
+ schema: open_api_3_schema)
299
201
 
300
202
  header "Content-Type", "application/json"
301
- post "/apps", JSON.generate(params)
203
+ post "/string_params_coercer", JSON.generate(params)
302
204
  assert_equal 200, last_response.status
303
205
  end
304
- =end
305
206
 
306
207
  it "OpenAPI3 detects an invalid request" do
307
- @app = new_rack_app(open_api_3: open_api_3_schema, strict: true)
208
+ @app = new_rack_app(schema: open_api_3_schema, strict: true)
308
209
  header "Content-Type", "application/json"
309
210
  params = {
310
211
  "string_post_1" => 1
@@ -316,7 +217,7 @@ describe Committee::Middleware::RequestValidation do
316
217
  end
317
218
 
318
219
  it "rescues JSON errors" do
319
- @app = new_rack_app(open_api_3: open_api_3_schema)
220
+ @app = new_rack_app(schema: open_api_3_schema)
320
221
  header "Content-Type", "application/json"
321
222
  post "/apps", "{x:y}"
322
223
  assert_equal 400, last_response.status
@@ -324,7 +225,7 @@ describe Committee::Middleware::RequestValidation do
324
225
  end
325
226
 
326
227
  it "take a prefix" do
327
- @app = new_rack_app(prefix: "/v1", open_api_3: open_api_3_schema)
228
+ @app = new_rack_app(prefix: "/v1", schema: open_api_3_schema)
328
229
  params = {
329
230
  "string_post_1" => "cloudnasium"
330
231
  }
@@ -333,147 +234,104 @@ describe Committee::Middleware::RequestValidation do
333
234
  assert_equal 200, last_response.status
334
235
  end
335
236
 
237
+ it "take a prefix with invalid data" do
238
+ @app = new_rack_app(prefix: "/v1", schema: open_api_3_schema)
239
+ params = {
240
+ "string_post_1" => 1
241
+ }
242
+ header "Content-Type", "application/json"
243
+ post "/v1/characters", JSON.generate(params)
244
+ assert_equal 400, last_response.status
245
+ assert_match(/1 class is/i, last_response.body)
246
+ end
247
+
336
248
  it "ignores paths outside the prefix" do
337
- @app = new_rack_app(prefix: "/v1", open_api_3: open_api_3_schema)
338
- header "Content-Type", "text/html"
339
- get "/hello"
249
+ @app = new_rack_app(prefix: "/v1", schema: open_api_3_schema)
250
+ params = {
251
+ "string_post_1" => 1
252
+ }
253
+ header "Content-Type", "application/json"
254
+ post "/characters", JSON.generate(params)
255
+ assert_equal 200, last_response.status
256
+ end
257
+
258
+ it "don't check prefix with no option" do
259
+ @app = new_rack_app(schema: open_api_3_schema)
260
+ params = {
261
+ "string_post_1" => 1
262
+ }
263
+ header "Content-Type", "application/json"
264
+ post "/v1/characters", JSON.generate(params)
340
265
  assert_equal 200, last_response.status
341
266
  end
342
267
 
343
268
  it "OpenAPI3 pass not exist href" do
344
- @app = new_rack_app(open_api_3: open_api_3_schema)
269
+ @app = new_rack_app(schema: open_api_3_schema)
345
270
  get "/unknown"
346
271
  assert_equal 200, last_response.status
347
272
  end
348
273
 
349
274
  it "OpenAPI3 pass not exist href in strict mode" do
350
- @app = new_rack_app(open_api_3: open_api_3_schema, strict: true)
275
+ @app = new_rack_app(schema: open_api_3_schema, strict: true)
351
276
  get "/unknown"
352
277
  assert_equal 404, last_response.status
353
278
  end
354
279
 
355
280
  it "optionally raises an error" do
356
- @app = new_rack_app(raise: true, open_api_3: open_api_3_schema)
281
+ @app = new_rack_app(raise: true, schema: open_api_3_schema)
357
282
  header "Content-Type", "application/json"
358
283
  assert_raises(Committee::InvalidRequest) do
359
284
  post "/characters", "{x:y}"
360
285
  end
361
286
  end
362
287
 
363
- # TODO: support check_content_type
364
- it "OpenAPI not support check_content_type" do
365
- @app = new_rack_app(open_api_3: open_api_3_schema, check_content_type: true)
366
-
367
- e = assert_raises(RuntimeError) {
368
- post "/characters", {}
369
- }
370
-
371
- assert_equal 'OpenAPI3 not support @check_content_type option', e.message
372
- end
373
- =begin
374
- it "optionally content_type check" do
375
- @app = new_rack_app(check_content_type: true, open_api_3: open_api_3_schema)
376
- params = {
377
- "string_post_1" => "cloudnasium"
378
- }
379
- header "Content-Type", "text/html"
380
- post "/characters", JSON.generate(params)
381
- assert_equal 400, last_response.status
382
- end
383
- =end
384
-
385
- it "optionally skip content_type check" do
386
- @app = new_rack_app(check_content_type: false, open_api_3: open_api_3_schema)
387
- params = {
388
- "string_post_1" => "cloudnasium"
389
- }
390
- header "Content-Type", "text/html"
391
- post "/characters", JSON.generate(params)
392
- assert_equal 200, last_response.status
393
- end
394
-
395
288
  it "optionally coerces query params" do
396
- @app = new_rack_app(coerce_query_params: true, open_api_3: open_api_3_schema)
289
+ @app = new_rack_app(coerce_query_params: true, schema: open_api_3_schema)
397
290
  header "Content-Type", "application/json"
398
291
  get "/string_params_coercer", {"integer_1" => "1"}
399
292
  assert_equal 200, last_response.status
400
293
  end
401
294
 
402
- =begin
403
295
  it "still raises an error if query param coercion is not possible" do
404
- @app = new_rack_app(coerce_query_params: true, schema: hyper_schema)
296
+ @app = new_rack_app(coerce_query_params: false, schema: open_api_3_schema)
405
297
  header "Content-Type", "application/json"
406
- get "/search/apps", {"per_page" => "foo", "query" => "cloudnasium"}
298
+ get "/string_params_coercer", {"integer_1" => "1"}
299
+
407
300
  assert_equal 400, last_response.status
408
- assert_match(/invalid request/i, last_response.body)
301
+ assert_match(/1 class/i, last_response.body)
409
302
  end
410
303
 
411
- it "passes through a valid request for OpenAPI" do
304
+ it "passes through a valid request for OpenAPI3" do
412
305
  check_parameter = lambda { |env|
413
306
  assert_equal 3, env['rack.request.query_hash']['limit']
414
307
  [200, {}, []]
415
308
  }
416
309
 
417
- @app = new_rack_app_with_lambda(check_parameter, schema: open_api_2_schema)
418
- get "/api/pets?limit=3", nil, { "HTTP_AUTH_TOKEN" => "xxx" }
310
+ @app = new_rack_app_with_lambda(check_parameter, schema: open_api_3_schema)
311
+ get "/characters?limit=3"
419
312
  assert_equal 200, last_response.status
420
313
  end
421
314
 
422
315
  it "detects an invalid request for OpenAPI" do
423
- @app = new_rack_app(schema: open_api_2_schema)
424
- get "/api/pets?limit=foo", nil, { "HTTP_AUTH_TOKEN" => "xxx" }
425
- assert_equal 400, last_response.status
426
- assert_match(/invalid request/i, last_response.body)
427
- end
316
+ @app = new_rack_app(schema: open_api_3_schema)
317
+ get "/characters?limit=foo"
428
318
 
429
- it "passes through a valid request for OpenAPI including path parameters" do
430
- @app = new_rack_app(schema: open_api_2_schema)
431
- # not that ID is expect to be an integer
432
- get "/api/pets/123"
433
- assert_equal 200, last_response.status
434
- end
435
-
436
- it "detects an invalid request for OpenAPI including path parameters" do
437
- @app = new_rack_app(schema: open_api_2_schema)
438
- # not that ID is expect to be an integer
439
- get "/api/pets/not-integer"
440
319
  assert_equal 400, last_response.status
441
- assert_match(/invalid request/i, last_response.body)
320
+ assert_match(/foo class/i, last_response.body)
442
321
  end
443
- =end
444
-
445
- describe "coerce_path_params" do
446
- it "coerce string to integer" do
447
- check_parameter_string = lambda { |env|
448
- assert env['committee.params']['integer'].is_a?(Integer)
449
- [200, {}, []]
450
- }
451
322
 
452
- @app = new_rack_app_with_lambda(check_parameter_string, open_api_3: open_api_3_schema, coerce_path_params: true)
453
- get "/coerce_path_params/1"
454
- end
455
-
456
- # TODO: support parameter validation
457
- it "path parameter validation" do
458
- @app = new_rack_app(open_api_3: open_api_3_schema, coerce_path_params: false)
459
- get "/coerce_path_params/1"
323
+ it "coerce string to integer" do
324
+ check_parameter_string = lambda { |env|
325
+ assert env['committee.params']['integer'].is_a?(Integer)
326
+ [200, {}, []]
327
+ }
460
328
 
461
- assert true
462
- end
463
- =begin
464
- it "path parameter validation" do
465
- @app = new_rack_app_with_lambda(check_parameter_string, open_api_3: open_api_3_schema, coerce_path_params: false)
466
- e = assert_raises(RuntimeError) {
467
- get "/coerce_path_params/1"
468
- }
469
-
470
- assert_equal 'OpenAPI3 not support @coerce_query_params option', e.message
471
- end
472
- =end
329
+ @app = new_rack_app_with_lambda(check_parameter_string, schema: open_api_3_schema, coerce_path_params: true)
330
+ get "/coerce_path_params/1"
473
331
  end
474
332
 
475
333
  it "OpenAPI3 raise not support method" do
476
- @app = new_rack_app(open_api_3: open_api_3_schema)
334
+ @app = new_rack_app(schema: open_api_3_schema)
477
335
 
478
336
  e = assert_raises(RuntimeError) {
479
337
  head "/characters", {}
@@ -482,6 +340,25 @@ describe Committee::Middleware::RequestValidation do
482
340
  assert_equal 'Committee OpenAPI3 not support head method', e.message
483
341
  end
484
342
 
343
+ describe 'check header' do
344
+ it 'no required header' do
345
+ @app = new_rack_app(schema: open_api_3_schema, check_header: true)
346
+
347
+ get "/header"
348
+
349
+ assert_equal 400, last_response.status
350
+ assert_match(/required parameters integer not exist/i, last_response.body)
351
+ end
352
+
353
+ it 'no required header but not check' do
354
+ @app = new_rack_app(schema: open_api_3_schema, check_header: false)
355
+
356
+ get "/header"
357
+
358
+ assert_equal 200, last_response.status
359
+ end
360
+ end
361
+
485
362
  private
486
363
 
487
364
  def new_rack_app(options = {})
@@ -374,23 +374,38 @@ describe Committee::Middleware::RequestValidation do
374
374
  end
375
375
 
376
376
  it "OpenAPI3 pass through a valid request" do
377
- @app = new_rack_app(open_api_3: open_api_3_schema)
377
+ @app = new_rack_app(schema: open_api_3_schema)
378
378
  get "/characters"
379
379
  assert_equal 200, last_response.status
380
380
  end
381
381
 
382
382
  it "OpenAPI3 pass not exist href" do
383
- @app = new_rack_app(open_api_3: open_api_3_schema)
383
+ @app = new_rack_app(schema: open_api_3_schema)
384
384
  get "/unknown"
385
385
  assert_equal 200, last_response.status
386
386
  end
387
387
 
388
388
  it "OpenAPI3 pass not exist href in strict mode" do
389
- @app = new_rack_app(open_api_3: open_api_3_schema, strict: true)
389
+ @app = new_rack_app(schema: open_api_3_schema, strict: true)
390
390
  get "/unknown"
391
391
  assert_equal 404, last_response.status
392
392
  end
393
393
 
394
+ it "not exist path and options" do
395
+ options = {
396
+ coerce_form_params: true,
397
+ coerce_date_times: true,
398
+ coerce_query_params: true,
399
+ coerce_path_params: true,
400
+ coerce_recursive: true
401
+ }
402
+
403
+ @app = new_rack_app({schema: hyper_schema}.merge(options))
404
+ header "Content-Type", "application/x-www-form-urlencoded"
405
+ post "/unknown"
406
+ assert_equal 200, last_response.status
407
+ end
408
+
394
409
  private
395
410
 
396
411
  def new_rack_app(options = {})