@@ -83,11 +83,12 @@ class OpenApiConverter:
8383 Attributes:
8484 spec: The parsed OpenAPI specification dictionary.
8585 spec_url: Optional URL where the specification was retrieved from.
86+ base_url: Optional base URL override for all API endpoints.
8687 placeholder_counter: Counter for generating unique placeholder variables.
8788 call_template_name: Normalized name for the call_template derived from the spec.
8889 """
8990
90- def __init__ (self , openapi_spec : Dict [str , Any ], spec_url : Optional [str ] = None , call_template_name : Optional [str ] = None , auth_tools : Optional [Auth ] = None ):
91+ def __init__ (self , openapi_spec : Dict [str , Any ], spec_url : Optional [str ] = None , call_template_name : Optional [str ] = None , auth_tools : Optional [Auth ] = None , base_url : Optional [ str ] = None ):
9192 """Initializes the OpenAPI converter.
9293
9394 Args:
@@ -98,10 +99,13 @@ def __init__(self, openapi_spec: Dict[str, Any], spec_url: Optional[str] = None,
9899 the specification title is not provided.
99100 auth_tools: Optional auth configuration for generated tools.
100101 Applied only to endpoints that require authentication per OpenAPI spec.
102+ base_url: Optional base URL override for all API endpoints.
103+ When provided, this takes precedence over servers in the spec.
101104 """
102105 self .spec = openapi_spec
103106 self .spec_url = spec_url
104107 self .auth_tools = auth_tools
108+ self ._base_url_override = base_url
105109 # Single counter for all placeholder variables
106110 self .placeholder_counter = 0
107111 if call_template_name is None :
@@ -141,9 +145,12 @@ def convert(self) -> UtcpManual:
141145 """
142146 self .placeholder_counter = 0
143147 tools = []
144- servers = self .spec .get ("servers" )
145- if servers :
146- base_url = servers [0 ].get ("url" , "/" )
148+
149+ # Determine base URL: override > servers > spec_url > fallback
150+ if self ._base_url_override :
151+ base_url = self ._base_url_override
152+ elif self .spec .get ("servers" ):
153+ base_url = self .spec ["servers" ][0 ].get ("url" , "/" )
147154 elif self .spec_url :
148155 parsed_url = urlparse (self .spec_url )
149156 base_url = f"{ parsed_url .scheme } ://{ parsed_url .netloc } "
0 commit comments