From 78569760260616aedf0d8d7da4e56bb6e646ef3b Mon Sep 17 00:00:00 2001 From: Contributor Date: Wed, 4 Feb 2026 22:33:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20duplicate=20operationId=20?= =?UTF-8?q?when=20using=20multiple=20methods=20on=20same=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a route is added with multiple HTTP methods (e.g., methods=["POST", "DELETE"]), all methods were getting the same auto-generated operationId based only on the first method, causing "Duplicate Operation ID" warnings. The fix appends the method name to the operationId when: 1. No explicit operation_id is provided 2. The route has multiple methods This ensures unique operationIds for each method while maintaining backward compatibility for single-method routes and explicit operation_id usage. Fixes #13175 --- fastapi/openapi/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index 5736af3b7..76a663e9f 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -243,6 +243,10 @@ def get_openapi_operation_metadata( if route.description: operation["description"] = route.description operation_id = route.operation_id or route.unique_id + # When a route has multiple methods and uses auto-generated unique_id, + # append the method to make the operation_id unique for each method + if not route.operation_id and len(route.methods) > 1: + operation_id = f"{operation_id}_{method.lower()}" if operation_id in operation_ids: message = ( f"Duplicate Operation ID {operation_id} for function "