You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request: Support List[pydantic.BaseModel] as response #56
I'm trying to migrate an existing Flask API to Flask-OpenAPI, and I'm hitting an issue.
Most of my endpoints return a JSON object, with the proper content type. This is compatible with the responses parameter in the @app.get decorator ✅
Other endpoints return a simple string, with text content type. This is compatible with the extra_responses parameter ✅
However, I do have a number of endpoints that return a JSON encoded list of objects, with content type JSON. This is not compatible with responses.
Since this API is used in production:
I can't afford to wrap these lists in "dummy" object with a data key that would contain the list.
I also don't really want to have to write a special dictionary to use in extra_responses. I tried using pydantic's schema_of function inside extra_responses, but that's not compatible because of the use of definitions.
Note that pydantic.schema_of(List[<child of pydantic.BaseModel>]) does work.
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.
Activity
luolingchun commentedon Feb 3, 2023
I think
__root__can solve your problem:More information see https://docs.pydantic.dev/usage/models/#custom-root-types
guneemwelloeux commentedon Feb 3, 2023
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 commentedon Feb 6, 2023
It's worth it because developers can understand your API more easily.