fix(tools): avoid double slash when joining OpenAPI server URL and path (#46155)

This commit is contained in:
ChengFa authored and GitHub committed 2026-11-12 10:14:11 +00:00
1 parent ea974667af
commit b38d5a2c7b
2 files changed
+31 -1

No files matched your search

+1 -1
View File
@@ -204,7 +204,7 @@ class ApiBasedToolSchemaParser:
bundles.append(
ApiToolBundle(
server_url=server_url + interface["path"],
server_url=server_url.rstrip("/") + interface["path"],
method=interface["method"],
summary=interface["operation"]["description"]
if "description" in interface["operation"]
@@ -511,3 +511,33 @@ def test_openapi_31_union_with_only_null_returns_none():
parameter = {"name": "value", "schema": {"type": ["null"]}}
assert ApiBasedToolSchemaParser._get_tool_parameter_type(parameter) is None
def test_parse_openapi_to_tool_bundle_avoids_double_slash_in_server_url(app: Flask) -> None:
openapi = {
"openapi": "3.0.0",
"info": {"title": "API", "version": "1.0.0"},
"servers": [{"url": "https://api.example.com/v1/"}],
"paths": {"/items": {"get": {"summary": "List items", "responses": {"200": {"description": "OK"}}}}},
}
with app.test_request_context():
bundles = ApiBasedToolSchemaParser.parse_openapi_to_tool_bundle(openapi)
assert len(bundles) == 1
assert bundles[0].server_url == "https://api.example.com/v1/items"
def test_parse_openapi_to_tool_bundle_keeps_server_url_without_trailing_slash(app: Flask) -> None:
openapi = {
"openapi": "3.0.0",
"info": {"title": "API", "version": "1.0.0"},
"servers": [{"url": "https://api.example.com/v1"}],
"paths": {"/items": {"get": {"summary": "List items", "responses": {"200": {"description": "OK"}}}}},
}
with app.test_request_context():
bundles = ApiBasedToolSchemaParser.parse_openapi_to_tool_bundle(openapi)
assert len(bundles) == 1
assert bundles[0].server_url == "https://api.example.com/v1/items"