committee 4.0.0 → 4.1.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/schema_validator/hyper_schema.rb +8 -1
- data/lib/committee/schema_validator/open_api_3.rb +8 -1
- data/lib/committee/schema_validator/option.rb +8 -1
- data/test/bin/committee_stub_test.rb +5 -1
- data/test/middleware/base_test.rb +9 -3
- data/test/middleware/request_validation_open_api_3_test.rb +3 -0
- data/test/middleware/request_validation_test.rb +3 -0
- data/test/middleware/response_validation_open_api_3_test.rb +11 -0
- data/test/middleware/response_validation_test.rb +3 -0
- data/test/middleware/stub_test.rb +4 -0
- data/test/request_unpacker_test.rb +12 -3
- data/test/schema_validator/hyper_schema/router_test.rb +4 -0
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +6 -1
- data/test/schema_validator/open_api_3/request_validator_test.rb +3 -0
- data/test/schema_validator/open_api_3/response_validator_test.rb +8 -3
- data/test/test/methods_new_version_test.rb +3 -0
- data/test/test/methods_test.rb +6 -3
- 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: 9bef22bebc103d1bee78ba294078cd56e34e37da3e92b5cb89aba683a2361c74
|
4
|
+
data.tar.gz: 76f012e3f28bd5275af941a372563f00b3bf68e1c0332d0e78affc18cbac9f2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da601220eca1ea05bb829a61a65bf6928262be27c73647de756f44b07329752efe6818be1a79b95bb51ad2e00025d08ff5fbb5410acfdc670d43f6816c6614f1
|
7
|
+
data.tar.gz: c0fad32bef922020708c194065d0de90fccc9d33d00354b4c8a4f3208e18b4720030e01810e798107894e6f503e8145fef11fd12afa1ba1f0b5b017f3b58eeda
|
@@ -35,7 +35,14 @@ module Committee
|
|
35
35
|
response.each do |chunk|
|
36
36
|
full_body << chunk
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
|
+
data = {}
|
40
|
+
unless full_body.empty?
|
41
|
+
parse_to_json = !validator_option.parse_response_by_content_type ||
|
42
|
+
headers.fetch('Content-Type', nil)&.start_with?('application/json')
|
43
|
+
data = JSON.parse(full_body) if parse_to_json
|
44
|
+
end
|
45
|
+
|
39
46
|
Committee::SchemaValidator::HyperSchema::ResponseValidator.new(link, validate_success_only: validator_option.validate_success_only).call(status, headers, data)
|
40
47
|
end
|
41
48
|
|
@@ -30,7 +30,14 @@ module Committee
|
|
30
30
|
response.each do |chunk|
|
31
31
|
full_body << chunk
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
|
+
parse_to_json = !validator_option.parse_response_by_content_type ||
|
35
|
+
headers.fetch('Content-Type', nil)&.start_with?('application/json')
|
36
|
+
data = if parse_to_json
|
37
|
+
full_body.empty? ? {} : JSON.parse(full_body)
|
38
|
+
else
|
39
|
+
full_body
|
40
|
+
end
|
34
41
|
|
35
42
|
strict = test_method
|
36
43
|
Committee::SchemaValidator::OpenAPI3::ResponseValidator.
|
@@ -15,7 +15,8 @@ module Committee
|
|
15
15
|
:coerce_query_params,
|
16
16
|
:coerce_recursive,
|
17
17
|
:optimistic_json,
|
18
|
-
:validate_success_only
|
18
|
+
:validate_success_only,
|
19
|
+
:parse_response_by_content_type
|
19
20
|
|
20
21
|
# Non-boolean options:
|
21
22
|
attr_reader :headers_key,
|
@@ -35,6 +36,12 @@ module Committee
|
|
35
36
|
@check_header = options.fetch(:check_header, true)
|
36
37
|
@coerce_recursive = options.fetch(:coerce_recursive, true)
|
37
38
|
@optimistic_json = options.fetch(:optimistic_json, false)
|
39
|
+
@parse_response_by_content_type = if options[:parse_response_by_content_type].nil?
|
40
|
+
Committee.warn_deprecated('Committee: please set parse_response_by_content_type = false because we\'ll change default value in next major version.')
|
41
|
+
false
|
42
|
+
else
|
43
|
+
options.fetch(:parse_response_by_content_type)
|
44
|
+
end
|
38
45
|
|
39
46
|
# Boolean options and have a different value by default
|
40
47
|
@allow_get_body = options.fetch(:allow_get_body, schema.driver.default_allow_get_body)
|
@@ -43,7 +43,11 @@ describe Committee::Bin::CommitteeStub, "app" do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def app
|
46
|
-
|
46
|
+
options = {}
|
47
|
+
# TODO: delete when 5.0.0 released because default value changed
|
48
|
+
options[:parse_response_by_content_type] = false
|
49
|
+
|
50
|
+
@bin.get_app(hyper_schema, options)
|
47
51
|
end
|
48
52
|
|
49
53
|
it "defaults to a 404" do
|
@@ -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 { |_|
|
@@ -466,6 +466,9 @@ describe Committee::Middleware::RequestValidation do
|
|
466
466
|
end
|
467
467
|
|
468
468
|
def new_rack_app_with_lambda(check_lambda, options = {})
|
469
|
+
# TODO: delete when 5.0.0 released because default value changed
|
470
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
471
|
+
|
469
472
|
Rack::Builder.new {
|
470
473
|
use Committee::Middleware::RequestValidation, options
|
471
474
|
run check_lambda
|
@@ -519,6 +519,9 @@ describe Committee::Middleware::RequestValidation do
|
|
519
519
|
|
520
520
|
|
521
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
|
+
|
522
525
|
Rack::Builder.new {
|
523
526
|
use Committee::Middleware::RequestValidation, options
|
524
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"
|
@@ -210,6 +218,9 @@ describe Committee::Middleware::ResponseValidation do
|
|
210
218
|
private
|
211
219
|
|
212
220
|
def new_response_rack(response, headers = {}, options = {}, rack_options = {})
|
221
|
+
# TODO: delete when 5.0.0 released because default value changed
|
222
|
+
options[:parse_response_by_content_type] = true if options[:parse_response_by_content_type] == nil
|
223
|
+
|
213
224
|
status = rack_options[:status] || 200
|
214
225
|
headers = {
|
215
226
|
"Content-Type" => "application/json"
|
@@ -184,6 +184,9 @@ describe Committee::Middleware::ResponseValidation do
|
|
184
184
|
private
|
185
185
|
|
186
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
|
+
|
187
190
|
headers = {
|
188
191
|
"Content-Type" => "application/json"
|
189
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|
|
@@ -100,7 +100,10 @@ describe Committee::RequestUnpacker do
|
|
100
100
|
}
|
101
101
|
request = Rack::Request.new(env)
|
102
102
|
|
103
|
-
|
103
|
+
options = {}
|
104
|
+
# TODO: delete when 5.0.0 released because default value changed
|
105
|
+
options[:parse_response_by_content_type] = false
|
106
|
+
router = hyper_schema.build_router(options)
|
104
107
|
validator = router.build_schema_validator(request)
|
105
108
|
|
106
109
|
schema = JsonSchema::Schema.new
|
@@ -133,7 +136,10 @@ describe Committee::RequestUnpacker do
|
|
133
136
|
}
|
134
137
|
request = Rack::Request.new(env)
|
135
138
|
|
136
|
-
|
139
|
+
options = {}
|
140
|
+
# TODO: delete when 5.0.0 released because default value changed
|
141
|
+
options[:parse_response_by_content_type] = false
|
142
|
+
router = open_api_3_schema.build_router(options)
|
137
143
|
validator = router.build_schema_validator(request)
|
138
144
|
|
139
145
|
params, _ = Committee::RequestUnpacker.new(
|
@@ -158,7 +164,10 @@ describe Committee::RequestUnpacker do
|
|
158
164
|
}
|
159
165
|
request = Rack::Request.new(env)
|
160
166
|
|
161
|
-
|
167
|
+
options = {}
|
168
|
+
# TODO: delete when 5.0.0 released because default value changed
|
169
|
+
options[:parse_response_by_content_type] = false
|
170
|
+
router = open_api_3_schema.build_router(options)
|
162
171
|
validator = router.build_schema_validator(request)
|
163
172
|
|
164
173
|
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
|
@@ -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,7 +34,7 @@ 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
39
|
assert_raises(Committee::InvalidResponse) {
|
35
40
|
call_response_validator(true)
|
@@ -41,7 +46,7 @@ describe Committee::SchemaValidator::OpenAPI3::ResponseValidator do
|
|
41
46
|
call_response_validator
|
42
47
|
end
|
43
48
|
|
44
|
-
it "
|
49
|
+
it "raises InvalidResponse when a valid response with no Content-Type headers with strict option" do
|
45
50
|
@headers = {}
|
46
51
|
assert_raises(Committee::InvalidResponse) {
|
47
52
|
call_response_validator(true)
|
@@ -30,6 +30,9 @@ describe Committee::Test::Methods do
|
|
30
30
|
@committee_schema = nil
|
31
31
|
|
32
32
|
@committee_options = {schema: hyper_schema}
|
33
|
+
|
34
|
+
# TODO: delete when 5.0.0 released because default value changed
|
35
|
+
@committee_options[:parse_response_by_content_type] = false
|
33
36
|
end
|
34
37
|
|
35
38
|
describe "#assert_schema_conform" do
|
data/test/test/methods_test.rb
CHANGED
@@ -28,7 +28,10 @@ describe Committee::Test::Methods do
|
|
28
28
|
# our purposes here in testing the module.
|
29
29
|
@committee_router = nil
|
30
30
|
@committee_schema = nil
|
31
|
-
@committee_options =
|
31
|
+
@committee_options = {}
|
32
|
+
|
33
|
+
# TODO: delete when 5.0.0 released because default value changed
|
34
|
+
@committee_options[:parse_response_by_content_type] = true
|
32
35
|
end
|
33
36
|
|
34
37
|
describe "Hyper-Schema" do
|
@@ -36,7 +39,7 @@ describe Committee::Test::Methods do
|
|
36
39
|
sc = JsonSchema.parse!(hyper_schema_data)
|
37
40
|
sc.expand_references!
|
38
41
|
s = Committee::Drivers::HyperSchema::Driver.new.parse(sc)
|
39
|
-
@committee_options
|
42
|
+
@committee_options.merge!({schema: s})
|
40
43
|
end
|
41
44
|
|
42
45
|
describe "#assert_schema_conform" do
|
@@ -120,7 +123,7 @@ describe Committee::Test::Methods do
|
|
120
123
|
|
121
124
|
describe "OpenAPI3" do
|
122
125
|
before do
|
123
|
-
@committee_options
|
126
|
+
@committee_options.merge!({schema: open_api_3_schema})
|
124
127
|
|
125
128
|
@correct_response = { string_1: :honoka }
|
126
129
|
end
|
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: 4.
|
4
|
+
version: 4.1.0
|
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: 2020-
|
13
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_schema
|