flask-pydantic icon indicating copy to clipboard operation
flask-pydantic copied to clipboard

Can this library integrate openapi

Open suoaao opened this issue 3 years ago • 6 comments

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.

suoaao avatar Dec 03 '20 04:12 suoaao

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

bauerji avatar Dec 03 '20 18:12 bauerji

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.

miquelvir avatar Apr 11 '21 08:04 miquelvir

@bauerji I have a working prototype, but I needed to convert Flask Pydantic to a proper flask extension. Have you worked on this?

miquelvir avatar Apr 11 '21 22:04 miquelvir

@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 avatar Apr 12 '21 19:04 bauerji

@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 avatar Apr 12 '21 19:04 miquelvir

@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?

bauerji avatar Apr 12 '21 19:04 bauerji