Browse Source

🎨 Auto format

pull/14869/head
pre-commit-ci-lite[bot] 5 months ago
committed by GitHub
parent
commit
f0086d5f29
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      fastapi/openapi/utils.py
  2. 14
      tests/test_duplicate_operation_id.py

6
fastapi/openapi/utils.py

@ -246,11 +246,7 @@ def get_openapi_operation_metadata(
operation_id = route.operation_id or route.unique_id
# If the route has multiple methods and operation_id was not explicitly set,
# append the method to make each operation ID unique
if (
not route.operation_id
and route.methods
and len(route.methods) > 1
):
if not route.operation_id and route.methods and len(route.methods) > 1:
# unique_id already includes a method suffix, so we need to replace it
# with the actual method being processed
# unique_id format: "{name}_{path}_{first_method}"

14
tests/test_duplicate_operation_id.py

@ -2,10 +2,10 @@
Test that routes with multiple methods get unique operation IDs.
Related to issue #13175
"""
import warnings
from fastapi import FastAPI
from fastapi.testclient import TestClient
def test_multiple_methods_unique_operation_ids():
@ -25,8 +25,7 @@ def test_multiple_methods_unique_operation_ids():
# Check that no duplicate operation ID warning was raised
duplicate_warnings = [
warning for warning in w
if "Duplicate Operation ID" in str(warning.message)
warning for warning in w if "Duplicate Operation ID" in str(warning.message)
]
assert len(duplicate_warnings) == 0, (
f"Found {len(duplicate_warnings)} duplicate operation ID warnings: "
@ -46,8 +45,7 @@ def test_multiple_methods_unique_operation_ids():
delete_op_id = clear_path["delete"]["operationId"]
assert post_op_id != delete_op_id, (
f"Operation IDs should be different: "
f"POST={post_op_id}, DELETE={delete_op_id}"
f"Operation IDs should be different: POST={post_op_id}, DELETE={delete_op_id}"
)
@ -68,8 +66,7 @@ def test_multiple_routes_with_multiple_methods():
openapi_schema = app.openapi()
duplicate_warnings = [
warning for warning in w
if "Duplicate Operation ID" in str(warning.message)
warning for warning in w if "Duplicate Operation ID" in str(warning.message)
]
assert len(duplicate_warnings) == 0
@ -113,8 +110,7 @@ def test_add_api_route_with_multiple_methods():
openapi_schema = app.openapi()
duplicate_warnings = [
warning for warning in w
if "Duplicate Operation ID" in str(warning.message)
warning for warning in w if "Duplicate Operation ID" in str(warning.message)
]
assert len(duplicate_warnings) == 0

Loading…
Cancel
Save