Class: Committee::SchemaValidator::OpenAPI3
- Inherits:
-
Object
- Object
- Committee::SchemaValidator::OpenAPI3
show all
- Defined in:
- lib/committee/schema_validator/open_api_3.rb,
lib/committee/schema_validator/open_api_3/router.rb,
lib/committee/schema_validator/open_api_3/operation_wrapper.rb,
lib/committee/schema_validator/open_api_3/request_validator.rb,
lib/committee/schema_validator/open_api_3/response_validator.rb
Defined Under Namespace
Classes: OperationWrapper, RequestValidator, ResponseValidator, Router
Instance Method Summary
collapse
Constructor Details
#initialize(router, request, validator_option) ⇒ OpenAPI3
Returns a new instance of OpenAPI3.
7
8
9
10
11
12
|
# File 'lib/committee/schema_validator/open_api_3.rb', line 7
def initialize(router, request, validator_option)
@router = router
@request = request
@operation_object = router.operation_object(request)
@validator_option = validator_option
end
|
Instance Method Details
#link_exist? ⇒ Boolean
44
45
46
|
# File 'lib/committee/schema_validator/open_api_3.rb', line 44
def link_exist?
!@operation_object.nil?
end
|
#request_validate(request) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/committee/schema_validator/open_api_3.rb', line 14
def request_validate(request)
return unless link_exist?
request_unpack(request)
request_schema_validation(request)
copy_coerced_data_to_params(request)
end
|
#response_validate(status, headers, response, test_method = false) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/committee/schema_validator/open_api_3.rb', line 23
def response_validate(status, , response, test_method = false)
full_body = +""
response.each do |chunk|
full_body << chunk
end
parse_to_json = !validator_option.parse_response_by_content_type ||
.fetch('Content-Type', nil)&.start_with?('application/json')
data = if parse_to_json
full_body.empty? ? {} : JSON.parse(full_body)
else
full_body
end
strict = test_method
Committee::SchemaValidator::OpenAPI3::ResponseValidator.
new(@operation_object, validator_option).
call(status, , data, strict)
end
|