committee 4.2.0 → 4.2.1

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: 43984e56c905ff9e141e1ed49af5c9e51b07c39bda8bc268d195dc5799809d89
4
- data.tar.gz: 76a6269ac7cc8237a63b2ae6c69ac512a60cecabaed7564dee88cd3adfa9328e
3
+ metadata.gz: 238def2dc052574b0bb8022a3765df9a6f5c3b359ee34d9bcdbdccef7240748a
4
+ data.tar.gz: 615f73429b3c9e4336cdfef38db5d4f9ec778298fdc96139f10d83f8d12cf296
5
5
  SHA512:
6
- metadata.gz: f79ef24531c7b81489d12ea59e9da42e570236554a84c064c8478625e29167c3fef7245196a2c48d2a0a31ab33639417d47527321b321172f32c5f80fce5f46b
7
- data.tar.gz: 68c8ad83aa2392ba1d31d440edb54b1301b6c37e093f7d466c0a9f406510a0efbdf6c9ea8aacf1ddf051fae31c03d2bd777accd90101bd321037dfdafd0affbf
6
+ metadata.gz: 113e66a74a6e2214f53aaf572c8563f1d99b273e70ac0f96e1f77c3aaf44c0af4964468bd11bfaf906449db8fb9a7f32b7e6943aa11e5895b11c92e09481c62f
7
+ data.tar.gz: 8c7fd8cddfea01a569a85ee1f49ff41e1854474b922c0cdeec0b96cfff57349fa9905d84cf8727b48fdfa3fd026d69b4f4493964e6d7b7917086777c1cdf89ad
@@ -8,9 +8,21 @@ module Committee
8
8
  end
9
9
 
10
10
  class InvalidRequest < Error
11
+ attr_reader :original_error
12
+
13
+ def initialize(error_message=nil, original_error: nil)
14
+ @original_error = original_error
15
+ super(error_message)
16
+ end
11
17
  end
12
18
 
13
19
  class InvalidResponse < Error
20
+ attr_reader :original_error
21
+
22
+ def initialize(error_message=nil, original_error: nil)
23
+ @original_error = original_error
24
+ super(error_message)
25
+ end
14
26
  end
15
27
 
16
28
  class NotFound < Error
@@ -42,11 +42,7 @@ module Committee
42
42
  if @error_handler.arity > 1
43
43
  @error_handler.call(e, env)
44
44
  else
45
- warn <<-MESSAGE
46
- [DEPRECATION] Using `error_handler.call(exception)` is deprecated and will be change to
47
- `error_handler.call(exception, request.env)` in next major version.
48
- MESSAGE
49
-
45
+ warn '[DEPRECATION] Using `error_handler.call(exception)` is deprecated and will be change to `error_handler.call(exception, request.env)` in next major version.'
50
46
  @error_handler.call(e)
51
47
  end
52
48
  end
@@ -46,11 +46,7 @@ module Committee
46
46
  if @error_handler.arity > 1
47
47
  @error_handler.call(e, env)
48
48
  else
49
- warn <<-MESSAGE
50
- [DEPRECATION] Using `error_handler.call(exception)` is deprecated and will be change to
51
- `error_handler.call(exception, request.env)` in next major version.
52
- MESSAGE
53
-
49
+ warn '[DEPRECATION] Using `error_handler.call(exception)` is deprecated and will be change to `error_handler.call(exception, request.env)` in next major version.'
54
50
  @error_handler.call(e)
55
51
  end
56
52
  end
@@ -16,7 +16,7 @@ module Committee
16
16
  def call
17
17
  # if Content-Type is empty or JSON, and there was a request body, try to
18
18
  # interpret it as JSON
19
- params = if !@request.media_type || @request.media_type =~ %r{application/.*json}
19
+ params = if !@request.media_type || @request.media_type =~ %r{application/(?:.*\+)?json}
20
20
  parse_json
21
21
  elsif @optimistic_json
22
22
  begin
@@ -23,7 +23,7 @@ module Committee
23
23
 
24
24
  request_operation.validate_path_params(options)
25
25
  rescue OpenAPIParser::OpenAPIError => e
26
- raise Committee::InvalidRequest.new(e.message)
26
+ raise Committee::InvalidRequest.new(e.message, original_error: e)
27
27
  end
28
28
 
29
29
  # @param [Boolean] strict when not content_type or status code definition, raise error
@@ -32,7 +32,7 @@ module Committee
32
32
 
33
33
  return request_operation.validate_response_body(response_body, response_validate_options(strict, check_header))
34
34
  rescue OpenAPIParser::OpenAPIError => e
35
- raise Committee::InvalidResponse.new(e.message)
35
+ raise Committee::InvalidResponse.new(e.message, original_error: e)
36
36
  end
37
37
 
38
38
  def validate_request_params(params, headers, validator_option)
@@ -109,7 +109,7 @@ module Committee
109
109
  # bad performance because when we coerce value, same check
110
110
  request_operation.validate_request_parameter(params, headers, build_openapi_parser_get_option(validator_option))
111
111
  rescue OpenAPIParser::OpenAPIError => e
112
- raise Committee::InvalidRequest.new(e.message)
112
+ raise Committee::InvalidRequest.new(e.message, original_error: e)
113
113
  end
114
114
 
115
115
  def validate_post_request_params(params, headers, validator_option)
@@ -120,7 +120,7 @@ module Committee
120
120
  request_operation.validate_request_parameter(params, headers, schema_validator_options)
121
121
  request_operation.validate_request_body(content_type, params, schema_validator_options)
122
122
  rescue => e
123
- raise Committee::InvalidRequest.new(e.message)
123
+ raise Committee::InvalidRequest.new(e.message, original_error: e)
124
124
  end
125
125
 
126
126
  def response_validate_options(strict, check_header)
@@ -58,12 +58,7 @@ module Committee
58
58
  def old_behavior
59
59
  old_assert_behavior = committee_options.fetch(:old_assert_behavior, nil)
60
60
  if old_assert_behavior.nil?
61
- warn <<-MSG
62
- [DEPRECATION] now assert_schema_conform check response schema only.
63
- but we will change check request and response in future major version.
64
- so if you want to conform response only, please use assert_response_schema_confirm,
65
- or you can suppress this message and keep old behavior by setting old_assert_behavior=true.
66
- MSG
61
+ warn '[DEPRECATION] now assert_schema_conform check response schema only. but we will change check request and response in future major version. so if you want to conform response only, please use assert_response_schema_confirm, or you can suppress this message and keep old behavior by setting old_assert_behavior=true.'
67
62
  old_assert_behavior = true
68
63
  end
69
64
  old_assert_behavior
@@ -13,6 +13,16 @@ describe Committee::RequestUnpacker do
13
13
  assert_equal({ "x" => "y" }, params)
14
14
  end
15
15
 
16
+ it "unpacks JSON on Content-Type: application/vnd.api+json" do
17
+ env = {
18
+ "CONTENT_TYPE" => "application/vnd.api+json",
19
+ "rack.input" => StringIO.new('{"x":"y"}'),
20
+ }
21
+ request = Rack::Request.new(env)
22
+ params, _ = Committee::RequestUnpacker.new(request).call
23
+ assert_equal({ "x" => "y" }, params)
24
+ end
25
+
16
26
  it "unpacks JSON on no Content-Type" do
17
27
  env = {
18
28
  "rack.input" => StringIO.new('{"x":"y"}'),
@@ -22,6 +32,16 @@ describe Committee::RequestUnpacker do
22
32
  assert_equal({ "x" => "y" }, params)
23
33
  end
24
34
 
35
+ it "doesn't unpack JSON on application/x-ndjson" do
36
+ env = {
37
+ "CONTENT_TYPE" => "application/x-ndjson",
38
+ "rack.input" => StringIO.new('{"x":"y"}\n{"a":"b"}'),
39
+ }
40
+ request = Rack::Request.new(env)
41
+ params, _ = Committee::RequestUnpacker.new(request).call
42
+ assert_equal({}, params)
43
+ end
44
+
25
45
  it "doesn't unpack JSON under other Content-Types" do
26
46
  %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
27
47
  env = {
@@ -58,6 +58,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
58
58
  }
59
59
 
60
60
  assert_match(/expected string, but received Integer: 1/i, e.message)
61
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
61
62
  end
62
63
 
63
64
  it 'support put method' do
@@ -69,6 +70,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
69
70
  }
70
71
 
71
72
  assert_match(/expected string, but received Integer: 1/i, e.message)
73
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
72
74
  end
73
75
 
74
76
  it 'support patch method' do
@@ -80,6 +82,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
80
82
  }
81
83
 
82
84
  assert_match(/expected integer, but received String: str/i, e.message)
85
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
83
86
  end
84
87
 
85
88
  it 'unknown param' do
@@ -113,6 +116,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
113
116
  }
114
117
 
115
118
  assert_match(/missing required parameters: query_string/i, e.message)
119
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
116
120
  end
117
121
 
118
122
  it 'invalid type' do
@@ -125,6 +129,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
125
129
  }
126
130
 
127
131
  assert_match(/expected string, but received Integer: 1/i, e.message)
132
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
128
133
  end
129
134
  end
130
135
 
@@ -146,6 +151,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
146
151
  }
147
152
 
148
153
  assert_match(/expected integer, but received String: a/i, e.message)
154
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
149
155
  end
150
156
  end
151
157
 
@@ -36,9 +36,10 @@ describe Committee::SchemaValidator::OpenAPI3::ResponseValidator do
36
36
 
37
37
  it "raises InvalidResponse when a valid response with no registered body with strict option" do
38
38
  @headers = { "Content-Type" => "application/xml" }
39
- assert_raises(Committee::InvalidResponse) {
39
+ e = assert_raises(Committee::InvalidResponse) {
40
40
  call_response_validator(true)
41
41
  }
42
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
42
43
  end
43
44
 
44
45
  it "passes through a valid response with no Content-Type" do
@@ -48,9 +49,10 @@ describe Committee::SchemaValidator::OpenAPI3::ResponseValidator do
48
49
 
49
50
  it "raises InvalidResponse when a valid response with no Content-Type headers with strict option" do
50
51
  @headers = {}
51
- assert_raises(Committee::InvalidResponse) {
52
+ e = assert_raises(Committee::InvalidResponse) {
52
53
  call_response_validator(true)
53
54
  }
55
+ assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
54
56
  end
55
57
 
56
58
  it "passes through a valid list response" do
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.2.0
4
+ version: 4.2.1
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-08-26 00:00:00.000000000 Z
13
+ date: 2020-11-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json_schema