From f1eace75239f5804320afb449435c2598947fe4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Ehlert?= Date: Thu, 2 May 2024 15:08:01 +0200 Subject: [PATCH] Create response field with proper mode Which should be "serialization" also for custom response models defined in the `responses` option. The same way we do that for the "main" response model on line 475. This fixes issue 1. mentioned in https://github.com/tiangolo/fastapi/discussions/10697 --- fastapi/routing.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index fa1351859..2375b389d 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -502,7 +502,11 @@ class APIRoute(routing.Route): additional_status_code ), f"Status code {additional_status_code} must not have a response body" response_name = f"Response_{additional_status_code}_{self.unique_id}" - response_field = create_response_field(name=response_name, type_=model) + response_field = create_response_field( + name=response_name, + type_=model, + mode="serialization", + ) response_fields[additional_status_code] = response_field if response_fields: self.response_fields: Dict[Union[int, str], ModelField] = response_fields