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
- #call ⇒ Object
- #valid? ⇒ Boolean
- #validate_response(body:, code:, media_type: request.media_type) ⇒ Object
Instance Attribute Details
#api_doc ⇒ Object (readonly)
Returns the value of attribute api_doc.
7 8 9 |
# File 'lib/openapi_validator/request_validator.rb', line 7 def api_doc @api_doc end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/openapi_validator/request_validator.rb', line 7 def errors @errors end |
#path_validator ⇒ Object (readonly)
Returns the value of attribute path_validator.
7 8 9 |
# File 'lib/openapi_validator/request_validator.rb', line 7 def path_validator @path_validator end |
Class Method Details
.call(**params) ⇒ Object
13 14 15 |
# File 'lib/openapi_validator/request_validator.rb', line 13 def self.call(**params) new(**params).call end |
Instance Method Details
#call ⇒ Object
17 18 19 20 |
# File 'lib/openapi_validator/request_validator.rb', line 17 def call validate_path self end |
#valid? ⇒ Boolean
9 10 11 |
# File 'lib/openapi_validator/request_validator.rb', line 9 def valid? errors.empty? end |
#validate_response(body:, code:, media_type: request.media_type) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openapi_validator/request_validator.rb', line 22 def validate_response(body:, code:, media_type: request.media_type) 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, media_type: media_type, fragment: path_validator.fragment(media_type: media_type), response: true ).errors end validator.remove_validated_path(path_validator.path) if @errors.empty? self end |