RobbeSneyders commented on issue #35234:
URL: https://github.com/apache/airflow/issues/35234#issuecomment-1793449425

   Yes ideally, the following logic would be followed:
   
   1) The app is instantiated using Connexion. Using a Flask app with Connexion 
APIs instead will lose most of Connexion's functionality as mentioned above.
   
       ```python
       connexion_app = connexion.FlaskApp(__name__, **kwargs)
       ```
   
       The supported `kwargs` here are the same as the ones on the `FlaskApi` 
class or `add_api()` method. This could 
       simplify things as you're currently setting the same `kwargs` on 
multiple `FlaskApi`s in different places. You can still 
       override app level `kwargs` when registering an api if needed.
   
   2) You can access the underlying Flask app as before, which can be useful to 
set Flask-specific configuration.
   
       ```python
       flask_app = connexion_app.app
       ```
   
   3) Adding Apis / Blueprints must happen via the `add_api()` method of the 
Connexion app. This now does a lot more than just creating a `FlaskApi`.
   
       ```python
       connexion_app = connexion_app.add_api(spec, **kwargs)
       ```
   
       This means that everywhere you're now returning the `FlaskApi`, you 
should either:
       - Pass in the `connexion_app` and let the function register the api.
       - Let the function return the specification and any `kwargs` to override.
         - We do have an [API 
class](https://github.com/spec-first/connexion/blob/bcf4c63b32835eddd624d6b936abfccad1646908/connexion/middleware/main.py#L155)
 in connexion which can be used to represent this information. I would be 
willing to expose a proper interface to use it.
         - You could provide a similar class yourself, possibly with only 
limited options that you want the function to be able to override. This way 
you're not exposing anything Connexion-specific to the function.
   
   4) Adding error handlers must happen via the `add_error_handler()` method of 
the Connexion app. This method has the same interface as the one from Flask. 
But this means you need to have access to the `connexion_app` instead of the 
`flask_app` here.
   
   5)  You should run the Connexion app instead of the Flask app, using an ASGI 
server. If you run the Flask app directly, the Connexion middleware would not 
be called.
   
       ```shell
       $ gunicorn -k uvicorn.workers.UvicornWorker run:connexion_app
       ```
   
   Let me know if any of these points would be blocking, and we can look for 
solutions together.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to