Class: OpenapiValidator::RequestValidator
- Inherits:
-
Object
- Object
- OpenapiValidator::RequestValidator
- Defined in:
- lib/openapi_validator/request_validator.rb
Instance Attribute Summary collapse
-
#api_doc ⇒ Object
readonly
Returns the value of attribute api_doc.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#path_validator ⇒ Object
readonly
Returns the value of attribute path_validator.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#api_doc ⇒ Object (readonly)
Returns the value of attribute api_doc.
8 9 10 |
# File 'lib/openapi_validator/request_validator.rb', line 8 def api_doc @api_doc end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/openapi_validator/request_validator.rb', line 8 def errors @errors end |
#path_validator ⇒ Object (readonly)
Returns the value of attribute path_validator.
8 9 10 |
# File 'lib/openapi_validator/request_validator.rb', line 8 def path_validator @path_validator end |
Class Method Details
.call(**params) ⇒ Object
14 15 16 |
# File 'lib/openapi_validator/request_validator.rb', line 14 def self.call(**params) new(**params).call end |
Instance Method Details
#call ⇒ Object
18 19 20 21 |
# File 'lib/openapi_validator/request_validator.rb', line 18 def call validate_path self end |
#valid? ⇒ Boolean
10 11 12 |
# File 'lib/openapi_validator/request_validator.rb', line 10 def valid? errors.empty? end |
#validate_response(body:, code:) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openapi_validator/request_validator.rb', line 23 def validate_response(body:, code:) if request.code != code.to_s @errors << "Path #{request.path} did not respond with expected status code. Expected #{request.code} got #{code}" end if path_validator.empty_schema? @errors << "Path #{request.path} should return empty response." unless body.empty? else @errors += OpenapiValidator::ResponseValidator.call( request: request, schema: validator.api_doc, data: body, fragment: path_validator.fragment, response: true ).errors end validator.remove_validated_path(path_validator.path) if @errors.empty? self end |