I am interested in integrating a swagger-codegen generated Python server with an existing Flask application. swagger-codegen generates a Python implementation based on the Connexion library from a Swagger API specification.
The examples I have found all seem to expect that connexion.App manages the entire flask application.
import connexion
app = connexion.App(__name__, specification_dir='swagger/')
app.add_api('my_api.yaml')
app.run(port=8080)
However, I have existing blueprints, config and sqlalchemy models I would like to integrate with the generated Connexion API. It looks like connexion.App.app is the underlying Flask app. One option might be to reach in and extend the Connexion Flask application, perhaps something like this:
import connexion
app = connexion.App(__name__, specification_dir='swagger/')
app.app.config.from_pyfile('...')
db.init_app(app.app)
for blueprint in my_blueprints:
app.app.register_blueprint(blueprint)
app.add_api('my_api.yaml')
app.run(port=8080)
Trying to piggyback on the heavily customized Connexion Flask app seems simpler than integrating the bare blueprint from connexion.Api into my existing Flask app. However, I cannot easily tell whether Connexion is designed to play nicely with non-Connexion managed blueprints.
What is the best way to integrate the Connexion Swagger defined API within an existing, traditional Flask application? Has anyone gone down this path?