committee 5.5.5 → 5.6.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 +4 -4
- data/lib/committee/schema_validator/hyper_schema/response_validator.rb +13 -5
- data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +1 -1
- data/lib/committee/schema_validator.rb +1 -1
- data/lib/committee/version.rb +1 -1
- data/test/schema_validator/hyper_schema/response_validator_test.rb +8 -0
- data/test/schema_validator_test.rb +23 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 07fd25d2379c9e5d324556185a1071995f394712a778f4d8ee2afda016601645
|
|
4
|
+
data.tar.gz: dd86ac014d3b34fc1f2d03456fe74190756084c8432858d20e01717562ff7c49
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2226c6247449ba57f98ec7fdf69c287d797ff7aabf92de710e91d7d080e3bc8ec65b9b88a5304e549d13f023c6238343c1971f801784f8b4fc2dce6587841e49
|
|
7
|
+
data.tar.gz: 589bf4caf9cdd2ded55739c90de5db53ebd21e52b66f30d4d883289349af9553fd619fd5d4b7328c0c85e5402f274018b00d6a7ed55e2fcc608157c99d87b2ec
|
|
@@ -11,13 +11,14 @@ module Committee
|
|
|
11
11
|
@validate_success_only = options[:validate_success_only]
|
|
12
12
|
@allow_blank_structures = options[:allow_blank_structures]
|
|
13
13
|
|
|
14
|
+
@validator = nil
|
|
14
15
|
@validators = {}
|
|
15
16
|
if link.is_a? Drivers::OpenAPI2::Link
|
|
16
17
|
link.target_schemas.each do |status, schema|
|
|
17
18
|
@validators[status] = JsonSchema::Validator.new(target_schema(link))
|
|
18
19
|
end
|
|
19
20
|
else
|
|
20
|
-
@
|
|
21
|
+
@validator = JsonSchema::Validator.new(target_schema(link))
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
|
|
@@ -53,10 +54,17 @@ module Committee
|
|
|
53
54
|
|
|
54
55
|
begin
|
|
55
56
|
if Committee::Middleware::ResponseValidation.validate?(status, validate_success_only)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
if @link.is_a?(Drivers::OpenAPI2::Link)
|
|
58
|
+
raise InvalidResponse, "Invalid response.#{@link.href} status code #{status} definition does not exist" if @validators[status].nil?
|
|
59
|
+
if !@validators[status].validate(data)
|
|
60
|
+
errors = JsonSchema::SchemaError.aggregate(@validators[status].errors).join("\n")
|
|
61
|
+
raise InvalidResponse, "Invalid response.\n\n#{errors}"
|
|
62
|
+
end
|
|
63
|
+
else
|
|
64
|
+
if !@validator.validate(data)
|
|
65
|
+
errors = JsonSchema::SchemaError.aggregate(@validator.errors).join("\n")
|
|
66
|
+
raise InvalidResponse, "Invalid response.\n\n#{errors}"
|
|
67
|
+
end
|
|
60
68
|
end
|
|
61
69
|
end
|
|
62
70
|
rescue => e
|
|
@@ -111,7 +111,7 @@ module Committee
|
|
|
111
111
|
|
|
112
112
|
def validate_post_request_params(path_params, query_params, body_params, headers, validator_option)
|
|
113
113
|
content_type_key = headers.keys.detect { |k| k.casecmp?('Content-Type') }
|
|
114
|
-
content_type = headers[content_type_key]
|
|
114
|
+
content_type = Rack::MediaType.type(headers[content_type_key])
|
|
115
115
|
|
|
116
116
|
# bad performance because when we coerce value, same check
|
|
117
117
|
validate_path_and_query_params(path_params, query_params, headers, validator_option)
|
data/lib/committee/version.rb
CHANGED
|
@@ -9,6 +9,8 @@ describe Committee::SchemaValidator::HyperSchema::ResponseValidator do
|
|
|
9
9
|
@data = ValidApp.dup
|
|
10
10
|
@schema = JsonSchema.parse!(hyper_schema_data)
|
|
11
11
|
@schema.expand_references!
|
|
12
|
+
# POST /apps
|
|
13
|
+
@create_link = @schema.properties["app"].links[0]
|
|
12
14
|
# GET /apps/:id
|
|
13
15
|
@get_link = @link = @schema.properties["app"].links[2]
|
|
14
16
|
# GET /apps
|
|
@@ -41,6 +43,12 @@ describe Committee::SchemaValidator::HyperSchema::ResponseValidator do
|
|
|
41
43
|
call
|
|
42
44
|
end
|
|
43
45
|
|
|
46
|
+
it "allows non-201 on create" do
|
|
47
|
+
@link = @create_link
|
|
48
|
+
@status = 200
|
|
49
|
+
call
|
|
50
|
+
end
|
|
51
|
+
|
|
44
52
|
it "passes through a valid list response for for rel instances links" do
|
|
45
53
|
@link = @list_link
|
|
46
54
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
describe Committee::SchemaValidator do
|
|
6
|
+
it "parses simple content types" do
|
|
7
|
+
request = Rack::Request.new({ "CONTENT_TYPE" => "application/json" })
|
|
8
|
+
media_type = Committee::SchemaValidator.request_media_type(request)
|
|
9
|
+
assert_equal 'application/json', media_type
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "parses comma-delineated content types" do
|
|
13
|
+
request = Rack::Request.new({ "CONTENT_TYPE" => "multipart/form-data, application/json" })
|
|
14
|
+
media_type = Committee::SchemaValidator.request_media_type(request)
|
|
15
|
+
assert_equal 'multipart/form-data', media_type
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "parses semicolon-delineated content types" do
|
|
19
|
+
request = Rack::Request.new({ "CONTENT_TYPE" => "multipart/form-data; application/json" })
|
|
20
|
+
media_type = Committee::SchemaValidator.request_media_type(request)
|
|
21
|
+
assert_equal 'multipart/form-data', media_type
|
|
22
|
+
end
|
|
23
|
+
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: 5.
|
|
4
|
+
version: 5.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brandur
|
|
@@ -239,6 +239,7 @@ files:
|
|
|
239
239
|
- test/schema_validator/open_api_3/operation_wrapper_test.rb
|
|
240
240
|
- test/schema_validator/open_api_3/request_validator_test.rb
|
|
241
241
|
- test/schema_validator/open_api_3/response_validator_test.rb
|
|
242
|
+
- test/schema_validator_test.rb
|
|
242
243
|
- test/test/methods_new_version_test.rb
|
|
243
244
|
- test/test/methods_test.rb
|
|
244
245
|
- test/test/schema_coverage_test.rb
|