fix(proxy): avoid misleading multi-method operation ids

This commit is contained in:
user
2026-04-30 20:44:14 -07:00
parent f18ee0319d
commit e9fb89b90c
2 changed files with 28 additions and 2 deletions
+3 -2
View File
@@ -953,8 +953,9 @@ async def proxy_startup_event(app: FastAPI): # noqa: PLR0915
def _generate_stable_operation_id(route: Any) -> str:
operation_id = re.sub(r"\W", "_", f"{route.name}{route.path_format}")
if route.methods:
operation_id = f"{operation_id}_{sorted(route.methods)[0].lower()}"
route_methods = sorted(route.methods or [])
if len(route_methods) == 1:
operation_id = f"{operation_id}_{route_methods[0].lower()}"
return operation_id
@@ -460,6 +460,31 @@ class TestSwaggerChatCompletions:
]
assert len(operation_ids) == len(set(operation_ids))
def test_should_not_add_method_suffix_to_multi_method_route_base_id(self):
from types import SimpleNamespace
from litellm.proxy.proxy_server import _generate_stable_operation_id
multi_method_route = SimpleNamespace(
name="anthropic_proxy_route",
path_format="/anthropic/{endpoint}",
methods={"DELETE", "GET", "POST"},
)
single_method_route = SimpleNamespace(
name="list_models",
path_format="/models",
methods={"GET"},
)
assert (
_generate_stable_operation_id(multi_method_route)
== "anthropic_proxy_route_anthropic__endpoint_"
)
assert (
_generate_stable_operation_id(single_method_route)
== "list_models_models_get"
)
def test_should_reserve_operation_ids_across_lazy_fragments(self):
from litellm.proxy.proxy_server import ensure_unique_openapi_operation_ids