对于FastAPI PYDANIC接口,我希望是尽可能可接受的,比如接收字符串参数的整数并将该整数解析为字符串:
from pydantic import BaseModel
class FooBar(BaseModel):
whatever: str
FooBar(whatever=12)
提供:
ValidationError: 1 validation error for FooBar
whatever
Input should be a valid string [type=string_type, input_value=12, input_type=int]
For further information visit https://errors.pydantic.dev/2.4/v/string_type
我认为在早期版本中,这是可能的.
- Python3.10
- 夸张==2.4.2
- PYDANIC_CORE==2.10.1