Class: Committee::SchemaValidator::OpenAPI3::OperationWrapper
- Inherits:
-
Object
- Object
- Committee::SchemaValidator::OpenAPI3::OperationWrapper
- Defined in:
- lib/committee/schema_validator/open_api_3/operation_wrapper.rb
Instance Method Summary collapse
- #coerce_path_parameter(validator_option) ⇒ Object
-
#initialize(request_operation) ⇒ OperationWrapper
constructor
# @param request_operation [OpenAPIParser::RequestOperation].
- #original_path ⇒ Object
- #path_params ⇒ Object
- #request_content_types ⇒ Object
- #valid_request_content_type?(content_type) ⇒ Boolean
- #validate_request_params(params, headers, validator_option) ⇒ Object
- #validate_response_params(status_code, headers, response_data, strict, check_header) ⇒ Object
Constructor Details
#initialize(request_operation) ⇒ OperationWrapper
# @param request_operation [OpenAPIParser::RequestOperation]
8 9 10 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 8 def initialize(request_operation) @request_operation = request_operation end |
Instance Method Details
#coerce_path_parameter(validator_option) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 20 def coerce_path_parameter(validator_option) = build_openapi_parser_path_option(validator_option) return {} unless .coerce_value request_operation.validate_path_params() rescue OpenAPIParser::OpenAPIError => e raise Committee::InvalidRequest.new(e.) end |
#original_path ⇒ Object
16 17 18 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 16 def original_path request_operation.original_path end |
#path_params ⇒ Object
12 13 14 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 12 def path_params request_operation.path_params end |
#request_content_types ⇒ Object
67 68 69 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 67 def request_content_types request_operation.operation_object&.request_body&.content&.keys || [] end |
#valid_request_content_type?(content_type) ⇒ Boolean
57 58 59 60 61 62 63 64 65 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 57 def valid_request_content_type?(content_type) if (request_body = request_operation.operation_object&.request_body) !request_body.select_media_type(content_type).nil? else # if not exist request body object, all content_type allow. # because request body object required content field so when it exists there're content type definition. true end end |
#validate_request_params(params, headers, validator_option) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 38 def validate_request_params(params, headers, validator_option) ret, err = case request_operation.http_method when 'get' validate_get_request_params(params, headers, validator_option) when 'post' validate_post_request_params(params, headers, validator_option) when 'put' validate_post_request_params(params, headers, validator_option) when 'patch' validate_post_request_params(params, headers, validator_option) when 'delete' validate_get_request_params(params, headers, validator_option) else raise "Committee OpenAPI3 not support #{request_operation.http_method} method" end raise err if err ret end |
#validate_response_params(status_code, headers, response_data, strict, check_header) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 30 def validate_response_params(status_code, headers, response_data, strict, check_header) response_body = OpenAPIParser::RequestOperation::ValidatableResponseBody.new(status_code, response_data, headers) return request_operation.validate_response_body(response_body, (strict, check_header)) rescue OpenAPIParser::OpenAPIError => e raise Committee::InvalidResponse.new(e.) end |