@@ -686,6 +686,65 @@ def test_prepare_request_params_unknown_parameter(
686686 # Make sure unknown parameters are ignored and do not raise errors.
687687 assert "unknown_param" not in request_params ["params" ]
688688
689+ def test_prepare_request_params_merges_default_headers (
690+ self ,
691+ sample_endpoint ,
692+ sample_auth_credential ,
693+ sample_auth_scheme ,
694+ sample_operation ,
695+ ):
696+ tool = RestApiTool (
697+ name = "test_tool" ,
698+ description = "Test Tool" ,
699+ endpoint = sample_endpoint ,
700+ operation = sample_operation ,
701+ auth_credential = sample_auth_credential ,
702+ auth_scheme = sample_auth_scheme ,
703+ )
704+ tool .set_default_headers ({"developer-token" : "token" })
705+
706+ request_params = tool ._prepare_request_params ([], {})
707+
708+ assert request_params ["headers" ]["developer-token" ] == "token"
709+
710+ def test_prepare_request_params_preserves_existing_headers (
711+ self ,
712+ sample_endpoint ,
713+ sample_auth_credential ,
714+ sample_auth_scheme ,
715+ sample_operation ,
716+ sample_api_parameters ,
717+ ):
718+ tool = RestApiTool (
719+ name = "test_tool" ,
720+ description = "Test Tool" ,
721+ endpoint = sample_endpoint ,
722+ operation = sample_operation ,
723+ auth_credential = sample_auth_credential ,
724+ auth_scheme = sample_auth_scheme ,
725+ )
726+ tool .set_default_headers ({
727+ "Content-Type" : "text/plain" ,
728+ "developer-token" : "token" ,
729+ "User-Agent" : "custom-default" ,
730+ })
731+
732+ header_param = ApiParameter (
733+ original_name = "User-Agent" ,
734+ py_name = "user_agent" ,
735+ param_location = "header" ,
736+ param_schema = OpenAPISchema (type = "string" ),
737+ )
738+
739+ params = sample_api_parameters + [header_param ]
740+ kwargs = {"test_body_param" : "value" , "user_agent" : "api-client" }
741+
742+ request_params = tool ._prepare_request_params (params , kwargs )
743+
744+ assert request_params ["headers" ]["Content-Type" ] == "application/json"
745+ assert request_params ["headers" ]["developer-token" ] == "token"
746+ assert request_params ["headers" ]["User-Agent" ] == "api-client"
747+
689748 def test_prepare_request_params_base_url_handling (
690749 self , sample_auth_credential , sample_auth_scheme , sample_operation
691750 ):
0 commit comments