committee 5.5.0 → 5.5.2

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/committee/bin/committee_stub.rb +1 -6
  3. data/lib/committee/drivers/open_api_2/driver.rb +21 -33
  4. data/lib/committee/drivers/open_api_2/link.rb +8 -1
  5. data/lib/committee/drivers/open_api_2/parameter_schema_builder.rb +1 -2
  6. data/lib/committee/drivers/open_api_2/schema_builder.rb +2 -5
  7. data/lib/committee/drivers.rb +1 -1
  8. data/lib/committee/errors.rb +2 -2
  9. data/lib/committee/middleware/base.rb +2 -2
  10. data/lib/committee/middleware/request_validation.rb +1 -1
  11. data/lib/committee/middleware/stub.rb +1 -1
  12. data/lib/committee/request_unpacker.rb +17 -9
  13. data/lib/committee/schema_validator/hyper_schema/parameter_coercer.rb +41 -41
  14. data/lib/committee/schema_validator/hyper_schema/request_validator.rb +1 -2
  15. data/lib/committee/schema_validator/hyper_schema/response_validator.rb +15 -7
  16. data/lib/committee/schema_validator/hyper_schema/string_params_coercer.rb +60 -60
  17. data/lib/committee/schema_validator/hyper_schema.rb +65 -59
  18. data/lib/committee/schema_validator/open_api_3/request_validator.rb +1 -1
  19. data/lib/committee/schema_validator/open_api_3.rb +11 -5
  20. data/lib/committee/schema_validator/option.rb +3 -6
  21. data/lib/committee/test/schema_coverage.rb +1 -7
  22. data/lib/committee/utils.rb +20 -20
  23. data/lib/committee/version.rb +1 -1
  24. data/test/bin/committee_stub_test.rb +1 -5
  25. data/test/committee_test.rb +0 -1
  26. data/test/drivers/hyper_schema/driver_test.rb +0 -1
  27. data/test/drivers/open_api_2/driver_test.rb +1 -3
  28. data/test/drivers/open_api_2/header_schema_builder_test.rb +1 -9
  29. data/test/drivers/open_api_2/link_test.rb +1 -2
  30. data/test/drivers/open_api_2/parameter_schema_builder_test.rb +6 -45
  31. data/test/drivers/open_api_3/driver_test.rb +5 -5
  32. data/test/drivers_test.rb +19 -28
  33. data/test/middleware/base_test.rb +13 -36
  34. data/test/middleware/request_validation_open_api_3_test.rb +24 -47
  35. data/test/middleware/request_validation_test.rb +19 -53
  36. data/test/middleware/response_validation_open_api_3_test.rb +33 -25
  37. data/test/middleware/response_validation_test.rb +24 -15
  38. data/test/middleware/stub_test.rb +5 -12
  39. data/test/request_unpacker_test.rb +26 -66
  40. data/test/schema_validator/hyper_schema/parameter_coercer_test.rb +3 -3
  41. data/test/schema_validator/hyper_schema/request_validator_test.rb +7 -17
  42. data/test/schema_validator/hyper_schema/response_generator_test.rb +24 -18
  43. data/test/schema_validator/hyper_schema/response_validator_test.rb +3 -7
  44. data/test/schema_validator/hyper_schema/string_params_coercer_test.rb +2 -2
  45. data/test/schema_validator/open_api_3/operation_wrapper_test.rb +16 -17
  46. data/test/schema_validator/open_api_3/request_validator_test.rb +8 -19
  47. data/test/schema_validator/open_api_3/response_validator_test.rb +2 -4
  48. data/test/test/methods_new_version_test.rb +2 -2
  49. data/test/test/methods_test.rb +5 -5
  50. data/test/test/schema_coverage_test.rb +4 -17
  51. data/test/test_helper.rb +6 -13
  52. data/test/validation_error_test.rb +1 -5
  53. metadata +3 -17
@@ -28,8 +28,13 @@ module Committee
28
28
 
29
29
  data = {}
30
30
  unless full_body.empty?
31
- parse_to_json = !validator_option.parse_response_by_content_type ||
32
- headers.fetch('Content-Type', nil)&.start_with?('application/json')
31
+ parse_to_json = if validator_option.parse_response_by_content_type
32
+ content_type_key = headers.keys.detect { |k| k.casecmp?('Content-Type') }
33
+ headers.fetch(content_type_key, nil)&.start_with?('application/json')
34
+ else
35
+ true
36
+ end
37
+
33
38
  data = JSON.parse(full_body) if parse_to_json
34
39
  end
35
40
 
@@ -42,71 +47,72 @@ module Committee
42
47
 
43
48
  private
44
49
 
45
- def coerce_path_params
46
- return {} unless link_exist?
50
+ def coerce_path_params
51
+ return {} unless link_exist?
47
52
 
48
- Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(param_matches, link.schema, coerce_recursive: validator_option.coerce_recursive).call!
49
- param_matches
50
- end
53
+ Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(param_matches, link.schema, coerce_recursive: validator_option.coerce_recursive).call!
54
+ param_matches
55
+ end
51
56
 
52
- def coerce_query_params(request)
53
- return unless link_exist?
54
- return if request.GET.nil? || link.schema.nil?
57
+ def coerce_query_params(request)
58
+ return unless link_exist?
59
+ return if request.GET.nil? || link.schema.nil?
55
60
 
56
- Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(request.GET, link.schema, coerce_recursive: validator_option.coerce_recursive).call!
57
- end
61
+ Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(request.GET, link.schema, coerce_recursive: validator_option.coerce_recursive).call!
62
+ end
58
63
 
59
- def request_unpack(request)
60
- unpacker = Committee::RequestUnpacker.new(
61
- allow_form_params: validator_option.allow_form_params,
62
- allow_get_body: validator_option.allow_get_body,
63
- allow_query_params: validator_option.allow_query_params,
64
- optimistic_json: validator_option.optimistic_json,
65
- )
66
-
67
- request.env[validator_option.headers_key] = unpacker.unpack_headers(request)
68
-
69
- # Attempts to coerce parameters that appear in a link's URL to Ruby
70
- # types that can be validated with a schema.
71
- param_matches_hash = validator_option.coerce_path_params ? coerce_path_params : {}
72
-
73
- # Attempts to coerce parameters that appear in a query string to Ruby
74
- # types that can be validated with a schema.
75
- coerce_query_params(request) if validator_option.coerce_query_params
76
-
77
- query_param = unpacker.unpack_query_params(request)
78
- request_param, is_form_params = unpacker.unpack_request_params(request)
79
- coerce_form_params(request_param) if validator_option.coerce_form_params && is_form_params
80
- request.env[validator_option.request_body_hash_key] = request_param
81
-
82
- request.env[validator_option.params_key] = Committee::Utils.indifferent_hash
83
- request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(query_param))
84
- request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(request_param))
85
- request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(param_matches_hash))
86
- end
64
+ def request_unpack(request)
65
+ unpacker = Committee::RequestUnpacker.new(
66
+ allow_form_params: validator_option.allow_form_params,
67
+ allow_get_body: validator_option.allow_get_body,
68
+ allow_query_params: validator_option.allow_query_params,
69
+ allow_non_get_query_params: validator_option.allow_non_get_query_params,
70
+ optimistic_json: validator_option.optimistic_json,
71
+ )
72
+
73
+ request.env[validator_option.headers_key] = unpacker.unpack_headers(request)
74
+
75
+ # Attempts to coerce parameters that appear in a link's URL to Ruby
76
+ # types that can be validated with a schema.
77
+ param_matches_hash = validator_option.coerce_path_params ? coerce_path_params : {}
78
+
79
+ # Attempts to coerce parameters that appear in a query string to Ruby
80
+ # types that can be validated with a schema.
81
+ coerce_query_params(request) if validator_option.coerce_query_params
82
+
83
+ query_param = unpacker.unpack_query_params(request)
84
+ request_param, is_form_params = unpacker.unpack_request_params(request)
85
+ coerce_form_params(request_param) if validator_option.coerce_form_params && is_form_params
86
+ request.env[validator_option.request_body_hash_key] = request_param
87
+
88
+ request.env[validator_option.params_key] = Committee::Utils.indifferent_hash
89
+ request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(query_param))
90
+ request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(request_param))
91
+ request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(param_matches_hash))
92
+ end
87
93
 
88
- def coerce_form_params(parameter)
89
- return unless link_exist?
90
- return unless link.schema
91
- Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(parameter, link.schema).call!
92
- end
94
+ def coerce_form_params(parameter)
95
+ return unless link_exist?
96
+ return unless link.schema
97
+ Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(parameter, link.schema).call!
98
+ end
93
99
 
94
- def request_schema_validation(request)
95
- return unless link_exist?
96
- validator = Committee::SchemaValidator::HyperSchema::RequestValidator.new(link, check_content_type: validator_option.check_content_type, check_header: validator_option.check_header)
97
- validator.call(request, request.env[validator_option.params_key], request.env[validator_option.headers_key])
98
- end
100
+ def request_schema_validation(request)
101
+ return unless link_exist?
102
+ validator = Committee::SchemaValidator::HyperSchema::RequestValidator.new(link, check_content_type: validator_option.check_content_type, check_header: validator_option.check_header)
103
+ validator.call(request, request.env[validator_option.params_key], request.env[validator_option.headers_key])
104
+ end
99
105
 
100
- def parameter_coerce!(request, link, coerce_key)
101
- return unless link_exist?
106
+ def parameter_coerce!(request, link, coerce_key)
107
+ return unless link_exist?
102
108
 
103
- Committee::SchemaValidator::HyperSchema::ParameterCoercer.
104
- new(request.env[coerce_key],
105
- link.schema,
106
- coerce_date_times: validator_option.coerce_date_times,
107
- coerce_recursive: validator_option.coerce_recursive).
108
- call!
109
- end
109
+ Committee::SchemaValidator::HyperSchema::ParameterCoercer.
110
+ new(request.env[coerce_key],
111
+ link.schema,
112
+ coerce_date_times: validator_option.coerce_date_times,
113
+ coerce_recursive: validator_option.coerce_recursive).
114
+ call!
115
+ end
110
116
  end
111
117
  end
112
118
  end
@@ -27,7 +27,7 @@ module Committee
27
27
  return true if @operation_object.optional_body? && empty_request?(request)
28
28
 
29
29
  message = if valid_content_types.size > 1
30
- types = valid_content_types.map {|x| %{"#{x}"} }.join(', ')
30
+ types = valid_content_types.map { |x| %{"#{x}"} }.join(', ')
31
31
  %{"Content-Type" request header must be set to any of the following: [#{types}].}
32
32
  else
33
33
  %{"Content-Type" request header must be set to "#{valid_content_types.first}".}
@@ -26,10 +26,15 @@ module Committee
26
26
  full_body << chunk
27
27
  end
28
28
 
29
- parse_to_json = !validator_option.parse_response_by_content_type ||
30
- headers.fetch('Content-Type', nil)&.start_with?('application/json')
29
+ parse_to_json = if validator_option.parse_response_by_content_type
30
+ content_type_key = headers.keys.detect { |k| k.casecmp?('Content-Type') }
31
+ headers.fetch(content_type_key, nil)&.start_with?('application/json')
32
+ else
33
+ true
34
+ end
35
+
31
36
  data = if parse_to_json
32
- full_body.empty? ? {} : JSON.parse(full_body)
37
+ full_body.empty? ? {} : JSON.parse(full_body)
33
38
  else
34
39
  full_body
35
40
  end
@@ -82,6 +87,7 @@ module Committee
82
87
  allow_form_params: validator_option.allow_form_params,
83
88
  allow_get_body: validator_option.allow_get_body,
84
89
  allow_query_params: validator_option.allow_query_params,
90
+ allow_non_get_query_params: validator_option.allow_non_get_query_params,
85
91
  optimistic_json: validator_option.optimistic_json,
86
92
  )
87
93
 
@@ -98,8 +104,8 @@ module Committee
98
104
 
99
105
  def copy_coerced_data_to_params(request)
100
106
  order = if validator_option.parameter_overwrite_by_rails_rule
101
- # (high priority) path_hash_key -> query_param -> request_body_hash
102
- [validator_option.request_body_hash_key, validator_option.query_hash_key, validator_option.path_hash_key]
107
+ # (high priority) path_hash_key -> query_param -> request_body_hash
108
+ [validator_option.request_body_hash_key, validator_option.query_hash_key, validator_option.path_hash_key]
103
109
  else
104
110
  # (high priority) path_hash_key -> request_body_hash -> query_param
105
111
  [validator_option.query_hash_key, validator_option.request_body_hash_key, validator_option.path_hash_key]
@@ -8,6 +8,7 @@ module Committee
8
8
  :allow_form_params,
9
9
  :allow_get_body,
10
10
  :allow_query_params,
11
+ :allow_non_get_query_params,
11
12
  :check_content_type,
12
13
  :check_header,
13
14
  :coerce_date_times,
@@ -21,12 +22,7 @@ module Committee
21
22
  :parameter_overwrite_by_rails_rule
22
23
 
23
24
  # Non-boolean options:
24
- attr_reader :headers_key,
25
- :params_key,
26
- :query_hash_key,
27
- :request_body_hash_key,
28
- :path_hash_key,
29
- :prefix
25
+ attr_reader :headers_key, :params_key, :query_hash_key, :request_body_hash_key, :path_hash_key, :prefix
30
26
 
31
27
  def initialize(options, schema, schema_type)
32
28
  # Non-boolean options
@@ -42,6 +38,7 @@ module Committee
42
38
  @allow_blank_structures = options.fetch(:allow_blank_structures, false)
43
39
  @allow_form_params = options.fetch(:allow_form_params, true)
44
40
  @allow_query_params = options.fetch(:allow_query_params, true)
41
+ @allow_non_get_query_params = options.fetch(:allow_non_get_query_params, false)
45
42
  @check_content_type = options.fetch(:check_content_type, true)
46
43
  @check_header = options.fetch(:check_header, true)
47
44
  @coerce_recursive = options.fetch(:coerce_recursive, true)
@@ -28,12 +28,7 @@ module Committee
28
28
  path_coverage.each do |method, method_coverage|
29
29
  responses_coverage = method_coverage['responses']
30
30
  responses_coverage.each do |response_status, is_covered|
31
- responses << {
32
- path: path_name,
33
- method: method,
34
- status: response_status,
35
- is_covered: is_covered,
36
- }
31
+ responses << { path: path_name, method: method, status: response_status, is_covered: is_covered, }
37
32
  end
38
33
  end
39
34
  end
@@ -98,4 +93,3 @@ module Committee
98
93
  end
99
94
  end
100
95
  end
101
-
@@ -1,28 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Committee
4
- module Utils
5
- # Creates a Hash with indifferent access.
6
- #
7
- # (Copied from Sinatra)
8
- def self.indifferent_hash
9
- Hash.new { |hash,key| hash[key.to_s] if Symbol === key }
10
- end
11
-
12
- def self.deep_copy(from)
13
- if from.is_a?(Hash)
14
- h = Committee::Utils.indifferent_hash
15
- from.each_pair do |k, v|
16
- h[k] = deep_copy(v)
17
- end
18
- return h
19
- end
4
+ module Utils
5
+ # Creates a Hash with indifferent access.
6
+ #
7
+ # (Copied from Sinatra)
8
+ def self.indifferent_hash
9
+ Hash.new { |hash, key| hash[key.to_s] if Symbol === key }
10
+ end
20
11
 
21
- if from.is_a?(Array)
22
- return from.map{ |v| deep_copy(v) }
23
- end
12
+ def self.deep_copy(from)
13
+ if from.is_a?(Hash)
14
+ h = Committee::Utils.indifferent_hash
15
+ from.each_pair do |k, v|
16
+ h[k] = deep_copy(v)
17
+ end
18
+ return h
19
+ end
24
20
 
25
- return from
21
+ if from.is_a?(Array)
22
+ return from.map { |v| deep_copy(v) }
26
23
  end
24
+
25
+ return from
27
26
  end
27
+ end
28
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Committee
4
- VERSION = '5.5.0'.freeze
4
+ VERSION = '5.5.2'.freeze
5
5
  end
@@ -18,11 +18,7 @@ describe Committee::Bin::CommitteeStub do
18
18
  parser.parse!(["--help"])
19
19
  assert_equal true, options[:help]
20
20
 
21
- parser.parse!([
22
- "--driver", "open_api_2",
23
- "--tolerant", "true",
24
- "--port", "1234"
25
- ])
21
+ parser.parse!(["--driver", "open_api_2", "--tolerant", "true", "--port", "1234"])
26
22
  assert_equal :open_api_2, options[:driver]
27
23
  assert_equal true, options[:tolerant]
28
24
  assert_equal "1234", options[:port]
@@ -62,7 +62,6 @@ describe Committee do
62
62
  end
63
63
  end
64
64
 
65
-
66
65
  it "doesn't warns on deprecated if cond is false" do
67
66
  old_stderr = $stderr
68
67
  old_verbose = $VERBOSE
@@ -46,4 +46,3 @@ describe Committee::Drivers::HyperSchema::Driver do
46
46
  assert_equal false, @driver.default_query_params
47
47
  end
48
48
  end
49
-
@@ -46,8 +46,7 @@ describe Committee::Drivers::OpenAPI2::Driver do
46
46
 
47
47
  it "names capture groups into href regexes" do
48
48
  schema = @driver.parse(open_api_2_data)
49
- assert_equal %r{^\/api\/pets\/(?<id>[^\/]+)$}.inspect,
50
- schema.routes["DELETE"][0][0].inspect
49
+ assert_equal %r{^\/api\/pets\/(?<id>[^\/]+)$}.inspect, schema.routes["DELETE"][0][0].inspect
51
50
  end
52
51
 
53
52
  it "prefers a 200 response first" do
@@ -153,4 +152,3 @@ describe Committee::Drivers::OpenAPI2::Driver do
153
152
  }
154
153
  end
155
154
  end
156
-
@@ -4,15 +4,7 @@ require "test_helper"
4
4
 
5
5
  describe Committee::Drivers::OpenAPI2::HeaderSchemaBuilder do
6
6
  it "returns schema data for header" do
7
- data = {
8
- "parameters" => [
9
- {
10
- "name" => "AUTH_TOKEN",
11
- "type" => "string",
12
- "in" => "header",
13
- }
14
- ]
15
- }
7
+ data = { "parameters" => [{ "name" => "AUTH_TOKEN", "type" => "string", "in" => "header", }] }
16
8
  schema = call(data)
17
9
 
18
10
  assert_equal ["string"], schema.properties["AUTH_TOKEN"].type
@@ -11,7 +11,7 @@ describe Committee::Drivers::OpenAPI2::Link do
11
11
  @link.method = "GET"
12
12
  @link.status_success = 200
13
13
  @link.schema = { "title" => "input" }
14
- @link.target_schema = { "title" => "target" }
14
+ @link.target_schemas = { 200 => { "title" => "target" } }
15
15
  end
16
16
 
17
17
  it "uses set #enc_type" do
@@ -49,4 +49,3 @@ describe Committee::Drivers::OpenAPI2::Link do
49
49
  assert_equal({ "title" => "target" }, @link.target_schema)
50
50
  end
51
51
  end
52
-
@@ -7,14 +7,7 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
7
7
  end
8
8
 
9
9
  it "reflects a basic type into a schema" do
10
- data = {
11
- "parameters" => [
12
- {
13
- "name" => "limit",
14
- "type" => "integer",
15
- }
16
- ]
17
- }
10
+ data = { "parameters" => [{ "name" => "limit", "type" => "integer", }] }
18
11
  schema, schema_data = call(data)
19
12
 
20
13
  assert_nil schema_data
@@ -37,14 +30,7 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
37
30
  end
38
31
 
39
32
  it "reflects a required property into a schema" do
40
- data = {
41
- "parameters" => [
42
- {
43
- "name" => "limit",
44
- "required" => true,
45
- }
46
- ]
47
- }
33
+ data = { "parameters" => [{ "name" => "limit", "required" => true, }] }
48
34
  schema, schema_data = call(data)
49
35
 
50
36
  assert_nil schema_data
@@ -77,15 +63,7 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
77
63
  end
78
64
 
79
65
  it "reflects a enum property into a schema" do
80
- data = {
81
- "parameters" => [
82
- {
83
- "name" => "type",
84
- "type" => "string",
85
- "enum" => ["hoge", "fuga"]
86
- }
87
- ]
88
- }
66
+ data = { "parameters" => [{ "name" => "type", "type" => "string", "enum" => ["hoge", "fuga"] }] }
89
67
  schema, schema_data = call(data)
90
68
 
91
69
  assert_nil schema_data
@@ -157,12 +135,7 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
157
135
  end
158
136
 
159
137
  it "requires that certain fields are present" do
160
- data = {
161
- "parameters" => [
162
- {
163
- }
164
- ]
165
- }
138
+ data = { "parameters" => [{}] }
166
139
  e = assert_raises ArgumentError do
167
140
  call(data)
168
141
  end
@@ -170,23 +143,11 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
170
143
  end
171
144
 
172
145
  it "requires that body parameters not be mixed with form parameters" do
173
- data = {
174
- "parameters" => [
175
- {
176
- "name" => "payload",
177
- "in" => "body",
178
- },
179
- {
180
- "name" => "limit",
181
- "in" => "form",
182
- },
183
- ]
184
- }
146
+ data = { "parameters" => [{ "name" => "payload", "in" => "body", }, { "name" => "limit", "in" => "form", },] }
185
147
  e = assert_raises ArgumentError do
186
148
  call(data)
187
149
  end
188
- assert_equal "Committee: can't mix body parameter with form parameters.",
189
- e.message
150
+ assert_equal "Committee: can't mix body parameter with form parameters.", e.message
190
151
  end
191
152
 
192
153
  def call(data)
@@ -52,31 +52,31 @@ describe Committee::Drivers::OpenAPI3::Driver do
52
52
  it "gets a nested template path" do
53
53
  obj = open_api_3_schema.operation_object("/path_template_test/abc/nested", "get")
54
54
  assert_equal "/path_template_test/{template_name}/nested", obj.original_path
55
- assert_equal({"template_name"=>"abc"}, obj.path_params)
55
+ assert_equal({ "template_name" => "abc" }, obj.path_params)
56
56
  end
57
57
 
58
58
  it "gets a double nested template path" do
59
59
  obj = open_api_3_schema.operation_object("/path_template_test/test/nested/abc", "get")
60
60
  assert_equal "/path_template_test/{template_name}/nested/{nested_parameter}", obj.original_path
61
- assert_equal({"template_name"=>"test", "nested_parameter" => "abc"}, obj.path_params)
61
+ assert_equal({ "template_name" => "test", "nested_parameter" => "abc" }, obj.path_params)
62
62
  end
63
63
 
64
64
  it "gets a twice nested template path" do
65
65
  obj = open_api_3_schema.operation_object("/path_template_test/test/abc", "get")
66
66
  assert_equal "/path_template_test/{template_name}/{nested_parameter}", obj.original_path
67
- assert_equal({"template_name"=>"test", "nested_parameter" => "abc"}, obj.path_params)
67
+ assert_equal({ "template_name" => "test", "nested_parameter" => "abc" }, obj.path_params)
68
68
  end
69
69
 
70
70
  it "gets a twice nested concrete path" do
71
71
  obj = open_api_3_schema.operation_object("/path_template_test/test/abc/finish", "get")
72
72
  assert_equal "/path_template_test/{template_name}/{nested_parameter}/finish", obj.original_path
73
- assert_equal({"template_name"=>"test", "nested_parameter" => "abc"}, obj.path_params)
73
+ assert_equal({ "template_name" => "test", "nested_parameter" => "abc" }, obj.path_params)
74
74
  end
75
75
 
76
76
  it "gets an ambiguous path" do
77
77
  obj = open_api_3_schema.operation_object("/ambiguous/no_template", "get")
78
78
  assert_equal "/{ambiguous}/no_template", obj.original_path
79
- assert_equal({"ambiguous"=>"ambiguous"}, obj.path_params)
79
+ assert_equal({ "ambiguous" => "ambiguous" }, obj.path_params)
80
80
  end
81
81
  end
82
82
  end
data/test/drivers_test.rb CHANGED
@@ -3,11 +3,7 @@
3
3
  require "test_helper"
4
4
 
5
5
  describe Committee::Drivers do
6
- DRIVERS = [
7
- :hyper_schema,
8
- :open_api_2,
9
- :open_api_3,
10
- ].freeze
6
+ DRIVERS = [:hyper_schema, :open_api_2, :open_api_3,].freeze
11
7
 
12
8
  it "gets driver with .driver_from_name" do
13
9
  DRIVERS.each do |name|
@@ -37,20 +33,20 @@ describe Committee::Drivers do
37
33
  end
38
34
 
39
35
  it 'loads OpenAPI 3' do
40
- s = Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true})
36
+ s = Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true })
41
37
  assert_kind_of Committee::Drivers::Schema, s
42
38
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
43
39
  end
44
40
 
45
41
  it 'load OpenAPI 3 (patch version 3.0.1)' do
46
- s = Committee::Drivers.load_from_file(open_api_3_0_1_schema_path, parser_options:{strict_reference_validation: true})
42
+ s = Committee::Drivers.load_from_file(open_api_3_0_1_schema_path, parser_options: { strict_reference_validation: true })
47
43
  assert_kind_of Committee::Drivers::Schema, s
48
44
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
49
45
  end
50
46
 
51
47
  it 'fails to load OpenAPI 3.1+' do
52
48
  e = assert_raises(Committee::OpenAPI3Unsupported) do
53
- Committee::Drivers.load_from_file(open_api_3_1_schema_path, parser_options:{strict_reference_validation: true})
49
+ Committee::Drivers.load_from_file(open_api_3_1_schema_path, parser_options: { strict_reference_validation: true })
54
50
  end
55
51
  assert_equal 'Committee does not support OpenAPI 3.1+ yet', e.message
56
52
  end
@@ -64,13 +60,13 @@ describe Committee::Drivers do
64
60
 
65
61
  # This test can be removed when the test above (raising on invalid reference) becomes default behavior?
66
62
  it 'allows loading OpenAPI 3 with invalid reference as existing behavior' do
67
- s = Committee::Drivers.load_from_file(open_api_3_invalid_reference_path, parser_options:{strict_reference_validation: false})
63
+ s = Committee::Drivers.load_from_file(open_api_3_invalid_reference_path, parser_options: { strict_reference_validation: false })
68
64
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
69
65
  end
70
66
 
71
67
  it 'errors on an unsupported file extension' do
72
68
  e = assert_raises(StandardError) do
73
- Committee::Drivers.load_from_file('test.xml', parser_options:{strict_reference_validation: true})
69
+ Committee::Drivers.load_from_file('test.xml', parser_options: { strict_reference_validation: true })
74
70
  end
75
71
  assert_equal "Committee only supports the following file extensions: '.json', '.yaml', '.yml'", e.message
76
72
  end
@@ -79,24 +75,24 @@ describe Committee::Drivers do
79
75
  describe 'when loading the same file' do
80
76
  it 'returns the same object when the options are identical' do
81
77
  assert_equal(
82
- Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
83
- Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
78
+ Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
79
+ Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
84
80
  )
85
81
  end
86
82
 
87
83
  it 'returns different objects if the options are different' do
88
84
  refute_equal(
89
- Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
90
- Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: false}).object_id,
85
+ Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
86
+ Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: false }).object_id,
91
87
  )
92
88
  end
93
89
 
94
90
  it 'returns different objects if the file contents have changed' do
95
- object_id = Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id
91
+ object_id = Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id
96
92
  original_file_contents = File.read(open_api_3_schema_path)
97
93
  File.write(open_api_3_schema_path, original_file_contents + "\n")
98
94
  refute_equal(
99
- Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
95
+ Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
100
96
  object_id,
101
97
  )
102
98
  File.write(open_api_3_schema_path, original_file_contents)
@@ -107,13 +103,13 @@ describe Committee::Drivers do
107
103
 
108
104
  describe 'load_from_json(schema_path)' do
109
105
  it 'loads OpenAPI2' do
110
- s = Committee::Drivers.load_from_json(open_api_2_schema_path, parser_options:{strict_reference_validation: true})
106
+ s = Committee::Drivers.load_from_json(open_api_2_schema_path, parser_options: { strict_reference_validation: true })
111
107
  assert_kind_of Committee::Drivers::Schema, s
112
108
  assert_kind_of Committee::Drivers::OpenAPI2::Schema, s
113
109
  end
114
110
 
115
111
  it 'loads Hyper-Schema' do
116
- s = Committee::Drivers.load_from_json(hyper_schema_schema_path, parser_options:{strict_reference_validation: true})
112
+ s = Committee::Drivers.load_from_json(hyper_schema_schema_path, parser_options: { strict_reference_validation: true })
117
113
  assert_kind_of Committee::Drivers::Schema, s
118
114
  assert_kind_of Committee::Drivers::HyperSchema::Schema, s
119
115
  end
@@ -121,7 +117,7 @@ describe Committee::Drivers do
121
117
 
122
118
  describe 'load_from_yaml(schema_path)' do
123
119
  it 'loads OpenAPI3' do
124
- s = Committee::Drivers.load_from_yaml(open_api_3_schema_path, parser_options:{strict_reference_validation: true})
120
+ s = Committee::Drivers.load_from_yaml(open_api_3_schema_path, parser_options: { strict_reference_validation: true })
125
121
  assert_kind_of Committee::Drivers::Schema, s
126
122
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
127
123
  end
@@ -129,7 +125,7 @@ describe Committee::Drivers do
129
125
 
130
126
  describe 'load_from_data(schema_path)' do
131
127
  it 'loads OpenAPI3' do
132
- s = Committee::Drivers.load_from_data(open_api_3_data, parser_options:{strict_reference_validation: false})
128
+ s = Committee::Drivers.load_from_data(open_api_3_data, parser_options: { strict_reference_validation: false })
133
129
  assert_kind_of Committee::Drivers::Schema, s
134
130
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
135
131
  end
@@ -172,17 +168,13 @@ describe Committee::Drivers::Driver do
172
168
  e = assert_raises do
173
169
  driver.send(name, *args)
174
170
  end
175
- assert_equal "needs implementation", e.message,
176
- "Incorrect error message while sending #{name}: #{e.message}"
171
+ assert_equal "needs implementation", e.message, "Incorrect error message while sending #{name}: #{e.message}"
177
172
  end
178
173
  end
179
174
  end
180
175
 
181
176
  describe Committee::Drivers::Schema do
182
- SCHEMA_METHODS = {
183
- driver: [],
184
- build_router: [validator_option: nil, prefix: nil]
185
- }
177
+ SCHEMA_METHODS = { driver: [], build_router: [validator_option: nil, prefix: nil] }
186
178
 
187
179
  it "has a set of abstract methods" do
188
180
  schema = Committee::Drivers::Schema.new
@@ -190,8 +182,7 @@ describe Committee::Drivers::Schema do
190
182
  e = assert_raises do
191
183
  schema.send(name, *args)
192
184
  end
193
- assert_equal "needs implementation", e.message,
194
- "Incorrect error message while sending #{name}: #{e.message}"
185
+ assert_equal "needs implementation", e.message, "Incorrect error message while sending #{name}: #{e.message}"
195
186
  end
196
187
  end
197
188
  end