Closed guneemwelloeux closed 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
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
It's worth it because developers can understand your API more easily.
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.
responses
parameter in the @app.get decorator ✅extra_responses
parameter ✅responses
.Since this API is used in production:
data
key that would contain the list.extra_responses
. I tried using pydantic'sschema_of
function insideextra_responses
, but that's not compatible because of the use ofdefinitions
.Note that
pydantic.schema_of(List[<child of pydantic.BaseModel>])
does work.