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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c35304cf9026ae20062ea312cdca6b43af486c4c2e5e7c952b35bbad811ce4e
4
- data.tar.gz: d9a96cd2c6c15b9de26fb95ef0b4d59216c999f8589329d6ee6b21b41e2511d9
3
+ metadata.gz: fba0d88ad4356b605437b7bdee80b8af67f4c1604aa01ed67f8e23f03097e93d
4
+ data.tar.gz: 3a26946ba09a1543a045d2e5755e18da81302964c8b7452e093457745960ad01
5
5
  SHA512:
6
- metadata.gz: 42ffc889dcc301c9de500417390454f4723bf049f0336b9de92b94fcaa2d67f53a7f5c4c9ad5a3a56bd2e9fff70d06ebe7c7279729c616b45ab33625c2a33572
7
- data.tar.gz: d3c7ca273497b2eb4444fcdb6eb43f49fed866335d1a627f806586f6755557b8a956b43eb5c9448b7cf19176b9e2a4705c78bf6045dde2e98b19fd55211e0070
6
+ metadata.gz: 245f5960617c3bba3da10e6c64441493eb4d8d657f3deb98d18e46e3db4564ebeeae63fc372eb6153f4d2e0c00124fee4fcec1b7d8b3b342a712d9da63d28257
7
+ data.tar.gz: 5bb6f878296cac731f5c081e6fe531305c79599e427dad1d72b128def97627c56e2c62901de3aff8b15e8cfa0e07798c608b23e778aedb485a17c92d7aeb0c73
@@ -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
- parser = OpenAPIParser.parse(hash)
54
- return Committee::Drivers::OpenAPI3::Driver.new.parse(parser)
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
- # FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
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
- # FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
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 |check_header:, description:, value:, expected:|
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 |description:, accept_request_filter:, expected:|
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 |description:, accept_request_filter:, expected:|
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 |check_header:, description:, header:, expected:|
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 |description:, accept_request_filter:, expected:|
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 |description:, accept_request_filter:, expected:|
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
- # FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
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
- # FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
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
- # FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
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
 
@@ -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.load_from_data(open_api_3_data)
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: 3.3.0
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: 2019-11-15 00:00:00.000000000 Z
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.6.1
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.6.1
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.3.0
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.0.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.