diff --git a/lib/committee/schema_validator/open_api_3/request_validator.rb b/lib/committee/schema_validator/open_api_3/request_validator.rb index 8334acd1..2f56819b 100644 --- a/lib/committee/schema_validator/open_api_3/request_validator.rb +++ b/lib/committee/schema_validator/open_api_3/request_validator.rb @@ -21,8 +21,8 @@ def call(request, path_params, query_params, body_params, headers) private def check_content_type(request, content_type) - # support post, put, patch only - return true unless request.post? || request.put? || request.patch? + # support post, put, patch, options only + return true unless request.post? || request.put? || request.patch? || request.options? return true if @operation_object.valid_request_content_type?(content_type) return true if @operation_object.optional_body? && empty_request?(request) diff --git a/test/schema_validator/open_api_3/request_validator_test.rb b/test/schema_validator/open_api_3/request_validator_test.rb index 49cdd679..fc223a09 100644 --- a/test/schema_validator/open_api_3/request_validator_test.rb +++ b/test/schema_validator/open_api_3/request_validator_test.rb @@ -95,6 +95,13 @@ def app assert_equal 400, last_response.status end + it "validates content_type for option request" do + @app = new_rack_app(check_content_type: true, schema: open_api_3_schema) + header "Content-Type", "text/html" + options "/validate", "{}" + assert_equal 400, last_response.status + end + def new_rack_app(options = {}) Rack::Builder.new { use Committee::Middleware::RequestValidation, options