From 4fffe81a7113c7ae846ea3404fcb1710588c57b7 Mon Sep 17 00:00:00 2001 From: DJ Melisso Date: Fri, 5 Dec 2025 00:38:49 -0800 Subject: [PATCH] fix(openapi): avoid duplicated anyOf refs from shared app-level responses The OpenAPI generator performed only a shallow copy of `additional_response`, causing nested objects (e.g., `content`) to be shared across all routes during openapi generation. When `deep_dict_update()` merged schemas for each route, the shared `anyOf` array accumulated duplicate $ref entries. Switching to a deep copy ensures each route processes an isolated response definition and prevents duplication. --- fastapi/openapi/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index 9fe2044f2..278adb1dc 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -1,3 +1,4 @@ +import copy import http.client import inspect import warnings @@ -378,7 +379,7 @@ def get_openapi_path( additional_status_code, additional_response, ) in route.responses.items(): - process_response = additional_response.copy() + process_response = copy.deepcopy(additional_response) process_response.pop("model", None) status_code_key = str(additional_status_code).upper() if status_code_key == "DEFAULT":