Repository navigation
Request: Support List[pydantic.BaseModel] as response #57
Environment:
RequestAdd support of List[] in ExplanationI'm trying to migrate an existing Flask API to Flask-OpenAPI, and I'm hitting an issue.
Since this API is used in production:
Note that |
Replies: 4 comments
|
I think class ResponseWithList(BaseModel):
__root__: List[Any]More information see https://docs.pydantic.dev/usage/models/#custom-root-types |
|
Hi @luolingchun, That's exactly what I needed. Thanks for pointing it out. Thanks |
|
It's worth it because developers can understand your API more easily. |
|
For future reference: Nowadays this would be from typing import Any
from pydantic import RootModel
ResponseWithList = RootModel[list[Any]]https://docs.pydantic.dev/latest/concepts/models/#rootmodel-and-custom-root-types |
I think
__root__can solve your problem:More information see https://docs.pydantic.dev/usage/models/#custom-root-types