From 8698216bb0c9b3cc68cffea5506773d89b3308c1 Mon Sep 17 00:00:00 2001 From: Varun Chawla Date: Sat, 7 Feb 2026 18:36:09 -0800 Subject: [PATCH] Add test for explicit operation_id with multiple methods to improve coverage --- tests/test_duplicate_operation_id.py | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_duplicate_operation_id.py b/tests/test_duplicate_operation_id.py index 23eecc19e..3465038e4 100644 --- a/tests/test_duplicate_operation_id.py +++ b/tests/test_duplicate_operation_id.py @@ -116,3 +116,33 @@ def test_add_api_route_with_multiple_methods(): clear_path = openapi_schema["paths"]["/clear"] assert clear_path["post"]["operationId"] != clear_path["delete"]["operationId"] + + +def test_explicit_operation_id_with_multiple_methods(): + """Test that explicit operation_id is respected and not modified""" + app = FastAPI() + + @app.api_route("/clear", methods=["POST", "DELETE"], operation_id="custom_clear") + def clear(): + return {"message": "cleared"} + + # When explicit operation_id is provided, it's used as-is which may cause + # duplicate operation ID warnings - this is expected behavior + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + openapi_schema = app.openapi() + + # If user provides explicit operation_id with multiple methods, + # they'll get a duplicate warning - this is intentional + duplicate_warnings = [ + warning for warning in w + if "Duplicate Operation ID" in str(warning.message) + ] + # We expect a duplicate warning because the user explicitly set the same + # operation_id for multiple methods + assert len(duplicate_warnings) > 0 + + clear_path = openapi_schema["paths"]["/clear"] + # Both methods use the same explicit operation_id + assert clear_path["post"]["operationId"] == "custom_clear" + assert clear_path["delete"]["operationId"] == "custom_clear"