Class: Committee::SchemaValidator::OpenAPI3::OperationWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/committee/schema_validator/open_api_3/operation_wrapper.rb

Instance Method Summary collapse

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)
  options = build_openapi_parser_path_option(validator_option)
  return {} unless options.coerce_value

  request_operation.validate_path_params(options)
rescue OpenAPIParser::OpenAPIError => e
  raise Committee::InvalidRequest.new(e.message)
end

#original_pathObject



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_paramsObject



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_typesObject



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

Returns:

  • (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

Parameters:

  • strict (Boolean)

    when not content_type or status code definition, raise error



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, response_validate_options(strict, check_header))
rescue OpenAPIParser::OpenAPIError => e
  raise Committee::InvalidResponse.new(e.message)
end