swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.94k stars 6.03k forks source link

[python] Adding support for python FastAPI as server stub and SQLAlchemy ORM #11160

Open nicop311 opened 3 years ago

nicop311 commented 3 years ago
Description

Hello, I was wondering if there are any ideas or plans to implement a new server stub option for python that would rely on FastAPI. This would be an alternative to the current python server stub using python Flask and zalando/connexion.

And I was wondering if this could also use SQLAlchemy ORM (object relational mapper) to handle models and databases. Because I think this lacks the current python server stub.

Swagger-codegen version

3.0.27

Related issues/PRs

My question is related to this How to properly initialize Connexion and SQLAlchemy in Flask generated main.py, and more precisely related to this comment.

Summary: the Swagger-codegen python flask server stub models are very different from the official zalando/connexion SQLAlchemy ORM example. And I don't understand why and how to use the Swagger-codegen models and nor can I find real life examples of a python flask server (using DB) and generated with Swagger-codegen.

Suggest a fix/enhancement

FastAPI is gaining much popularity in the Python community and is under active development. And I find that the current swagger codegen python server stub using python Flask and zalando/connexion lack the support for ORM and DB support with SQLAlchemy.

Either enhance current python server stub (or explain to me how it works), or start fresh with FastAPI.

However if we forget about models and DB support, I have to say that using Flask + zalando/connexion is a nice idea.

tmkasun commented 3 years ago

I have the same problem, I have an OAS definition and wanted to start the implementation using FastAPI, But OAS generator doesn't support generating FastAPI server stub. If we can have a generator similar to Flask REST it would be easy to get start things with FastAPI