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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5ca2d98a65682acdd759d0fdbb8de493cec34b96889fec3cfd18bf4928b50cc
4
- data.tar.gz: f2c50536c4bd4840dae6dc1a3da96c4a85dd2ec25ee69e55c944a90f3a514d00
3
+ metadata.gz: 07fd25d2379c9e5d324556185a1071995f394712a778f4d8ee2afda016601645
4
+ data.tar.gz: dd86ac014d3b34fc1f2d03456fe74190756084c8432858d20e01717562ff7c49
5
5
  SHA512:
6
- metadata.gz: b3f35d67aab36148b9085b0a129ee315ea41e27ed6fde96c2038830c2046a3d1d5e212feeae849cd3d4571d69b01349911826711a699d326d6e799ca725a9391
7
- data.tar.gz: 411bb7a8a21de88b9c978cb848480a2a40ebd9aab2e9819648d066d301db47420e9ccf9820c292e441c90b546d9c42ff42b0363c852e7db78e7eb902415adf6c
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
- @validators[link.status_success] = JsonSchema::Validator.new(target_schema(link))
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
- raise InvalidResponse, "Invalid response.#{@link.href} status code #{status} definition does not exist" if @validators[status].nil?
57
- if !@validators[status].validate(data)
58
- errors = JsonSchema::SchemaError.aggregate(@validators[status].errors).join("\n")
59
- raise InvalidResponse, "Invalid response.\n\n#{errors}"
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].to_s.split(';').first.to_s
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)
@@ -4,7 +4,7 @@ module Committee
4
4
  module SchemaValidator
5
5
  class << self
6
6
  def request_media_type(request)
7
- request.media_type.to_s
7
+ Rack::MediaType.type(request.env['CONTENT_TYPE'])
8
8
  end
9
9
 
10
10
  # @param [String] prefix
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Committee
4
- VERSION = '5.5.5'.freeze
4
+ VERSION = '5.6.1'.freeze
5
5
  end
@@ -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.5.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