Browse Source

Merge branch 'fix/duplicate-operation-id' of https://github.com/mokshagnachintha/fastapi into fix/duplicate-operation-id

pull/15327/head
Contributor 3 months ago
parent
commit
efe03d3be5
  1. 18
      tests/test_duplicate_operation_id.py

18
tests/test_duplicate_operation_id.py

@ -1,4 +1,5 @@
"""Test for fix of issue #13175: duplicate operation IDs with multi-method routes""" """Test for fix of issue #13175: duplicate operation IDs with multi-method routes"""
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -14,37 +15,37 @@ def test_no_duplicate_operation_ids_with_multiple_methods():
client = TestClient(app) client = TestClient(app)
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200 assert response.status_code == 200
data = response.json() data = response.json()
# Check that all three methods exist in the OpenAPI schema # Check that all three methods exist in the OpenAPI schema
paths = data.get("paths", {}) paths = data.get("paths", {})
items_path = paths.get("/items/", {}) items_path = paths.get("/items/", {})
assert "get" in items_path assert "get" in items_path
assert "post" in items_path assert "post" in items_path
assert "delete" in items_path assert "delete" in items_path
# Verify each method has a unique operation ID # Verify each method has a unique operation ID
get_op_id = items_path["get"].get("operationId") get_op_id = items_path["get"].get("operationId")
post_op_id = items_path["post"].get("operationId") post_op_id = items_path["post"].get("operationId")
delete_op_id = items_path["delete"].get("operationId") delete_op_id = items_path["delete"].get("operationId")
# All should exist # All should exist
assert get_op_id is not None assert get_op_id is not None
assert post_op_id is not None assert post_op_id is not None
assert delete_op_id is not None assert delete_op_id is not None
# All should be different # All should be different
assert get_op_id != post_op_id assert get_op_id != post_op_id
assert get_op_id != delete_op_id assert get_op_id != delete_op_id
assert post_op_id != delete_op_id assert post_op_id != delete_op_id
# Verify they follow the pattern: <name>_<path>_<method> # Verify they follow the pattern: <name>_<path>_<method>
assert "handle_items_items_" in get_op_id assert "handle_items_items_" in get_op_id
assert "handle_items_items_" in post_op_id assert "handle_items_items_" in post_op_id
assert "handle_items_items_" in delete_op_id assert "handle_items_items_" in delete_op_id
assert "_get" in get_op_id assert "_get" in get_op_id
assert "_post" in post_op_id assert "_post" in post_op_id
assert "_delete" in delete_op_id assert "_delete" in delete_op_id
@ -53,4 +54,3 @@ def test_no_duplicate_operation_ids_with_multiple_methods():
if __name__ == "__main__": if __name__ == "__main__":
test_no_duplicate_operation_ids_with_multiple_methods() test_no_duplicate_operation_ids_with_multiple_methods()
print("✓ Test passed!") print("✓ Test passed!")

Loading…
Cancel
Save