committee 5.5.2 → 5.5.3
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.
- checksums.yaml +4 -4
- data/lib/committee/request_unpacker.rb +6 -5
- data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +21 -9
- data/lib/committee/schema_validator/open_api_3/response_validator.rb +4 -1
- data/lib/committee/schema_validator/open_api_3.rb +1 -0
- data/lib/committee/schema_validator/option.rb +2 -0
- data/lib/committee/version.rb +1 -1
- data/test/middleware/request_validation_open_api_3_test.rb +45 -1
- data/test/schema_validator/open_api_3/response_validator_test.rb +70 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d63a9269323d485600c6f853e59ea9ac678faa6090838560cea1e54cec88f40
|
4
|
+
data.tar.gz: d8168ded9e92aabbf7144e6f98c8b52a90f1b5b956c3c4d9ae1bbba61504fbf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b951a8e7d81870e3d5947145dfdafb777e980367d41f83f4bc66c4ed902face9b29e6e92f7bb2db55e5a3ed56ff0c95544b35305373061501dcba76cb71ee5e
|
7
|
+
data.tar.gz: ac977e7c4f909abd4707aa0b540cf5efcd885b03212bec6eca6cf69f4199e2bed0ed2711768d7852f93921192d12ea957e7f4f07868cc3259b96374097c89a12
|
@@ -21,11 +21,12 @@ module Committee
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def initialize(options = {})
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
28
|
-
@
|
24
|
+
@allow_empty_date_and_datetime = options[:allow_empty_date_and_datetime]
|
25
|
+
@allow_form_params = options[:allow_form_params]
|
26
|
+
@allow_get_body = options[:allow_get_body]
|
27
|
+
@allow_query_params = options[:allow_query_params]
|
28
|
+
@allow_non_get_query_params = options[:allow_non_get_query_params]
|
29
|
+
@optimistic_json = options[:optimistic_json]
|
29
30
|
end
|
30
31
|
|
31
32
|
# return params and is_form_params
|
@@ -31,10 +31,12 @@ module Committee
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# @param [Boolean] strict when not content_type or status code definition, raise error
|
34
|
-
def validate_response_params(status_code, headers, response_data, strict, check_header)
|
34
|
+
def validate_response_params(status_code, headers, response_data, strict, check_header, validator_options: {})
|
35
35
|
response_body = OpenAPIParser::RequestOperation::ValidatableResponseBody.new(status_code, response_data, headers)
|
36
36
|
|
37
|
-
return request_operation.validate_response_body(
|
37
|
+
return request_operation.validate_response_body(
|
38
|
+
response_body,
|
39
|
+
response_validate_options(strict, check_header, validator_options: validator_options))
|
38
40
|
rescue OpenAPIParser::OpenAPIError => e
|
39
41
|
raise Committee::InvalidResponse.new(e.message, original_error: e)
|
40
42
|
end
|
@@ -89,11 +91,15 @@ module Committee
|
|
89
91
|
|
90
92
|
# @return [OpenAPIParser::SchemaValidator::Options]
|
91
93
|
def build_openapi_parser_option(validator_option, coerce_value)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
parser_options = {
|
95
|
+
coerce_value: coerce_value,
|
96
|
+
datetime_coerce_class: validator_option.coerce_date_times ? DateTime : nil,
|
97
|
+
validate_header: validator_option.check_header,
|
98
|
+
}
|
99
|
+
if OpenAPIParser::SchemaValidator::Options.method_defined?(:allow_empty_date_and_datetime)
|
100
|
+
parser_options[:allow_empty_date_and_datetime] = validator_option.allow_empty_date_and_datetime
|
101
|
+
end
|
102
|
+
OpenAPIParser::SchemaValidator::Options.new(**parser_options)
|
97
103
|
end
|
98
104
|
|
99
105
|
def validate_get_request_params(path_params, query_params, headers, validator_option)
|
@@ -130,8 +136,14 @@ module Committee
|
|
130
136
|
end
|
131
137
|
end
|
132
138
|
|
133
|
-
def response_validate_options(strict, check_header)
|
134
|
-
|
139
|
+
def response_validate_options(strict, check_header, validator_options: {})
|
140
|
+
options = { strict: strict, validate_header: check_header }
|
141
|
+
|
142
|
+
if OpenAPIParser::SchemaValidator::ResponseValidateOptions.method_defined?(:validator_options)
|
143
|
+
::OpenAPIParser::SchemaValidator::ResponseValidateOptions.new(**options, **validator_options)
|
144
|
+
else
|
145
|
+
::OpenAPIParser::SchemaValidator::ResponseValidateOptions.new(**options)
|
146
|
+
end
|
135
147
|
end
|
136
148
|
end
|
137
149
|
end
|
@@ -12,12 +12,15 @@ module Committee
|
|
12
12
|
@operation_wrapper = operation_wrapper
|
13
13
|
@validate_success_only = validator_option.validate_success_only
|
14
14
|
@check_header = validator_option.check_header
|
15
|
+
@allow_empty_date_and_datetime = validator_option.allow_empty_date_and_datetime
|
15
16
|
end
|
16
17
|
|
17
18
|
def call(status, headers, response_data, strict)
|
18
19
|
return unless Committee::Middleware::ResponseValidation.validate?(status, validate_success_only)
|
19
20
|
|
20
|
-
|
21
|
+
validator_options = { allow_empty_date_and_datetime: @allow_empty_date_and_datetime }
|
22
|
+
|
23
|
+
operation_wrapper.validate_response_params(status, headers, response_data, strict, check_header, validator_options: validator_options)
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
@@ -84,6 +84,7 @@ module Committee
|
|
84
84
|
|
85
85
|
def request_unpack(request)
|
86
86
|
unpacker = Committee::RequestUnpacker.new(
|
87
|
+
allow_empty_date_and_datetime: validator_option.allow_empty_date_and_datetime,
|
87
88
|
allow_form_params: validator_option.allow_form_params,
|
88
89
|
allow_get_body: validator_option.allow_get_body,
|
89
90
|
allow_query_params: validator_option.allow_query_params,
|
@@ -5,6 +5,7 @@ module Committee
|
|
5
5
|
class Option
|
6
6
|
# Boolean Options
|
7
7
|
attr_reader :allow_blank_structures,
|
8
|
+
:allow_empty_date_and_datetime,
|
8
9
|
:allow_form_params,
|
9
10
|
:allow_get_body,
|
10
11
|
:allow_query_params,
|
@@ -36,6 +37,7 @@ module Committee
|
|
36
37
|
|
37
38
|
# Boolean options and have a common value by default
|
38
39
|
@allow_blank_structures = options.fetch(:allow_blank_structures, false)
|
40
|
+
@allow_empty_date_and_datetime = options.fetch(:allow_empty_date_and_datetime, false)
|
39
41
|
@allow_form_params = options.fetch(:allow_form_params, true)
|
40
42
|
@allow_query_params = options.fetch(:allow_query_params, true)
|
41
43
|
@allow_non_get_query_params = options.fetch(:allow_non_get_query_params, false)
|
data/lib/committee/version.rb
CHANGED
@@ -146,7 +146,7 @@ describe Committee::Middleware::RequestValidation do
|
|
146
146
|
assert_equal 200, last_response.status
|
147
147
|
end
|
148
148
|
|
149
|
-
it "
|
149
|
+
it "errors given an invalid datetime string with coerce_date_times enabled" do
|
150
150
|
@app = new_rack_app(schema: open_api_3_schema, coerce_date_times: true)
|
151
151
|
params = { "datetime_string" => "invalid_datetime_format" }
|
152
152
|
get "/string_params_coercer", params
|
@@ -244,6 +244,50 @@ describe Committee::Middleware::RequestValidation do
|
|
244
244
|
assert_equal 200, last_response.status
|
245
245
|
end
|
246
246
|
|
247
|
+
it "errors given an empty datetime string with allow_empty_date_and_datetime disabled" do
|
248
|
+
@app = new_rack_app(schema: open_api_3_schema)
|
249
|
+
params = { "datetime_string" => "" }
|
250
|
+
get "/string_params_coercer", params
|
251
|
+
|
252
|
+
assert_equal 400, last_response.status
|
253
|
+
assert_match(/\\"\\" is not conformant with date-time format/i, last_response.body)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "passes given an empty datetime string with allow_empty_date_and_datetime enabled" do
|
257
|
+
@app = new_rack_app(schema: open_api_3_schema, allow_empty_date_and_datetime: true)
|
258
|
+
params = { "datetime_string" => "" }
|
259
|
+
get "/string_params_coercer", params
|
260
|
+
|
261
|
+
if OpenAPIParser::VERSION >= "2.2.5"
|
262
|
+
assert_equal 200, last_response.status
|
263
|
+
else
|
264
|
+
assert_equal 400, last_response.status
|
265
|
+
assert_match(/\\"\\" is not conformant with date-time format/i, last_response.body)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
it "errors given an empty date string with allow_empty_date_and_datetime disabled" do
|
270
|
+
@app = new_rack_app(schema: open_api_3_schema)
|
271
|
+
params = { "date_string" => "" }
|
272
|
+
get "/string_params_coercer", params
|
273
|
+
|
274
|
+
assert_equal 400, last_response.status
|
275
|
+
assert_match(/\\"\\" is not conformant with date format/i, last_response.body)
|
276
|
+
end
|
277
|
+
|
278
|
+
it "passes given an empty date string with allow_empty_date_and_datetime enabled" do
|
279
|
+
@app = new_rack_app(schema: open_api_3_schema, allow_empty_date_and_datetime: true)
|
280
|
+
params = { "date_string" => "" }
|
281
|
+
get "/string_params_coercer", params
|
282
|
+
|
283
|
+
if OpenAPIParser::VERSION >= "2.2.5"
|
284
|
+
assert_equal 200, last_response.status
|
285
|
+
else
|
286
|
+
assert_equal 400, last_response.status
|
287
|
+
assert_match(/\\"\\" is not conformant with date format/i, last_response.body)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
247
291
|
it "OpenAPI3 detects an invalid request" do
|
248
292
|
@app = new_rack_app(schema: open_api_3_schema, strict: true)
|
249
293
|
header "Content-Type", "application/json"
|
@@ -75,6 +75,76 @@ describe Committee::SchemaValidator::OpenAPI3::ResponseValidator do
|
|
75
75
|
call_response_validator
|
76
76
|
end
|
77
77
|
|
78
|
+
describe 'allow_empty_date_and_datetime' do
|
79
|
+
it "errors given an empty date string with allow_empty_date_and_datetime disabled" do
|
80
|
+
@path = '/date_time'
|
81
|
+
@method = 'get'
|
82
|
+
@data = { 'date' => '' }
|
83
|
+
|
84
|
+
e = assert_raises(Committee::InvalidResponse) {
|
85
|
+
call_response_validator
|
86
|
+
}
|
87
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
88
|
+
assert_match(/\"\" is not conformant with date format/i, e.message)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "errors given an empty date-time string with allow_empty_date_and_datetime disabled" do
|
92
|
+
@path = '/date_time'
|
93
|
+
@method = 'get'
|
94
|
+
@data = { 'date-time' => '' }
|
95
|
+
|
96
|
+
e = assert_raises(Committee::InvalidResponse) {
|
97
|
+
call_response_validator
|
98
|
+
}
|
99
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
100
|
+
assert_match(/\"\" is not conformant with date-time format/i, e.message)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "passes given an empty date string with allow_empty_date_and_datetime enabled" do
|
104
|
+
@validator_option = Committee::SchemaValidator::Option.new(
|
105
|
+
{ allow_empty_date_and_datetime: true },
|
106
|
+
open_api_3_schema,
|
107
|
+
:open_api_3)
|
108
|
+
|
109
|
+
@path = '/date_time'
|
110
|
+
@method = 'get'
|
111
|
+
@data = { 'date' => '' }
|
112
|
+
|
113
|
+
if OpenAPIParser::VERSION >= "2.2.6"
|
114
|
+
response = call_response_validator
|
115
|
+
assert_equal({ 'date' => '' }, response)
|
116
|
+
else
|
117
|
+
e = assert_raises(Committee::InvalidResponse) {
|
118
|
+
call_response_validator
|
119
|
+
}
|
120
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
121
|
+
assert_match(/\"\" is not conformant with date format/i, e.message)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "passes given an empty date-time string with allow_empty_date_and_datetime enabled" do
|
126
|
+
@validator_option = Committee::SchemaValidator::Option.new(
|
127
|
+
{ allow_empty_date_and_datetime: true },
|
128
|
+
open_api_3_schema,
|
129
|
+
:open_api_3)
|
130
|
+
|
131
|
+
@path = '/date_time'
|
132
|
+
@method = 'get'
|
133
|
+
@data = { 'date-time' => '' }
|
134
|
+
|
135
|
+
if OpenAPIParser::VERSION >= "2.2.6"
|
136
|
+
response = call_response_validator
|
137
|
+
assert_equal({ 'date-time' => '' }, response)
|
138
|
+
else
|
139
|
+
e = assert_raises(Committee::InvalidResponse) {
|
140
|
+
call_response_validator
|
141
|
+
}
|
142
|
+
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
|
143
|
+
assert_match(/\"\" is not conformant with date-time format/i, e.message)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
78
148
|
private
|
79
149
|
|
80
150
|
def call_response_validator(strict = false)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: committee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.5.
|
4
|
+
version: 5.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2025-
|
13
|
+
date: 2025-04-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_schema
|