committee 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/committee-stub +1 -0
- data/lib/committee.rb +12 -34
- data/lib/committee/bin/committee_stub.rb +6 -4
- data/lib/committee/drivers.rb +15 -67
- data/lib/committee/drivers/driver.rb +47 -0
- data/lib/committee/drivers/hyper_schema.rb +8 -171
- data/lib/committee/drivers/hyper_schema/driver.rb +105 -0
- data/lib/committee/drivers/hyper_schema/link.rb +68 -0
- data/lib/committee/drivers/hyper_schema/schema.rb +22 -0
- data/lib/committee/drivers/open_api_2.rb +9 -416
- data/lib/committee/drivers/open_api_2/driver.rb +253 -0
- data/lib/committee/drivers/open_api_2/header_schema_builder.rb +33 -0
- data/lib/committee/drivers/open_api_2/link.rb +36 -0
- data/lib/committee/drivers/open_api_2/parameter_schema_builder.rb +83 -0
- data/lib/committee/drivers/open_api_2/schema.rb +26 -0
- data/lib/committee/drivers/open_api_2/schema_builder.rb +33 -0
- data/lib/committee/drivers/open_api_3.rb +7 -75
- data/lib/committee/drivers/open_api_3/driver.rb +51 -0
- data/lib/committee/drivers/open_api_3/schema.rb +41 -0
- data/lib/committee/drivers/schema.rb +23 -0
- data/lib/committee/errors.rb +2 -0
- data/lib/committee/middleware.rb +11 -0
- data/lib/committee/middleware/base.rb +38 -34
- data/lib/committee/middleware/request_validation.rb +51 -30
- data/lib/committee/middleware/response_validation.rb +49 -26
- data/lib/committee/middleware/stub.rb +55 -51
- data/lib/committee/request_unpacker.rb +3 -1
- data/lib/committee/schema_validator.rb +23 -0
- data/lib/committee/schema_validator/hyper_schema.rb +85 -74
- data/lib/committee/schema_validator/hyper_schema/parameter_coercer.rb +60 -54
- data/lib/committee/schema_validator/hyper_schema/request_validator.rb +43 -37
- data/lib/committee/schema_validator/hyper_schema/response_generator.rb +86 -80
- data/lib/committee/schema_validator/hyper_schema/response_validator.rb +65 -59
- data/lib/committee/schema_validator/hyper_schema/router.rb +35 -29
- data/lib/committee/schema_validator/hyper_schema/string_params_coercer.rb +87 -81
- data/lib/committee/schema_validator/open_api_3.rb +71 -61
- data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +121 -115
- data/lib/committee/schema_validator/open_api_3/request_validator.rb +24 -18
- data/lib/committee/schema_validator/open_api_3/response_validator.rb +22 -16
- data/lib/committee/schema_validator/open_api_3/router.rb +30 -24
- data/lib/committee/schema_validator/option.rb +42 -38
- data/lib/committee/test/methods.rb +55 -51
- data/lib/committee/validation_error.rb +2 -0
- data/test/bin/committee_stub_test.rb +3 -1
- data/test/bin_test.rb +3 -1
- data/test/committee_test.rb +3 -1
- data/test/drivers/hyper_schema/driver_test.rb +49 -0
- data/test/drivers/{hyper_schema_test.rb → hyper_schema/link_test.rb} +2 -45
- data/test/drivers/open_api_2/driver_test.rb +156 -0
- data/test/drivers/open_api_2/header_schema_builder_test.rb +26 -0
- data/test/drivers/open_api_2/link_test.rb +52 -0
- data/test/drivers/open_api_2/parameter_schema_builder_test.rb +195 -0
- data/test/drivers/{open_api_3_test.rb → open_api_3/driver_test.rb} +5 -3
- data/test/drivers_test.rb +12 -10
- data/test/middleware/base_test.rb +3 -1
- data/test/middleware/request_validation_open_api_3_test.rb +4 -2
- data/test/middleware/request_validation_test.rb +46 -5
- data/test/middleware/response_validation_open_api_3_test.rb +3 -1
- data/test/middleware/response_validation_test.rb +39 -4
- data/test/middleware/stub_test.rb +3 -1
- data/test/request_unpacker_test.rb +2 -2
- data/test/schema_validator/hyper_schema/parameter_coercer_test.rb +2 -2
- data/test/schema_validator/hyper_schema/request_validator_test.rb +3 -1
- data/test/schema_validator/hyper_schema/response_generator_test.rb +3 -1
- data/test/schema_validator/hyper_schema/response_validator_test.rb +3 -1
- data/test/schema_validator/hyper_schema/router_test.rb +5 -3
- data/test/schema_validator/hyper_schema/string_params_coercer_test.rb +3 -1
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +3 -1
- data/test/schema_validator/open_api_3/request_validator_test.rb +11 -1
- data/test/schema_validator/open_api_3/response_validator_test.rb +3 -1
- data/test/test/methods_new_version_test.rb +3 -1
- data/test/test/methods_test.rb +4 -2
- data/test/test_helper.rb +16 -16
- data/test/validation_error_test.rb +3 -1
- metadata +52 -6
- data/lib/committee/schema_validator/schema_validator.rb +0 -15
- data/test/drivers/open_api_2_test.rb +0 -416
@@ -1,99 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Committee
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
module SchemaValidator
|
5
|
+
class HyperSchema
|
6
|
+
# StringParamsCoercer takes parameters that are specified over a medium that
|
7
|
+
# can only accept strings (for example in a URL path or in query parameters)
|
8
|
+
# and attempts to coerce them into known types based of a link's schema
|
9
|
+
# definition.
|
10
|
+
#
|
11
|
+
# Currently supported types: null, integer, number and boolean.
|
12
|
+
#
|
13
|
+
# +call+ returns a hash of all params which could be coerced - coercion
|
14
|
+
# errors are simply ignored and expected to be handled later by schema
|
15
|
+
# validation.
|
16
|
+
class StringParamsCoercer
|
17
|
+
def initialize(query_hash, schema, options = {})
|
18
|
+
@query_hash = query_hash
|
19
|
+
@schema = schema
|
16
20
|
|
17
|
-
|
18
|
-
|
21
|
+
@coerce_recursive = options.fetch(:coerce_recursive, false)
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
def call!
|
25
|
+
coerce_object!(@query_hash, @schema)
|
26
|
+
end
|
23
27
|
|
24
|
-
|
28
|
+
private
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
def coerce_object!(hash, schema)
|
31
|
+
return false unless schema.respond_to?(:properties)
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
is_coerced = false
|
34
|
+
schema.properties.each do |k, s|
|
35
|
+
original_val = hash[k]
|
36
|
+
unless original_val.nil?
|
37
|
+
new_value, is_changed = coerce_value!(original_val, s)
|
38
|
+
if is_changed
|
39
|
+
hash[k] = new_value
|
40
|
+
is_coerced = true
|
41
|
+
end
|
42
|
+
end
|
37
43
|
end
|
38
|
-
end
|
39
|
-
end
|
40
44
|
|
41
|
-
|
42
|
-
|
45
|
+
is_coerced
|
46
|
+
end
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
48
|
+
def coerce_value!(original_val, s)
|
49
|
+
unless original_val.nil?
|
50
|
+
s.type.each do |to_type|
|
51
|
+
case to_type
|
52
|
+
when "null"
|
53
|
+
return nil, true if original_val.empty?
|
54
|
+
when "integer"
|
55
|
+
begin
|
56
|
+
return Integer(original_val), true
|
57
|
+
rescue ArgumentError => e
|
58
|
+
raise e unless e.message =~ /invalid value for Integer/
|
59
|
+
end
|
60
|
+
when "number"
|
61
|
+
begin
|
62
|
+
return Float(original_val), true
|
63
|
+
rescue ArgumentError => e
|
64
|
+
raise e unless e.message =~ /invalid value for Float/
|
65
|
+
end
|
66
|
+
when "boolean"
|
67
|
+
if original_val == "true" || original_val == "1"
|
68
|
+
return true, true
|
69
|
+
end
|
70
|
+
if original_val == "false" || original_val == "0"
|
71
|
+
return false, true
|
72
|
+
end
|
73
|
+
when "array"
|
74
|
+
if @coerce_recursive && coerce_array_data!(original_val, s)
|
75
|
+
return original_val, true # change original value
|
76
|
+
end
|
77
|
+
when "object"
|
78
|
+
if @coerce_recursive && coerce_object!(original_val, s)
|
79
|
+
return original_val, true # change original value
|
80
|
+
end
|
76
81
|
end
|
82
|
+
end
|
77
83
|
end
|
84
|
+
return nil, false
|
78
85
|
end
|
79
|
-
end
|
80
|
-
return nil, false
|
81
|
-
end
|
82
86
|
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
def coerce_array_data!(original_val, schema)
|
88
|
+
return false unless schema.respond_to?(:items)
|
89
|
+
return false unless original_val.is_a?(Array)
|
86
90
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
is_coerced = false
|
92
|
+
original_val.each_with_index do |d, index|
|
93
|
+
new_value, is_changed = coerce_value!(d, schema.items)
|
94
|
+
if is_changed
|
95
|
+
original_val[index] = new_value
|
96
|
+
is_coerced = true
|
97
|
+
end
|
98
|
+
end
|
95
99
|
|
96
|
-
|
100
|
+
is_coerced
|
101
|
+
end
|
97
102
|
end
|
103
|
+
end
|
98
104
|
end
|
99
105
|
end
|
@@ -1,84 +1,94 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Committee
|
4
|
+
module SchemaValidator
|
5
|
+
class OpenAPI3
|
6
|
+
# @param [Committee::SchemaValidator::Option] validator_option
|
7
|
+
def initialize(router, request, validator_option)
|
8
|
+
@router = router
|
9
|
+
@request = request
|
10
|
+
@operation_object = router.operation_object(request)
|
11
|
+
@validator_option = validator_option
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
def request_validate(request)
|
15
|
+
return unless link_exist?
|
13
16
|
|
14
|
-
|
17
|
+
path_params = validator_option.coerce_path_params ? coerce_path_params : {}
|
15
18
|
|
16
|
-
|
19
|
+
request_unpack(request)
|
17
20
|
|
18
|
-
|
21
|
+
request.env[validator_option.params_key]&.merge!(path_params) unless path_params.empty?
|
19
22
|
|
20
|
-
|
21
|
-
end
|
23
|
+
request_schema_validation(request)
|
22
24
|
|
23
|
-
|
24
|
-
full_body = ""
|
25
|
-
response.each do |chunk|
|
26
|
-
full_body << chunk
|
25
|
+
copy_coerced_data_to_query_hash(request)
|
27
26
|
end
|
28
|
-
data = full_body.empty? ? {} : JSON.parse(full_body)
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def response_validate(status, headers, response, test_method = false)
|
29
|
+
full_body = +""
|
30
|
+
response.each do |chunk|
|
31
|
+
full_body << chunk
|
32
|
+
end
|
33
|
+
data = full_body.empty? ? {} : JSON.parse(full_body)
|
34
|
+
|
35
|
+
strict = test_method
|
36
|
+
Committee::SchemaValidator::OpenAPI3::ResponseValidator.
|
37
|
+
new(@operation_object, validator_option).
|
38
|
+
call(status, headers, data, strict)
|
39
|
+
end
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
def link_exist?
|
42
|
+
!@operation_object.nil?
|
43
|
+
end
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
def coerce_form_params(_parameter)
|
46
|
+
# Empty because request_schema_validation checks and coerces
|
47
|
+
end
|
43
48
|
|
44
|
-
|
49
|
+
private
|
45
50
|
|
46
|
-
|
51
|
+
attr_reader :validator_option
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
53
|
+
def coerce_path_params
|
54
|
+
@operation_object.coerce_path_parameter(@validator_option)
|
55
|
+
end
|
52
56
|
|
53
|
-
|
54
|
-
|
57
|
+
def request_schema_validation(request)
|
58
|
+
return unless @operation_object
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
validator = Committee::SchemaValidator::OpenAPI3::RequestValidator.new(@operation_object, validator_option: validator_option)
|
61
|
+
validator.call(request, request.env[validator_option.params_key], header(request))
|
62
|
+
end
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
64
|
+
def header(request)
|
65
|
+
request.env[validator_option.headers_key]
|
66
|
+
end
|
63
67
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
def request_unpack(request)
|
69
|
+
request.env[validator_option.params_key], request.env[validator_option.headers_key] = Committee::RequestUnpacker.new(
|
70
|
+
request,
|
71
|
+
allow_form_params: validator_option.allow_form_params,
|
72
|
+
allow_get_body: validator_option.allow_get_body,
|
73
|
+
allow_query_params: validator_option.allow_query_params,
|
74
|
+
coerce_form_params: validator_option.coerce_form_params,
|
75
|
+
optimistic_json: validator_option.optimistic_json,
|
76
|
+
schema_validator: self
|
77
|
+
).call
|
78
|
+
end
|
75
79
|
|
76
|
-
|
77
|
-
|
80
|
+
def copy_coerced_data_to_query_hash(request)
|
81
|
+
return if request.env["rack.request.query_hash"].nil? || request.env["rack.request.query_hash"].empty?
|
78
82
|
|
79
|
-
|
80
|
-
|
83
|
+
request.env["rack.request.query_hash"].keys.each do |k|
|
84
|
+
request.env["rack.request.query_hash"][k] = request.env[validator_option.params_key][k]
|
85
|
+
end
|
81
86
|
end
|
82
87
|
end
|
83
88
|
end
|
84
89
|
end
|
90
|
+
|
91
|
+
require_relative "open_api_3/router"
|
92
|
+
require_relative "open_api_3/operation_wrapper"
|
93
|
+
require_relative "open_api_3/request_validator"
|
94
|
+
require_relative "open_api_3/response_validator"
|
@@ -1,120 +1,126 @@
|
|
1
|
-
|
2
|
-
class SchemaValidator::OpenAPI3::OperationWrapper
|
3
|
-
# # @param request_operation [OpenAPIParser::RequestOperation]
|
4
|
-
def initialize(request_operation)
|
5
|
-
@request_operation = request_operation
|
6
|
-
end
|
7
|
-
|
8
|
-
def path_params
|
9
|
-
request_operation.path_params
|
10
|
-
end
|
11
|
-
|
12
|
-
def original_path
|
13
|
-
request_operation.original_path
|
14
|
-
end
|
15
|
-
|
16
|
-
def coerce_path_parameter(validator_option)
|
17
|
-
options = build_openapi_parser_path_option(validator_option)
|
18
|
-
return {} unless options.coerce_value
|
19
|
-
|
20
|
-
request_operation.validate_path_params(options)
|
21
|
-
rescue OpenAPIParser::OpenAPIError => e
|
22
|
-
raise Committee::InvalidRequest.new(e.message)
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param [Boolean] strict when not content_type or status code definition, raise error
|
26
|
-
def validate_response_params(status_code, headers, response_data, strict, check_header)
|
27
|
-
request_body = OpenAPIParser::RequestOperation::ValidatableResponseBody.new(status_code, response_data, headers)
|
28
|
-
|
29
|
-
return request_operation.validate_response_body(request_body, response_validate_options(strict, check_header))
|
30
|
-
rescue OpenAPIParser::OpenAPIError => e
|
31
|
-
raise Committee::InvalidResponse.new(e.message)
|
32
|
-
end
|
33
|
-
|
34
|
-
def validate_request_params(params, headers, validator_option)
|
35
|
-
ret, err = case request_operation.http_method
|
36
|
-
when 'get'
|
37
|
-
validate_get_request_params(params, headers, validator_option)
|
38
|
-
when 'post'
|
39
|
-
validate_post_request_params(params, headers, validator_option)
|
40
|
-
when 'put'
|
41
|
-
validate_post_request_params(params, headers, validator_option)
|
42
|
-
when 'patch'
|
43
|
-
validate_post_request_params(params, headers, validator_option)
|
44
|
-
when 'delete'
|
45
|
-
validate_get_request_params(params, headers, validator_option)
|
46
|
-
else
|
47
|
-
raise "Committee OpenAPI3 not support #{request_operation.http_method} method"
|
48
|
-
end
|
49
|
-
raise err if err
|
50
|
-
ret
|
51
|
-
end
|
1
|
+
# frozen_string_literal: true
|
52
2
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
|
59
|
-
|
3
|
+
module Committee
|
4
|
+
module SchemaValidator
|
5
|
+
class OpenAPI3
|
6
|
+
class OperationWrapper
|
7
|
+
# # @param request_operation [OpenAPIParser::RequestOperation]
|
8
|
+
def initialize(request_operation)
|
9
|
+
@request_operation = request_operation
|
10
|
+
end
|
11
|
+
|
12
|
+
def path_params
|
13
|
+
request_operation.path_params
|
14
|
+
end
|
15
|
+
|
16
|
+
def original_path
|
17
|
+
request_operation.original_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def coerce_path_parameter(validator_option)
|
21
|
+
options = build_openapi_parser_path_option(validator_option)
|
22
|
+
return {} unless options.coerce_value
|
23
|
+
|
24
|
+
request_operation.validate_path_params(options)
|
25
|
+
rescue OpenAPIParser::OpenAPIError => e
|
26
|
+
raise Committee::InvalidRequest.new(e.message)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [Boolean] strict when not content_type or status code definition, raise error
|
30
|
+
def validate_response_params(status_code, headers, response_data, strict, check_header)
|
31
|
+
response_body = OpenAPIParser::RequestOperation::ValidatableResponseBody.new(status_code, response_data, headers)
|
32
|
+
|
33
|
+
return request_operation.validate_response_body(response_body, response_validate_options(strict, check_header))
|
34
|
+
rescue OpenAPIParser::OpenAPIError => e
|
35
|
+
raise Committee::InvalidResponse.new(e.message)
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_request_params(params, headers, validator_option)
|
39
|
+
ret, err = case request_operation.http_method
|
40
|
+
when 'get'
|
41
|
+
validate_get_request_params(params, headers, validator_option)
|
42
|
+
when 'post'
|
43
|
+
validate_post_request_params(params, headers, validator_option)
|
44
|
+
when 'put'
|
45
|
+
validate_post_request_params(params, headers, validator_option)
|
46
|
+
when 'patch'
|
47
|
+
validate_post_request_params(params, headers, validator_option)
|
48
|
+
when 'delete'
|
49
|
+
validate_get_request_params(params, headers, validator_option)
|
50
|
+
else
|
51
|
+
raise "Committee OpenAPI3 not support #{request_operation.http_method} method"
|
52
|
+
end
|
53
|
+
raise err if err
|
54
|
+
ret
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid_request_content_type?(content_type)
|
58
|
+
if (request_body = request_operation.operation_object&.request_body)
|
59
|
+
!request_body.select_media_type(content_type).nil?
|
60
|
+
else
|
61
|
+
# if not exist request body object, all content_type allow.
|
62
|
+
# because request body object required content field so when it exists there're content type definition.
|
63
|
+
true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
attr_reader :request_operation
|
70
|
+
|
71
|
+
# @!attribute [r] request_operation
|
72
|
+
# @return [OpenAPIParser::RequestOperation]
|
73
|
+
|
74
|
+
# @return [OpenAPIParser::SchemaValidator::Options]
|
75
|
+
def build_openapi_parser_path_option(validator_option)
|
76
|
+
coerce_value = validator_option.coerce_path_params
|
77
|
+
datetime_coerce_class = validator_option.coerce_date_times ? DateTime : nil
|
78
|
+
validate_header = validator_option.check_header
|
79
|
+
OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value,
|
80
|
+
datetime_coerce_class: datetime_coerce_class,
|
81
|
+
validate_header: validate_header)
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [OpenAPIParser::SchemaValidator::Options]
|
85
|
+
def build_openapi_parser_post_option(validator_option)
|
86
|
+
coerce_value = validator_option.coerce_form_params
|
87
|
+
datetime_coerce_class = validator_option.coerce_date_times ? DateTime : nil
|
88
|
+
validate_header = validator_option.check_header
|
89
|
+
OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value,
|
90
|
+
datetime_coerce_class: datetime_coerce_class,
|
91
|
+
validate_header: validate_header)
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [OpenAPIParser::SchemaValidator::Options]
|
95
|
+
def build_openapi_parser_get_option(validator_option)
|
96
|
+
coerce_value = validator_option.coerce_query_params
|
97
|
+
datetime_coerce_class = validator_option.coerce_date_times ? DateTime : nil
|
98
|
+
validate_header = validator_option.check_header
|
99
|
+
OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value,
|
100
|
+
datetime_coerce_class: datetime_coerce_class,
|
101
|
+
validate_header: validate_header)
|
102
|
+
end
|
103
|
+
|
104
|
+
def validate_get_request_params(params, headers, validator_option)
|
105
|
+
# bad performance because when we coerce value, same check
|
106
|
+
request_operation.validate_request_parameter(params, headers, build_openapi_parser_get_option(validator_option))
|
107
|
+
rescue OpenAPIParser::OpenAPIError => e
|
108
|
+
raise Committee::InvalidRequest.new(e.message)
|
109
|
+
end
|
110
|
+
|
111
|
+
def validate_post_request_params(params, headers, validator_option)
|
112
|
+
content_type = headers['Content-Type'].to_s.split(";").first.to_s
|
113
|
+
|
114
|
+
# bad performance because when we coerce value, same check
|
115
|
+
return request_operation.validate_request_body(content_type, params, build_openapi_parser_post_option(validator_option))
|
116
|
+
rescue => e
|
117
|
+
raise Committee::InvalidRequest.new(e.message)
|
118
|
+
end
|
119
|
+
|
120
|
+
def response_validate_options(strict, check_header)
|
121
|
+
::OpenAPIParser::SchemaValidator::ResponseValidateOptions.new(strict: strict, validate_header: check_header)
|
122
|
+
end
|
60
123
|
end
|
61
124
|
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
attr_reader :request_operation
|
66
|
-
|
67
|
-
# @!attribute [r] request_operation
|
68
|
-
# @return [OpenAPIParser::RequestOperation]
|
69
|
-
|
70
|
-
# @return [OpenAPIParser::SchemaValidator::Options]
|
71
|
-
def build_openapi_parser_path_option(validator_option)
|
72
|
-
coerce_value = validator_option.coerce_path_params
|
73
|
-
datetime_coerce_class = validator_option.coerce_date_times ? DateTime : nil
|
74
|
-
validate_header = validator_option.check_header
|
75
|
-
OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value,
|
76
|
-
datetime_coerce_class: datetime_coerce_class,
|
77
|
-
validate_header: validate_header)
|
78
|
-
end
|
79
|
-
|
80
|
-
# @return [OpenAPIParser::SchemaValidator::Options]
|
81
|
-
def build_openapi_parser_post_option(validator_option)
|
82
|
-
coerce_value = validator_option.coerce_form_params
|
83
|
-
datetime_coerce_class = validator_option.coerce_date_times ? DateTime : nil
|
84
|
-
validate_header = validator_option.check_header
|
85
|
-
OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value,
|
86
|
-
datetime_coerce_class: datetime_coerce_class,
|
87
|
-
validate_header: validate_header)
|
88
|
-
end
|
89
|
-
|
90
|
-
# @return [OpenAPIParser::SchemaValidator::Options]
|
91
|
-
def build_openapi_parser_get_option(validator_option)
|
92
|
-
coerce_value = validator_option.coerce_query_params
|
93
|
-
datetime_coerce_class = validator_option.coerce_date_times ? DateTime : nil
|
94
|
-
validate_header = validator_option.check_header
|
95
|
-
OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value,
|
96
|
-
datetime_coerce_class: datetime_coerce_class,
|
97
|
-
validate_header: validate_header)
|
98
|
-
end
|
99
|
-
|
100
|
-
def validate_get_request_params(params, headers, validator_option)
|
101
|
-
# bad performance because when we coerce value, same check
|
102
|
-
request_operation.validate_request_parameter(params, headers, build_openapi_parser_get_option(validator_option))
|
103
|
-
rescue OpenAPIParser::OpenAPIError => e
|
104
|
-
raise Committee::InvalidRequest.new(e.message)
|
105
|
-
end
|
106
|
-
|
107
|
-
def validate_post_request_params(params, headers, validator_option)
|
108
|
-
content_type = headers['Content-Type'].to_s.split(";").first.to_s
|
109
|
-
|
110
|
-
# bad performance because when we coerce value, same check
|
111
|
-
return request_operation.validate_request_body(content_type, params, build_openapi_parser_post_option(validator_option))
|
112
|
-
rescue => e
|
113
|
-
raise Committee::InvalidRequest.new(e.message)
|
114
|
-
end
|
115
|
-
|
116
|
-
def response_validate_options(strict, check_header)
|
117
|
-
::OpenAPIParser::SchemaValidator::ResponseValidateOptions.new(strict: strict, validate_header: check_header)
|
118
|
-
end
|
119
125
|
end
|
120
126
|
end
|