committee 3.1.0 → 3.1.1

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