@@ -31,7 +31,6 @@ class ResponseValidatorMiddleware
31
31
# @param app [Object] The Rack application.
32
32
def initialize ( app )
33
33
@app = app
34
- # Handles the middleware call to validate the schema if the "VALIDATE_SCHEMA" header is present.
35
34
error_handler = Proc . new do |error , env |
36
35
logger = Logger . new ( Rails . root . join ( "log" , "committee_validation.log" ) )
37
36
logger . error ( "Committee Validation Error: #{ error . message } " )
@@ -40,39 +39,24 @@ def initialize(app)
40
39
@response_validator = Committee ::Middleware ::ResponseValidation . new ( app , schema_path : "docs/openapi.json" , ignore_error : true , error_handler : error_handler )
41
40
end
42
41
42
+ # Handles the middleware call to validate the schema if the "VALIDATE_SCHEMA" header is present.
43
43
#
44
44
# @param env [Hash] The Rack environment hash.
45
45
# @return [Array] The status, headers, and response.
46
46
def call ( env )
47
47
status , headers , response = @app . call ( env )
48
48
49
49
if condition_for_response_validation? ( env )
50
- status , headers , response = validate_response ( env , status , headers , response )
50
+ status , headers , response = @response_validator . call ( env )
51
51
end
52
52
53
53
[ status , headers , response ]
54
54
end
55
55
56
56
private
57
57
58
-
59
-
60
-
61
- # Checks if the "Validate-Schema" header is present in the environment hash.
62
- #
63
- # @param env [Hash] The Rack environment hash.
64
- # @return [Boolean] True if the "Validate-Schema" header is present, false otherwise.
65
58
def condition_for_response_validation? ( env )
66
59
true # env.key?("HTTP_VALIDATE_SCHEMA")
67
60
end
68
-
69
- def validate_response ( env , status , headers , response )
70
- begin
71
- @response_validator . call ( env )
72
- rescue StandardError => e
73
- @logger . error ( "Response Validation Failed: #{ e . message } " ) # Log the error, TODO: add more information
74
- [ status , headers , response ] # Return original response even if validation fails
75
- end
76
- end
77
61
end
78
62
end
0 commit comments