title: How to pass a variable into Connexion Flask app context?
body: <p>I run Connexion/Flask app like this:</p>
  
  <pre><code>import connexion
  from flask_cors import CORS
  from flask import g
  
  app = connexion.App(__name__, specification_dir='swagger_server/swagger/')
  app.add_api('swagger.yaml')
  CORS(app.app)
  with app.app.app_context():
      g.foo = 'bar'
      q = g.get('foo') # THIS WORKS
      print('variable', q)
  app.run(port=8088, use_reloader=False)
  </code></pre>
  
  <p>somewhere else in code:</p>
  
  <pre><code>from flask import abort, g, current_app
  
  def batch(machine=None):  # noqa: E501
      try:
          app = current_app._get_current_object()
          with app.app_context:
              bq = g.get('foo', None) # DOES NOT WORK HERE
              print('variable:', bq)
          res = MYHandler(bq).batch(machine)
      except:
          abort(404)
      return res
  </code></pre>
  
  <p>This does not work - I am not able to pass variable ('bla') to second code example.</p>
  
  <p><strong>Any idea how to pass context variable correctly? Or how to pass a variable and use it globally for all Flask handlers?</strong></p>
  
  <p>I've tried this solution (which works): In first code section I'd add:</p>
  
  <pre><code>app.app.config['foo'] = 'bar'
  </code></pre>
  
  <p>and in second code section there would be:</p>
  
  <pre><code>bq = current_app.config.get('foo')
  </code></pre>
  
  <p>This solution does not use application context and I am not sure if it's a correct way.</p>