|
|
@ -18,13 +18,14 @@ from typing import ( |
|
|
|
Union, |
|
|
|
) |
|
|
|
|
|
|
|
from fastapi.exceptions import RequestErrorModel |
|
|
|
from fastapi.types import IncEx, ModelNameMap, UnionType |
|
|
|
from pydantic import BaseModel, create_model |
|
|
|
from pydantic.version import VERSION as P_VERSION |
|
|
|
from starlette.datastructures import UploadFile |
|
|
|
from typing_extensions import Annotated, Literal, get_args, get_origin |
|
|
|
|
|
|
|
from fastapi.exceptions import RequestErrorModel |
|
|
|
from fastapi.types import IncEx, ModelNameMap, UnionType |
|
|
|
|
|
|
|
# Reassign variable to make it reexported for mypy |
|
|
|
PYDANTIC_VERSION = P_VERSION |
|
|
|
PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.") |
|
|
@ -50,8 +51,8 @@ if PYDANTIC_V2: |
|
|
|
from pydantic import PydanticSchemaGenerationError as PydanticSchemaGenerationError |
|
|
|
from pydantic import TypeAdapter |
|
|
|
from pydantic import ValidationError as ValidationError |
|
|
|
from pydantic._internal._schema_generation_shared import ( # type: ignore[attr-defined] |
|
|
|
GetJsonSchemaHandler as GetJsonSchemaHandler, |
|
|
|
from pydantic._internal._schema_generation_shared import ( |
|
|
|
GetJsonSchemaHandler as GetJsonSchemaHandler, # type: ignore[attr-defined] |
|
|
|
) |
|
|
|
from pydantic._internal._typing_extra import eval_type_lenient |
|
|
|
from pydantic._internal._utils import lenient_issubclass as lenient_issubclass |
|
|
@ -67,8 +68,8 @@ if PYDANTIC_V2: |
|
|
|
with_info_plain_validator_function as with_info_plain_validator_function, |
|
|
|
) |
|
|
|
except ImportError: # pragma: no cover |
|
|
|
from pydantic_core.core_schema import ( |
|
|
|
general_plain_validator_function as with_info_plain_validator_function, # noqa: F401 |
|
|
|
from pydantic_core.core_schema import ( # noqa: F401 |
|
|
|
general_plain_validator_function as with_info_plain_validator_function, |
|
|
|
) |
|
|
|
|
|
|
|
Required = PydanticUndefined |
|
|
@ -149,8 +150,8 @@ if PYDANTIC_V2: |
|
|
|
# What calls this code passes a value that already called |
|
|
|
# self._type_adapter.validate_python(value) |
|
|
|
# |
|
|
|
# context argument was introduced in pydantic 2.7.3 |
|
|
|
kwargs = {"context": context} if PYDANTIC_VERSION >= "2.7.3" else {} |
|
|
|
# context argument was introduced in pydantic 2.8 |
|
|
|
kwargs = {"context": context} if PYDANTIC_VERSION >= "2.8" else {} |
|
|
|
|
|
|
|
return self._type_adapter.dump_python( |
|
|
|
value, |
|
|
@ -287,17 +288,16 @@ if PYDANTIC_V2: |
|
|
|
return BodyModel |
|
|
|
|
|
|
|
else: |
|
|
|
from fastapi.openapi.constants import REF_PREFIX as REF_PREFIX |
|
|
|
from pydantic import AnyUrl as Url # noqa: F401 |
|
|
|
from pydantic import ( # type: ignore[assignment] |
|
|
|
BaseConfig as BaseConfig, # noqa: F401 |
|
|
|
from pydantic import ( # type: ignore[assignment]; noqa: F401 |
|
|
|
BaseConfig as BaseConfig, |
|
|
|
) |
|
|
|
from pydantic import ValidationError as ValidationError # noqa: F401 |
|
|
|
from pydantic.class_validators import ( # type: ignore[no-redef] |
|
|
|
Validator as Validator, # noqa: F401 |
|
|
|
from pydantic.class_validators import ( # type: ignore[no-redef]; noqa: F401 |
|
|
|
Validator as Validator, |
|
|
|
) |
|
|
|
from pydantic.error_wrappers import ( # type: ignore[no-redef] |
|
|
|
ErrorWrapper as ErrorWrapper, # noqa: F401 |
|
|
|
from pydantic.error_wrappers import ( # type: ignore[no-redef]; noqa: F401 |
|
|
|
ErrorWrapper as ErrorWrapper, |
|
|
|
) |
|
|
|
from pydantic.errors import MissingError |
|
|
|
from pydantic.fields import ( # type: ignore[attr-defined] |
|
|
@ -310,34 +310,36 @@ else: |
|
|
|
SHAPE_TUPLE_ELLIPSIS, |
|
|
|
) |
|
|
|
from pydantic.fields import FieldInfo as FieldInfo |
|
|
|
from pydantic.fields import ( # type: ignore[no-redef,attr-defined] |
|
|
|
ModelField as ModelField, # noqa: F401 |
|
|
|
from pydantic.fields import ( # type: ignore[no-redef,attr-defined]; noqa: F401 |
|
|
|
ModelField as ModelField, |
|
|
|
) |
|
|
|
from pydantic.fields import ( # type: ignore[no-redef,attr-defined] |
|
|
|
Required as Required, # noqa: F401 |
|
|
|
from pydantic.fields import ( # type: ignore[no-redef,attr-defined]; noqa: F401 |
|
|
|
Required as Required, |
|
|
|
) |
|
|
|
from pydantic.fields import ( # type: ignore[no-redef,attr-defined] |
|
|
|
Undefined as Undefined, |
|
|
|
from pydantic.fields import ( |
|
|
|
Undefined as Undefined, # type: ignore[no-redef,attr-defined] |
|
|
|
) |
|
|
|
from pydantic.fields import ( # type: ignore[no-redef, attr-defined] |
|
|
|
UndefinedType as UndefinedType, # noqa: F401 |
|
|
|
from pydantic.fields import ( # type: ignore[no-redef, attr-defined]; noqa: F401 |
|
|
|
UndefinedType as UndefinedType, |
|
|
|
) |
|
|
|
from pydantic.schema import field_schema |
|
|
|
from pydantic.schema import ( # type: ignore[no-redef] # noqa: F401 |
|
|
|
get_annotation_from_field_info as get_annotation_from_field_info, |
|
|
|
) |
|
|
|
from pydantic.schema import ( |
|
|
|
field_schema, |
|
|
|
get_flat_models_from_fields, |
|
|
|
get_model_name_map, |
|
|
|
model_process_schema, |
|
|
|
) |
|
|
|
from pydantic.schema import ( # type: ignore[no-redef] # noqa: F401 |
|
|
|
get_annotation_from_field_info as get_annotation_from_field_info, |
|
|
|
from pydantic.typing import ( # type: ignore[no-redef]; noqa: F401 |
|
|
|
evaluate_forwardref as evaluate_forwardref, |
|
|
|
) |
|
|
|
from pydantic.typing import ( # type: ignore[no-redef] |
|
|
|
evaluate_forwardref as evaluate_forwardref, # noqa: F401 |
|
|
|
) |
|
|
|
from pydantic.utils import ( # type: ignore[no-redef] |
|
|
|
lenient_issubclass as lenient_issubclass, # noqa: F401 |
|
|
|
from pydantic.utils import ( # type: ignore[no-redef]; noqa: F401 |
|
|
|
lenient_issubclass as lenient_issubclass, |
|
|
|
) |
|
|
|
|
|
|
|
from fastapi.openapi.constants import REF_PREFIX as REF_PREFIX |
|
|
|
|
|
|
|
GetJsonSchemaHandler = Any # type: ignore[assignment,misc] |
|
|
|
JsonSchemaValue = Dict[str, Any] # type: ignore[misc] |
|
|
|
CoreSchema = Any # type: ignore[assignment,misc] |
|
|
|