I use the generated openapi python flask server (generated by openapi-generator-cli-4.2.3.jar) in a larger python project. One of the openapi controllers needs access to my database. Another controller needs a list of objects. Both information are already in use by the python project.
My Idea is to pass all needed information as variables into the main method (in __main__.py). But how can I pass the variables to the controller or to a function in it? Are there other (better) ways?
openapi main method:
def main(): # add: db_connection:dict, my_object:list
app = connexion.App(__name__, specification_dir='./openapi/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('openapi.yaml',
arguments={'title': 'My API'},
pythonic_params=True)
app.run(port=8080)
Thank you for your help!
I found the following question on github, but no practical solution: https://github.com/zalando/connexion/issues/516