Skip to content

Commit 0fb1412

Browse files
committed
fix: cleanup
1 parent 979dc33 commit 0fb1412

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

config/application.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Application < Rails::Application
3030
# Skip views, helpers and assets when generating a new resource.
3131
config.api_only = true
3232

33+
# Add the request and response validation middleware to the application.
34+
# TODO: This can be changed later to add middleware in exact position e.g config.middleware.after Rack::Runtime, OpenApiSchema::RequestValidatorMiddleware
3335
config.middleware.use ::OpenApiSchema::RequestValidatorMiddleware
3436
config.middleware.use ::OpenApiSchema::ResponseValidatorMiddleware
3537
end

lib/open_api_schema/request_validator_middleware.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ def initialize(app)
77
end
88

99
# Handles the middleware call to validate the schema if the "VALIDATE_SCHEMA" header is present.
10-
# If the header is set to "1", it validates the request schema.
11-
# Otherwise, it continues the request-response cycle as usual.
10+
# If the header VALIDATE_SCHEMA is exist, it validates the request schema.
1211
#
1312
# @param env [Hash] The Rack environment hash.
1413
# @return [Array] The status, headers, and response.

lib/open_api_schema/response_validator_middleware.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def initialize(app)
99
@response_validator = Committee::Middleware::ResponseValidation.new(app, schema_path: "docs/openapi.json", strict_reference_validation: true)
1010
end
1111

12-
# Handles the middleware call to validate the schema if the "VALIDATE_SCHEMA" header is present.
13-
# If the header is set to "1", it validates the response schema.
12+
# Sets up the middleware to validate the response schema if the "VALIDATE_SCHEMA" header is present.
1413
#
1514
# @param env [Hash] The Rack environment hash.
1615
# @return [Array] The status, headers, and response.
@@ -25,11 +24,6 @@ def call(env)
2524
end
2625

2726
private
28-
29-
# Checks if the "Validate-Schema" header is present in the environment hash.
30-
#
31-
# @param env [Hash] The Rack environment hash.
32-
# @return [Boolean] True if the "Validate-Schema" header is present, false otherwise.
3327
def condition_for_response_validation?(env)
3428
env.key?("HTTP_VALIDATE_SCHEMA")
3529
end

0 commit comments

Comments
 (0)