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
- #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]
4 5 6 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 4 def initialize(request_operation) @request_operation = request_operation end |
Instance Method Details
#coerce_path_parameter(validator_option) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 16 def coerce_path_parameter(validator_option) = build_openapi_parser_path_option(validator_option) return {} unless .coerce_value request_operation.validate_path_params() rescue OpenAPIParser::NotExistRequiredKey => e raise Committee::InvalidRequest.new(e.) end |
#original_path ⇒ Object
12 13 14 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 12 def original_path request_operation.original_path end |
#path_params ⇒ Object
8 9 10 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 8 def path_params request_operation.path_params end |
#valid_request_content_type?(content_type) ⇒ Boolean
53 54 55 56 57 58 59 60 61 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 53 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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 34 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
26 27 28 29 30 31 32 |
# File 'lib/committee/schema_validator/open_api_3/operation_wrapper.rb', line 26 def validate_response_params(status_code, headers, response_data, strict, check_header) request_body = OpenAPIParser::RequestOperation::ValidatableResponseBody.new(status_code, response_data, headers) return request_operation.validate_response_body(request_body, (strict, check_header)) rescue OpenAPIParser::OpenAPIError => e raise Committee::InvalidResponse.new(e.) end |