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