flask-pydantic
flask-pydantic copied to clipboard
Can this library integrate openapi
In this way
@app.route("/kwargs")
@validate()
def test_route_kwargs(query:Query, body:Body)->MyModel:
return MyModel(...)
In : test_route_kwargs.__annotations__
Out:
{'query': Query,
' body':Body,
'return': MyModel}
It can get all the conditions for generating openapi.
Hi,
Do you mean to automatically generate route serving openapi documentation of all routes? This is actually a good idea. I will try to find time to implement it.
Jirka
I agree with @crowser ! I wanted to use this for a project, only drawback: no auto generated docs. This module could be the perfect reason to stay with all the benefeits of Flask + many of Fastapi.
Pydantic models can be transformed to compliant schemas out of the box (https://pydantic-docs.helpmanual.io/usage/schema/). So the only thing is generating the docs for each view/function, and then providing a swagger.json endpoint. Optionally, we could have out of the box a /redoc and /swagger endpoints with the doc ui.
@bauerji I have a working prototype, but I needed to convert Flask Pydantic to a proper flask extension. Have you worked on this?
@miquelvir I have though about it but haven't worked on it yet. Could you share me please your solution? I don't think it is necessary to convert it to flask extension. I don't want to make such a backward incompatible change.
@bauerji I needed to convert it to a Flask extension, how would you do it without? i will share when ive got a moment
@miquelvir I can imagine you might need it for list of routes but that can be stored in validate
decorator. For adding docs routes too maybe, but that can be overcome by passing application as function parameter. Do you have any other reason for it?