Browse Source

fix: preserve backwards compatibility in generate_unique_id for route creation

When generate_unique_id is called during route creation without a method parameter,
use the first method only (original behavior) to avoid breaking existing tests.
When called with a specific method parameter from openapi utils, generate unique
operation IDs per HTTP method to fix duplicate operation IDs bug.
pull/15327/head
Contributor 3 months ago
parent
commit
79225822bc
  1. 5
      fastapi/utils.py

5
fastapi/utils.py

@ -102,9 +102,8 @@ def generate_unique_id(route: APIRoute, method: str | None = None) -> str:
# Include the specific method being generated # Include the specific method being generated
operation_id = f"{operation_id}_{method.lower()}" operation_id = f"{operation_id}_{method.lower()}"
else: else:
# When no specific method is provided, include all methods (for backwards compatibility) # When no specific method is provided, use the first method for backwards compatibility
methods_str = "_".join(sorted(m.lower() for m in route.methods)) operation_id = f"{operation_id}_{list(route.methods)[0].lower()}"
operation_id = f"{operation_id}_{methods_str}"
return operation_id return operation_id

Loading…
Cancel
Save