committee 3.3.0 → 4.0.0
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/drivers.rb +5 -5
- data/test/middleware/request_validation_open_api_3_test.rb +11 -6
- data/test/middleware/request_validation_test.rb +4 -1
- data/test/middleware/response_validation_open_api_3_test.rb +24 -2
- data/test/middleware/response_validation_test.rb +4 -1
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +3 -6
- data/test/test_helper.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fba0d88ad4356b605437b7bdee80b8af67f4c1604aa01ed67f8e23f03097e93d
|
4
|
+
data.tar.gz: 3a26946ba09a1543a045d2e5755e18da81302964c8b7452e093457745960ad01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 245f5960617c3bba3da10e6c64441493eb4d8d657f3deb98d18e46e3db4564ebeeae63fc372eb6153f4d2e0c00124fee4fcec1b7d8b3b342a712d9da63d28257
|
7
|
+
data.tar.gz: 5bb6f878296cac731f5c081e6fe531305c79599e427dad1d72b128def97627c56e2c62901de3aff8b15e8cfa0e07798c608b23e778aedb485a17c92d7aeb0c73
|
data/lib/committee/drivers.rb
CHANGED
@@ -21,14 +21,14 @@ module Committee
|
|
21
21
|
# @param [String] schema_path
|
22
22
|
# @return [Committee::Driver]
|
23
23
|
def self.load_from_json(schema_path)
|
24
|
-
load_from_data(JSON.parse(File.read(schema_path)))
|
24
|
+
load_from_data(JSON.parse(File.read(schema_path)), schema_path)
|
25
25
|
end
|
26
26
|
|
27
27
|
# load and build drive from YAML file
|
28
28
|
# @param [String] schema_path
|
29
29
|
# @return [Committee::Driver]
|
30
30
|
def self.load_from_yaml(schema_path)
|
31
|
-
load_from_data(YAML.load_file(schema_path))
|
31
|
+
load_from_data(YAML.load_file(schema_path), schema_path)
|
32
32
|
end
|
33
33
|
|
34
34
|
# load and build drive from file
|
@@ -48,10 +48,10 @@ module Committee
|
|
48
48
|
# load and build drive from Hash object
|
49
49
|
# @param [Hash] hash
|
50
50
|
# @return [Committee::Driver]
|
51
|
-
def self.load_from_data(hash)
|
51
|
+
def self.load_from_data(hash, schema_path = nil)
|
52
52
|
if hash['openapi']&.start_with?('3.0.')
|
53
|
-
|
54
|
-
return Committee::Drivers::OpenAPI3::Driver.new.parse(
|
53
|
+
openapi = OpenAPIParser.parse_with_filepath(hash, schema_path)
|
54
|
+
return Committee::Drivers::OpenAPI3::Driver.new.parse(openapi)
|
55
55
|
end
|
56
56
|
|
57
57
|
driver = if hash['swagger'] == '2.0'
|
@@ -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
|
|
@@ -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
|
|
@@ -99,6 +99,20 @@ describe Committee::Middleware::ResponseValidation do
|
|
99
99
|
assert_match(/valid JSON/i, last_response.body)
|
100
100
|
end
|
101
101
|
|
102
|
+
describe "remote schema $ref" do
|
103
|
+
it "passes through a valid response" do
|
104
|
+
@app = new_response_rack(JSON.generate({ "sample" => "value" }), {}, schema: open_api_3_schema)
|
105
|
+
get "/ref-sample"
|
106
|
+
assert_equal 200, last_response.status
|
107
|
+
end
|
108
|
+
|
109
|
+
it "detects a invalid response" do
|
110
|
+
@app = new_response_rack("{}", {}, schema: open_api_3_schema)
|
111
|
+
get "/ref-sample"
|
112
|
+
assert_equal 500, last_response.status
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
102
116
|
describe 'check header' do
|
103
117
|
[
|
104
118
|
{ check_header: true, description: 'valid value', header: { 'integer' => 1 }, expected: { status: 200 } },
|
@@ -108,7 +122,11 @@ describe Committee::Middleware::ResponseValidation do
|
|
108
122
|
{ check_header: false, description: 'valid value', header: { 'integer' => 1 }, expected: { status: 200 } },
|
109
123
|
{ check_header: false, description: 'missing value', header: { 'integer' => nil }, expected: { status: 200 } },
|
110
124
|
{ check_header: false, description: 'invalid value', header: { 'integer' => 'x' }, expected: { status: 200 } },
|
111
|
-
].each do |
|
125
|
+
].each do |h|
|
126
|
+
check_header = h[:check_header]
|
127
|
+
description = h[:description]
|
128
|
+
header = h[:header]
|
129
|
+
expected = h[:expected]
|
112
130
|
describe "when #{check_header}" do
|
113
131
|
%w(get post put patch delete).each do |method|
|
114
132
|
describe method do
|
@@ -174,7 +192,11 @@ describe Committee::Middleware::ResponseValidation do
|
|
174
192
|
{ description: 'when not specified, includes everything', accept_request_filter: nil, expected: { status: 500 } },
|
175
193
|
{ description: 'when predicate matches, performs validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/c') }, expected: { status: 500 } },
|
176
194
|
{ description: 'when predicate does not match, skips validation', accept_request_filter: -> (request) { request.path.start_with?('/v1/x') }, expected: { status: 200 } },
|
177
|
-
].each do |
|
195
|
+
].each do |h|
|
196
|
+
description = h[:description]
|
197
|
+
accept_request_filter = h[:accept_request_filter]
|
198
|
+
expected = h[:expected]
|
199
|
+
|
178
200
|
it description do
|
179
201
|
@app = new_response_rack('not_json', {}, schema: open_api_3_schema, prefix: '/v1', accept_request_filter: accept_request_filter)
|
180
202
|
|
@@ -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
|
|
@@ -52,8 +52,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
52
52
|
operation_object.validate_request_params({"string" => 1}, HEADER, @validator_option)
|
53
53
|
}
|
54
54
|
|
55
|
-
|
56
|
-
assert_match(/expected string, but received #{1.class}: 1/i, e.message)
|
55
|
+
assert_match(/expected string, but received Integer: 1/i, e.message)
|
57
56
|
end
|
58
57
|
|
59
58
|
it 'support put method' do
|
@@ -64,8 +63,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
64
63
|
operation_object.validate_request_params({"string" => 1}, HEADER, @validator_option)
|
65
64
|
}
|
66
65
|
|
67
|
-
|
68
|
-
assert_match(/expected string, but received #{1.class}: 1/i, e.message)
|
66
|
+
assert_match(/expected string, but received Integer: 1/i, e.message)
|
69
67
|
end
|
70
68
|
|
71
69
|
it 'support patch method' do
|
@@ -121,8 +119,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
121
119
|
)
|
122
120
|
}
|
123
121
|
|
124
|
-
|
125
|
-
assert_match(/expected string, but received #{1.class}: 1/i, e.message)
|
122
|
+
assert_match(/expected string, but received Integer: 1/i, e.message)
|
126
123
|
end
|
127
124
|
end
|
128
125
|
|
data/test/test_helper.rb
CHANGED
@@ -56,7 +56,7 @@ def open_api_2_schema
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def open_api_3_schema
|
59
|
-
@open_api_3_schema ||= Committee::Drivers.
|
59
|
+
@open_api_3_schema ||= Committee::Drivers.load_from_file(open_api_3_schema_path)
|
60
60
|
end
|
61
61
|
|
62
62
|
# Don't cache this because we'll often manipulate the created hash in tests.
|
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
|
+
version: 4.0.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:
|
13
|
+
date: 2020-05-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_schema
|
@@ -52,14 +52,14 @@ dependencies:
|
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.11.1
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
62
|
+
version: 0.11.1
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: minitest
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -282,14 +282,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
282
282
|
requirements:
|
283
283
|
- - ">="
|
284
284
|
- !ruby/object:Gem::Version
|
285
|
-
version: 2.
|
285
|
+
version: 2.4.0
|
286
286
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
287
287
|
requirements:
|
288
288
|
- - ">="
|
289
289
|
- !ruby/object:Gem::Version
|
290
290
|
version: '0'
|
291
291
|
requirements: []
|
292
|
-
rubygems_version: 3.
|
292
|
+
rubygems_version: 3.1.2
|
293
293
|
signing_key:
|
294
294
|
specification_version: 4
|
295
295
|
summary: A collection of Rack middleware to support JSON Schema.
|