I use pydantic model with custom type. Set in config arbitrary_types_allowed=True.
Without setting a parameter "response_model" it's work. But when I set this model in param:
fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'Foo'> is a valid pydantic field type
Pydantic class definition example:
import Foo
class Model(BaseModel):
id: str
custom: Optional[Foo] = Field(None)
status: str = None
fail_message: Optional[str] = None
params: Dict[str, Any] = None
@validator('custom')
def deserialize_model(cls, v):
return Foo.loads(v)
class Config:
arbitrary_types_allowed = True
json_encoders = {Foo: lambda v: v.dumps()}
I use pydantic model with custom type. Set in config arbitrary_types_allowed=True.
Without setting a parameter "response_model" it's work. But when I set this model in param:
Pydantic class definition example: