def __init__(self, import_name, **kwargs): resolver = RestyResolver('cmk.gui.plugins.openapi.endpoints') resolver.function_resolver = wrap_result(resolver.function_resolver, with_user) kwargs.setdefault('resolver', resolver) super(CheckmkApiApp, self).__init__(import_name, api_cls=CheckmkApi, **kwargs)
def create_app(): """ Creates the application for webapp utils. """ utils_app = connexion.App("webapp-utils", options={ 'swagger_ui': True, 'openapi_spec_path': '/openapi.json' }) utils_app.add_api(SPEC, resolver=RestyResolver('app'), validate_responses=True, strict_validation=True, base_path='/api') @utils_app.app.after_request def set_default_headers(response): # pylint: disable=unused-variable response.headers["Access-Control-Allow-Origin"] = "*" response.headers[ "Access-Control-Allow-Headers"] = "Content-Type, Access-Control-Allow-Headers, \ Authorization, X-Requested-With, x-rh-identity" response.headers[ "Access-Control-Allow-Methods"] = "GET, OPTIONS, PATCH, POST" return response return utils_app
def test_client(): app = connexion.App(__name__, specification_dir='../swagger') app.add_api(SWAGGER_ROOT, resolver=RestyResolver('api')) FlaskInjector(app=app.app, modules=[test_elasticsearch_configure, test_redis_configure]) test_client = app.app.test_client() return test_client
def create_app() -> connexion.FlaskApp: # create connexion app con_app: FlaskApp = connexion.App(__name__) # con_app.server = 'gevent' con_app.specification_dir = specification_dir con_app.resolver = RestyResolver('sakura_village.api') # setup OpenAPI specification con_app.add_api(specification_dir.joinpath('openapi.yml'), base_path="/api") # setup flask app flask_app: Flask = con_app.app flask_app.config.from_mapping( yaml.load(open(config_path, encoding='utf-8'))) # setup flask extensions ADMIN.init_app(flask_app) DB.init_app(flask_app) MIGRATE.init_app(flask_app, DB) # discover models discover_models() # setup extra flask blueprints for bp, prefix in discover_blueprint(): flask_app.register_blueprint(BP, url_prefix=prefix) # # factory end here # ======================================================================== return con_app
def __init__(self): self._db_session = init_db('sqlite:///pybloods.db') self._app = connexion.FlaskApp(__name__) self._app.add_api('openapi/v1.yaml', resolver=RestyResolver('pybloods.api.handler')) @self._app.app.teardown_appcontext def shutdown_session(exception=None): self._db_session.remove()
def create_app(): app = connexion.App(__name__, specification_dir='swagger/') app.app.config.from_object(config_by_name[getenv('ENV', 'dev')]) env = Environment(loader=FileSystemLoader('swagger/')) swagger_string = env.get_template('main.yaml').render() specification = yaml.safe_load(swagger_string) app.add_api(specification, resolver=RestyResolver('api'), options={"swagger_ui": app.app.config.get("SWAGGER_UI")}) application = app.app db.init_app(application) return app
from connexion import RestyResolver import connexion from injector import Binder from flask_injector import FlaskInjector, inject from services.database_helper import TableProvider def configure(binder: Binder): binder.bind(TableProvider, TableProvider()) return binder if __name__ == '__main__': app = connexion.App(__name__, specification_dir='swagger/') app.add_api('schema.yaml', resolver=RestyResolver('api')) FlaskInjector(app=app.app, modules=[configure]) app.run(5000)
from connexion import RestyResolver from connexion.exceptions import ProblemException from flask_injector import FlaskInjector from injector import Binder import errorhandler import orm from services.provider.ItemsProvider import ItemsProvider db_session = None def configure(binder: Binder) -> Binder: binder.bind( ItemsProvider, ItemsProvider(db_session) # ItemsProvider([{"Name": "Test 1"}]) ) """Configure swagger yaml, db, dependency injection classes and error handlers""" if __name__ == '__main__': app = connexion.FlaskApp(__name__, port=9090, specification_dir='api/swagger/') app.add_api('helloworld-api.yaml', resolver=RestyResolver('api')) db_session = orm.init_db('sqlite:///:memory:') FlaskInjector(app=app.app, modules=[configure]) app.add_error_handler(ZeroDivisionError, errorhandler.render_unauthorized) app.add_error_handler(ProblemException, errorhandler.render_customexception) app.run() application = app.app
import json import os from pathlib import Path import unittest from io import BytesIO import connexion from connexion import RestyResolver BASE_URL = 'http://127.0.0.1:5000/api' BASE_DIR = Path(__file__).parents[1] UPLOAD_DIR = os.path.join(BASE_DIR, 'uploads') flask_app = connexion.FlaskApp(__name__) flask_app.add_api('swagger.yaml', resolver=RestyResolver('api')) class TestFlaskApi(unittest.TestCase): def setUp(self): flask_app.app.config['DEBUG'] = False flask_app.app.config['TESTING'] = True self.client = flask_app.app.test_client() # def test_upload(self): # import io # test_file_binary = b'ABCDE{FG.}.?!@#()*^&*(\n\n\r\t\n h' # data = {'file_binary': (io.BytesIO(test_file_binary), 'test_file_binary')} # response = self.client.post( # ('/api/upload?user_name=mahdi&file_name=test_file_binary'), # data=data, # content_type='multipart/form-data'
import connexion from connexion import RestyResolver from flask import request, render_template from intellisense.utils import get_recommendations_list options = {"swagger_ui": True, 'swagger_url': '/api'} connexion_app = connexion.FlaskApp(__name__, specification_dir='swagger/', options=options) app = connexion_app.app connexion_app.add_api('api.yaml', resolver=RestyResolver('api')) @app.route('/', methods=['POST', 'GET']) def io_html(): hints = [] if request.method == 'POST': word = request.form['word'] hints.append(get_recommendations_list(word)) return render_template('io.html', hints=hints) else: return render_template('io.html') if __name__ == '__main__': app.run(port=5000, debug=True)
import logging import os import connexion from connexion import RestyResolver from flask_cors import CORS logging.basicConfig(level=logging.INFO) app = connexion.FlaskApp(__name__) app.app.config['JUPYTERHUB_TOKEN'] = os.environ['JUPYTERHUB_TOKEN'] app.app.config['JUPYTERHUB_URL'] = os.environ['JUPYTERHUB_URL'] base_path = os.environ.get('BASE_PATH', '') resolver = RestyResolver('ewatercycle_experiment_launcher.api') app.add_api('openapi.yaml', resolver=resolver, validate_responses=True, base_path=base_path) CORS(app.app)
#!/usr/bin/env python import logging import connexion from resolver import ApiResolver from connexion import RestyResolver if __name__ == '__main__': logging.basicConfig(format='%(asctime)-15s %(message)s', level=logging.DEBUG) # create the flask application app = connexion.FlaskApp(__name__, debug=True) # create the bindings, if you use demo2.yaml you will need to use ApiResolver app.add_api('demo.yaml', arguments={'title': 'Demo Server'}, resolver=RestyResolver('api'), resolver_error=501) # start the application, in debug mode this will auto reload. app.run(port=5000, host=None, server='flask', debug=True)