Skip to content

Commit b5dce09

Browse files
committed
fix:cleanup
1 parent 45318ac commit b5dce09

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

lib/open_api_schema/response_validator_middleware.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class ResponseValidatorMiddleware
3131
# @param app [Object] The Rack application.
3232
def initialize(app)
3333
@app = app
34-
# Handles the middleware call to validate the schema if the "VALIDATE_SCHEMA" header is present.
3534
error_handler = Proc.new do |error, env|
3635
logger = Logger.new(Rails.root.join("log", "committee_validation.log"))
3736
logger.error("Committee Validation Error: #{error.message}")
@@ -40,39 +39,24 @@ def initialize(app)
4039
@response_validator = Committee::Middleware::ResponseValidation.new(app, schema_path: "docs/openapi.json", ignore_error: true, error_handler: error_handler)
4140
end
4241

42+
# Handles the middleware call to validate the schema if the "VALIDATE_SCHEMA" header is present.
4343
#
4444
# @param env [Hash] The Rack environment hash.
4545
# @return [Array] The status, headers, and response.
4646
def call(env)
4747
status, headers, response = @app.call(env)
4848

4949
if condition_for_response_validation?(env)
50-
status, headers, response = validate_response(env, status, headers, response)
50+
status, headers, response = @response_validator.call(env)
5151
end
5252

5353
[ status, headers, response ]
5454
end
5555

5656
private
5757

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.
6558
def condition_for_response_validation?(env)
6659
true # env.key?("HTTP_VALIDATE_SCHEMA")
6760
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
7761
end
7862
end

0 commit comments

Comments
 (0)