From 9c3bdae475e7e45c2a7c4a4e617046c081b4973a Mon Sep 17 00:00:00 2001 From: Thor Agent Date: Wed, 15 Apr 2026 22:27:51 +0200 Subject: [PATCH] Fix standalone HEAD routes: only exclude HEAD from operation ID when GET is present --- fastapi/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fastapi/utils.py b/fastapi/utils.py index 692179f7bd..9c38de5d01 100644 --- a/fastapi/utils.py +++ b/fastapi/utils.py @@ -96,7 +96,11 @@ def generate_unique_id(route: "APIRoute") -> str: operation_id = f"{route.name}{route.path_format}" operation_id = re.sub(r"\W", "_", operation_id) assert route.methods - operation_id = f"{operation_id}_{sorted(route.methods - {'HEAD'}, key=lambda m: 0 if m == 'GET' else 1)[0].lower()}" + methods_for_id = ( + route.methods - {"HEAD"} if "GET" in route.methods else route.methods + ) + primary_method = sorted(methods_for_id, key=lambda m: 0 if m == "GET" else 1)[0] + operation_id = f"{operation_id}_{primary_method.lower()}" return operation_id