From 6c4ec85165acc1650e45596a1c8b1a0d2d75dd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 5 Oct 2025 17:47:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20=5Fcompat.v1=20?= =?UTF-8?q?module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/_compat/v1.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fastapi/_compat/v1.py b/fastapi/_compat/v1.py index 9023c3220..4c941873b 100644 --- a/fastapi/_compat/v1.py +++ b/fastapi/_compat/v1.py @@ -14,7 +14,6 @@ from typing import ( ) from fastapi._compat import shared -from fastapi.exceptions import RequestErrorModel from fastapi.openapi.constants import REF_PREFIX as REF_PREFIX from fastapi.types import ModelNameMap from pydantic.version import VERSION as PYDANTIC_VERSION @@ -72,6 +71,7 @@ if not PYDANTIC_V2: get_annotation_from_field_info as get_annotation_from_field_info, ) from pydantic.schema import get_flat_models_from_field as get_flat_models_from_field + from pydantic.schema import get_model_name_map as get_model_name_map # noqa: F401 from pydantic.types import SecretBytes as SecretBytes # noqa: F401 from pydantic.types import SecretStr as SecretStr # noqa: F401 from pydantic.typing import ( # type: ignore[no-redef] @@ -81,6 +81,7 @@ if not PYDANTIC_V2: lenient_issubclass as lenient_issubclass, # noqa: F401 ) + else: from pydantic.v1 import AnyUrl as Url # noqa: F401 from pydantic.v1 import ( # type: ignore[assignment] @@ -129,6 +130,9 @@ else: from pydantic.v1.schema import ( get_flat_models_from_field as get_flat_models_from_field, # noqa: F401 ) + from pydantic.v1.schema import ( + get_model_name_map as get_model_name_map, # noqa: F401 + ) from pydantic.v1.types import SecretBytes as SecretBytes # noqa: F401 from pydantic.v1.types import SecretStr as SecretStr # noqa: F401 from pydantic.v1.typing import ( # type: ignore[no-redef] @@ -143,6 +147,7 @@ GetJsonSchemaHandler = Any # type: ignore[assignment,misc] JsonSchemaValue = Dict[str, Any] # type: ignore[misc] CoreSchema = Any # type: ignore[assignment,misc] + sequence_shapes = { SHAPE_LIST, SHAPE_SET, @@ -169,6 +174,9 @@ class PydanticSchemaGenerationError(Exception): # type: ignore[no-redef] pass +RequestErrorModel: Type[BaseModel] = create_model("Request") + + def with_info_plain_validator_function( # type: ignore[misc] function: Callable[..., Any], *, @@ -283,7 +291,6 @@ def get_schema_from_model_field( ], separate_input_output_schemas: bool = True, ) -> Dict[str, Any]: - # This expects that GenerateJsonSchema was already used to generate the definitions return field_schema( # type: ignore[no-any-return] field, model_name_map=model_name_map, ref_prefix=REF_PREFIX )[0]