committee 5.5.0 → 5.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/committee/bin/committee_stub.rb +1 -6
- data/lib/committee/drivers/open_api_2/driver.rb +21 -33
- data/lib/committee/drivers/open_api_2/link.rb +8 -1
- data/lib/committee/drivers/open_api_2/parameter_schema_builder.rb +1 -2
- data/lib/committee/drivers/open_api_2/schema_builder.rb +2 -5
- data/lib/committee/drivers.rb +1 -1
- data/lib/committee/errors.rb +2 -2
- data/lib/committee/middleware/base.rb +2 -2
- data/lib/committee/middleware/request_validation.rb +1 -1
- data/lib/committee/middleware/stub.rb +1 -1
- data/lib/committee/request_unpacker.rb +3 -4
- data/lib/committee/schema_validator/hyper_schema/parameter_coercer.rb +41 -41
- data/lib/committee/schema_validator/hyper_schema/request_validator.rb +1 -2
- data/lib/committee/schema_validator/hyper_schema/response_validator.rb +15 -7
- data/lib/committee/schema_validator/hyper_schema/string_params_coercer.rb +60 -60
- data/lib/committee/schema_validator/hyper_schema.rb +64 -59
- data/lib/committee/schema_validator/open_api_3/request_validator.rb +1 -1
- data/lib/committee/schema_validator/open_api_3.rb +10 -5
- data/lib/committee/schema_validator/option.rb +1 -6
- data/lib/committee/test/schema_coverage.rb +1 -7
- data/lib/committee/utils.rb +20 -20
- data/lib/committee/version.rb +1 -1
- data/test/bin/committee_stub_test.rb +1 -5
- data/test/committee_test.rb +0 -1
- data/test/drivers/hyper_schema/driver_test.rb +0 -1
- data/test/drivers/open_api_2/driver_test.rb +1 -3
- data/test/drivers/open_api_2/header_schema_builder_test.rb +1 -9
- data/test/drivers/open_api_2/link_test.rb +1 -2
- data/test/drivers/open_api_2/parameter_schema_builder_test.rb +6 -45
- data/test/drivers/open_api_3/driver_test.rb +5 -5
- data/test/drivers_test.rb +19 -28
- data/test/middleware/base_test.rb +13 -36
- data/test/middleware/request_validation_open_api_3_test.rb +24 -47
- data/test/middleware/request_validation_test.rb +19 -53
- data/test/middleware/response_validation_open_api_3_test.rb +33 -25
- data/test/middleware/response_validation_test.rb +24 -15
- data/test/middleware/stub_test.rb +5 -12
- data/test/request_unpacker_test.rb +19 -66
- data/test/schema_validator/hyper_schema/parameter_coercer_test.rb +3 -3
- data/test/schema_validator/hyper_schema/request_validator_test.rb +7 -17
- data/test/schema_validator/hyper_schema/response_generator_test.rb +24 -18
- data/test/schema_validator/hyper_schema/response_validator_test.rb +3 -7
- data/test/schema_validator/hyper_schema/string_params_coercer_test.rb +2 -2
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +16 -17
- data/test/schema_validator/open_api_3/request_validator_test.rb +8 -19
- data/test/schema_validator/open_api_3/response_validator_test.rb +2 -4
- data/test/test/methods_new_version_test.rb +2 -2
- data/test/test/methods_test.rb +5 -5
- data/test/test/schema_coverage_test.rb +4 -17
- data/test/test_helper.rb +6 -13
- data/test/validation_error_test.rb +1 -5
- metadata +3 -17
@@ -28,8 +28,13 @@ module Committee
|
|
28
28
|
|
29
29
|
data = {}
|
30
30
|
unless full_body.empty?
|
31
|
-
parse_to_json =
|
32
|
-
|
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,71 @@ module Committee
|
|
42
47
|
|
43
48
|
private
|
44
49
|
|
45
|
-
|
46
|
-
|
50
|
+
def coerce_path_params
|
51
|
+
return {} unless link_exist?
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
57
|
+
def coerce_query_params(request)
|
58
|
+
return unless link_exist?
|
59
|
+
return if request.GET.nil? || link.schema.nil?
|
55
60
|
|
56
|
-
|
57
|
-
|
61
|
+
Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(request.GET, link.schema, coerce_recursive: validator_option.coerce_recursive).call!
|
62
|
+
end
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
+
optimistic_json: validator_option.optimistic_json,
|
70
|
+
)
|
71
|
+
|
72
|
+
request.env[validator_option.headers_key] = unpacker.unpack_headers(request)
|
73
|
+
|
74
|
+
# Attempts to coerce parameters that appear in a link's URL to Ruby
|
75
|
+
# types that can be validated with a schema.
|
76
|
+
param_matches_hash = validator_option.coerce_path_params ? coerce_path_params : {}
|
77
|
+
|
78
|
+
# Attempts to coerce parameters that appear in a query string to Ruby
|
79
|
+
# types that can be validated with a schema.
|
80
|
+
coerce_query_params(request) if validator_option.coerce_query_params
|
81
|
+
|
82
|
+
query_param = unpacker.unpack_query_params(request)
|
83
|
+
request_param, is_form_params = unpacker.unpack_request_params(request)
|
84
|
+
coerce_form_params(request_param) if validator_option.coerce_form_params && is_form_params
|
85
|
+
request.env[validator_option.request_body_hash_key] = request_param
|
86
|
+
|
87
|
+
request.env[validator_option.params_key] = Committee::Utils.indifferent_hash
|
88
|
+
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(query_param))
|
89
|
+
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(request_param))
|
90
|
+
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(param_matches_hash))
|
91
|
+
end
|
87
92
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
def coerce_form_params(parameter)
|
94
|
+
return unless link_exist?
|
95
|
+
return unless link.schema
|
96
|
+
Committee::SchemaValidator::HyperSchema::StringParamsCoercer.new(parameter, link.schema).call!
|
97
|
+
end
|
93
98
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
+
def request_schema_validation(request)
|
100
|
+
return unless link_exist?
|
101
|
+
validator = Committee::SchemaValidator::HyperSchema::RequestValidator.new(link, check_content_type: validator_option.check_content_type, check_header: validator_option.check_header)
|
102
|
+
validator.call(request, request.env[validator_option.params_key], request.env[validator_option.headers_key])
|
103
|
+
end
|
99
104
|
|
100
|
-
|
101
|
-
|
105
|
+
def parameter_coerce!(request, link, coerce_key)
|
106
|
+
return unless link_exist?
|
102
107
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
Committee::SchemaValidator::HyperSchema::ParameterCoercer.
|
109
|
+
new(request.env[coerce_key],
|
110
|
+
link.schema,
|
111
|
+
coerce_date_times: validator_option.coerce_date_times,
|
112
|
+
coerce_recursive: validator_option.coerce_recursive).
|
113
|
+
call!
|
114
|
+
end
|
110
115
|
end
|
111
116
|
end
|
112
117
|
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 =
|
30
|
-
|
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
|
-
|
37
|
+
full_body.empty? ? {} : JSON.parse(full_body)
|
33
38
|
else
|
34
39
|
full_body
|
35
40
|
end
|
@@ -98,8 +103,8 @@ module Committee
|
|
98
103
|
|
99
104
|
def copy_coerced_data_to_params(request)
|
100
105
|
order = if validator_option.parameter_overwrite_by_rails_rule
|
101
|
-
# (high priority) path_hash_key -> query_param -> request_body_hash
|
102
|
-
|
106
|
+
# (high priority) path_hash_key -> query_param -> request_body_hash
|
107
|
+
[validator_option.request_body_hash_key, validator_option.query_hash_key, validator_option.path_hash_key]
|
103
108
|
else
|
104
109
|
# (high priority) path_hash_key -> request_body_hash -> query_param
|
105
110
|
[validator_option.query_hash_key, validator_option.request_body_hash_key, validator_option.path_hash_key]
|
@@ -21,12 +21,7 @@ module Committee
|
|
21
21
|
:parameter_overwrite_by_rails_rule
|
22
22
|
|
23
23
|
# 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
|
24
|
+
attr_reader :headers_key, :params_key, :query_hash_key, :request_body_hash_key, :path_hash_key, :prefix
|
30
25
|
|
31
26
|
def initialize(options, schema, schema_type)
|
32
27
|
# Non-boolean options
|
@@ -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
|
-
|
data/lib/committee/utils.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Committee
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
data/lib/committee/version.rb
CHANGED
@@ -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]
|
data/test/committee_test.rb
CHANGED
@@ -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.
|
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
|