luolingchun / flask-openapi3

Generate REST API and OpenAPI documentation for your Flask project.
https://luolingchun.github.io/flask-openapi3/
MIT License
189 stars 29 forks source link

Request: Support List[pydantic.BaseModel] as response #56

Closed guneemwelloeux closed 1 year ago

guneemwelloeux commented 1 year ago

Environment:

Request

Add support of List[] in responses.

Explanation

I'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 pydantic.schema_of(List[<child of pydantic.BaseModel>]) does work.

luolingchun commented 1 year ago

I think __root__ can solve your problem:

class ResponseWithList(BaseModel):
    __root__: List[Any]

More information see https://docs.pydantic.dev/usage/models/#custom-root-types

guneemwelloeux commented 1 year ago

Hi @luolingchun,

That's exactly what I needed. Thanks for pointing it out. Do you think it would be worth adding a few lines on this in the Flask-OpenAPI documentation? I understand it's not anything to do with Flask-openapi itself, but it might be useful to mention it.

Thanks

luolingchun commented 1 year ago

It's worth it because developers can understand your API more easily.