|
|
@ -2,6 +2,7 @@ |
|
|
Test that routes with multiple methods get unique operation IDs. |
|
|
Test that routes with multiple methods get unique operation IDs. |
|
|
This is a regression test for issue #13175. |
|
|
This is a regression test for issue #13175. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
import warnings |
|
|
import warnings |
|
|
|
|
|
|
|
|
from fastapi import FastAPI |
|
|
from fastapi import FastAPI |
|
|
@ -22,29 +23,34 @@ def test_multiple_methods_generate_unique_operation_ids(): |
|
|
warnings.simplefilter("always") |
|
|
warnings.simplefilter("always") |
|
|
client = TestClient(app) |
|
|
client = TestClient(app) |
|
|
response = client.get("/openapi.json") |
|
|
response = client.get("/openapi.json") |
|
|
|
|
|
|
|
|
# There should be no duplicate operation_id warnings |
|
|
# There should be no duplicate operation_id warnings |
|
|
dup_warnings = [ |
|
|
dup_warnings = [ |
|
|
warning for warning in w |
|
|
warning for warning in w if "Duplicate Operation ID" in str(warning.message) |
|
|
if "Duplicate Operation ID" in str(warning.message) |
|
|
|
|
|
] |
|
|
] |
|
|
assert len(dup_warnings) == 0, f"Expected no duplicate warnings, got: {dup_warnings}" |
|
|
assert len(dup_warnings) == 0, ( |
|
|
|
|
|
f"Expected no duplicate warnings, got: {dup_warnings}" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
openapi_schema = response.json() |
|
|
openapi_schema = response.json() |
|
|
|
|
|
|
|
|
# Get the operation IDs for POST and DELETE |
|
|
# Get the operation IDs for POST and DELETE |
|
|
post_operation_id = openapi_schema["paths"]["/clear"]["post"]["operationId"] |
|
|
post_operation_id = openapi_schema["paths"]["/clear"]["post"]["operationId"] |
|
|
delete_operation_id = openapi_schema["paths"]["/clear"]["delete"]["operationId"] |
|
|
delete_operation_id = openapi_schema["paths"]["/clear"]["delete"]["operationId"] |
|
|
|
|
|
|
|
|
# They should be different |
|
|
# They should be different |
|
|
assert post_operation_id != delete_operation_id, ( |
|
|
assert post_operation_id != delete_operation_id, ( |
|
|
f"POST and DELETE should have different operation IDs. " |
|
|
f"POST and DELETE should have different operation IDs. " |
|
|
f"Got POST: {post_operation_id}, DELETE: {delete_operation_id}" |
|
|
f"Got POST: {post_operation_id}, DELETE: {delete_operation_id}" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# Verify the operation IDs contain the correct method suffix |
|
|
# Verify the operation IDs contain the correct method suffix |
|
|
assert post_operation_id.endswith("_post"), f"POST operation_id should end with '_post', got: {post_operation_id}" |
|
|
assert post_operation_id.endswith("_post"), ( |
|
|
assert delete_operation_id.endswith("_delete"), f"DELETE operation_id should end with '_delete', got: {delete_operation_id}" |
|
|
f"POST operation_id should end with '_post', got: {post_operation_id}" |
|
|
|
|
|
) |
|
|
|
|
|
assert delete_operation_id.endswith("_delete"), ( |
|
|
|
|
|
f"DELETE operation_id should end with '_delete', got: {delete_operation_id}" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
|