From 6aed4f45cb1465ff31df1eb835d3eac47cd2636b Mon Sep 17 00:00:00 2001 From: geemus Date: Fri, 24 Oct 2025 15:16:10 -0500 Subject: [PATCH 1/3] fix content type split/parsing, using racks implementation fixes #454 --- lib/committee/schema_validator/open_api_3/operation_wrapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/committee/schema_validator/open_api_3/operation_wrapper.rb b/lib/committee/schema_validator/open_api_3/operation_wrapper.rb index ed0f4090..2da83420 100644 --- a/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +++ b/lib/committee/schema_validator/open_api_3/operation_wrapper.rb @@ -111,7 +111,7 @@ def validate_get_request_params(path_params, query_params, headers, validator_op def validate_post_request_params(path_params, query_params, body_params, headers, validator_option) content_type_key = headers.keys.detect { |k| k.casecmp?('Content-Type') } - content_type = headers[content_type_key].to_s.split(';').first.to_s + content_type = Rack::MediaType.type(headers[content_type_key]) # bad performance because when we coerce value, same check validate_path_and_query_params(path_params, query_params, headers, validator_option) From c441acc4c1b9097c2b965a28e824b3fcbaa14a74 Mon Sep 17 00:00:00 2001 From: geemus Date: Mon, 27 Oct 2025 08:46:50 -0500 Subject: [PATCH 2/3] use same code for content-type parsing in validator and operation wrapper --- lib/committee/schema_validator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/committee/schema_validator.rb b/lib/committee/schema_validator.rb index 240955cc..4885bbd3 100644 --- a/lib/committee/schema_validator.rb +++ b/lib/committee/schema_validator.rb @@ -4,7 +4,7 @@ module Committee module SchemaValidator class << self def request_media_type(request) - request.media_type.to_s + Rack::MediaType.type(request.env['CONTENT_TYPE']) end # @param [String] prefix From 1ee88f21e090866816040aabb879c44ddf2eef3a Mon Sep 17 00:00:00 2001 From: geemus Date: Thu, 30 Oct 2025 08:35:15 -0500 Subject: [PATCH 3/3] test(schema-validator): add basic tests for content type parsing - Add test cases for Committee::SchemaValidator#request_media_type - Verify parsing of simple, comma-separated, and semicolon-separated content types - Ensure correct media type extraction from request headers --- test/schema_validator_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/schema_validator_test.rb diff --git a/test/schema_validator_test.rb b/test/schema_validator_test.rb new file mode 100644 index 00000000..1bd5fb77 --- /dev/null +++ b/test/schema_validator_test.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "test_helper" + +describe Committee::SchemaValidator do + it "parses simple content types" do + request = Rack::Request.new({ "CONTENT_TYPE" => "application/json" }) + media_type = Committee::SchemaValidator.request_media_type(request) + assert_equal 'application/json', media_type + end + + it "parses comma-delineated content types" do + request = Rack::Request.new({ "CONTENT_TYPE" => "multipart/form-data, application/json" }) + media_type = Committee::SchemaValidator.request_media_type(request) + assert_equal 'multipart/form-data', media_type + end + + it "parses semicolon-delineated content types" do + request = Rack::Request.new({ "CONTENT_TYPE" => "multipart/form-data; application/json" }) + media_type = Committee::SchemaValidator.request_media_type(request) + assert_equal 'multipart/form-data', media_type + end +end