|
|
|
@ -2,6 +2,7 @@ import email.message |
|
|
|
import functools |
|
|
|
import inspect |
|
|
|
import json |
|
|
|
import warnings |
|
|
|
from collections.abc import ( |
|
|
|
AsyncIterator, |
|
|
|
Awaitable, |
|
|
|
@ -28,6 +29,7 @@ from fastapi._compat import ( |
|
|
|
_get_model_config, |
|
|
|
_model_dump, |
|
|
|
_normalize_errors, |
|
|
|
annotation_is_pydantic_v1, |
|
|
|
lenient_issubclass, |
|
|
|
may_v1, |
|
|
|
) |
|
|
|
@ -634,6 +636,13 @@ class APIRoute(routing.Route): |
|
|
|
f"Status code {status_code} must not have a response body" |
|
|
|
) |
|
|
|
response_name = "Response_" + self.unique_id |
|
|
|
if annotation_is_pydantic_v1(self.response_model): |
|
|
|
warnings.warn( |
|
|
|
"pydantic.v1 is deprecated and will soon stop being supported by FastAPI." |
|
|
|
f" Please update the response model {self.response_model!r}.", |
|
|
|
category=DeprecationWarning, |
|
|
|
stacklevel=4, |
|
|
|
) |
|
|
|
self.response_field = create_model_field( |
|
|
|
name=response_name, |
|
|
|
type_=self.response_model, |
|
|
|
@ -667,6 +676,13 @@ class APIRoute(routing.Route): |
|
|
|
f"Status code {additional_status_code} must not have a response body" |
|
|
|
) |
|
|
|
response_name = f"Response_{additional_status_code}_{self.unique_id}" |
|
|
|
if annotation_is_pydantic_v1(model): |
|
|
|
warnings.warn( |
|
|
|
"pydantic.v1 is deprecated and will soon stop being supported by FastAPI." |
|
|
|
f" In responses={{}}, please update {model}.", |
|
|
|
category=DeprecationWarning, |
|
|
|
stacklevel=4, |
|
|
|
) |
|
|
|
response_field = create_model_field( |
|
|
|
name=response_name, type_=model, mode="serialization" |
|
|
|
) |
|
|
|
|