From 7c64e2bf09ecd9183e65ec144d2713f27100ef1e Mon Sep 17 00:00:00 2001 From: Lucas Rangel Cezimbra Date: Fri, 23 May 2025 20:54:51 -0300 Subject: [PATCH] test: OpenAPI schema with duplicated payload name --- tests/test_openapi_schema.py | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_openapi_schema.py b/tests/test_openapi_schema.py index fe5d08478..74f7e85df 100644 --- a/tests/test_openapi_schema.py +++ b/tests/test_openapi_schema.py @@ -158,6 +158,16 @@ def method_test_deprecated_example_examples( return dict(i=param2, f=param3) +class Payload(Schema): + # Duplicated Schema name with another fields + s: str + + +@api.post("/test-duplicated-payload-name", response=Response) +def method_duplicated_payload_name(request, data: Payload): + return data.dict() + + def test_schema_views(client: Client): assert client.get("/api/").status_code == 404 assert client.get("/api/docs").status_code == 200 @@ -240,6 +250,42 @@ def test_schema(schema): } +def test_duplicated_payload_names(schema): + openapi_schemas = schema["components"]["schemas"] + + assert openapi_schemas["Payload"] == { + "properties": { + "f": { + "title": "F", + "type": "number", + }, + "i": { + "title": "I", + "type": "integer", + }, + }, + "required": [ + "i", + "f", + ], + "title": "Payload", + "type": "object", + } + assert openapi_schemas["Payload2"] == { + "properties": { + "s": { + "title": "S", + "type": "string", + }, + }, + "required": [ + "s", + ], + "title": "Payload2", + "type": "object", + } + + def test_schema_alias(schema): method = schema["paths"]["/api/test-alias"]["post"]