How to use the connexion.AioHttpApp function in connexion

To help you get started, we’ve selected a few connexion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_no_swagger_ui(aiohttp_api_spec_dir, aiohttp_client):
    options = {"swagger_ui": False}
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     options=options, debug=True)
    app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_ui = yield from app_client.get('/v1.0/ui/')
    assert swagger_ui.status == 404

    app2 = AioHttpApp(__name__, port=5001,
                      specification_dir=aiohttp_api_spec_dir,
                      debug=True)
    options = {"swagger_ui": False}
    app2.add_api('swagger_simple.yaml', options=options)
    app2_client = yield from aiohttp_client(app.app)
    swagger_ui2 = yield from app2_client.get('/v1.0/ui/')
    assert swagger_ui2.status == 404
github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_swagger_ui_static(aiohttp_api_spec_dir, aiohttp_client):
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     debug=True)
    app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_ui = yield from app_client.get('/v1.0/ui/lib/swagger-oauth.js')
    assert swagger_ui.status == 200

    app_client = yield from aiohttp_client(app.app)
    swagger_ui = yield from app_client.get('/v1.0/ui/swagger-ui.min.js')
    assert swagger_ui.status == 200
github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_no_swagger_json(aiohttp_api_spec_dir, aiohttp_client):
    """ Verify the swagger.json file is not returned when set to False when creating app. """
    options = {"swagger_json": False}
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     options=options,
                     debug=True)
    app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_json = yield from app_client.get('/v1.0/swagger.json')  # type: flask.Response
    assert swagger_json.status == 404
github zalando / connexion / tests / aiohttp / test_aiohttp_simple_api.py View on Github external
def test_swagger_json(aiohttp_api_spec_dir, aiohttp_client):
    """ Verify the swagger.json file is returned for default setting passed to app. """
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     debug=True)
    api = app.add_api('swagger_simple.yaml')

    app_client = yield from aiohttp_client(app.app)
    swagger_json = yield from app_client.get('/v1.0/swagger.json')

    assert swagger_json.status == 200
    json_ = yield from swagger_json.json()
    assert api.specification.raw == json_
github zalando / connexion / tests / aiohttp / test_aiohttp_app.py View on Github external
def test_app_add_two_apis_error_with_only_one_api(aiohttp_api_spec_dir):
    spec_dir = '..' / aiohttp_api_spec_dir.relative_to(TEST_FOLDER)
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=spec_dir,
                     debug=True,
                     only_one_api=True)
    app.add_api('swagger_empty_base_path.yaml')

    with pytest.raises(ConnexionException) as exc_info:
        app.add_api('swagger_empty_base_path.yaml')

    assert exc_info.value.args == (
        "an api was already added, "
        "create a new app with 'only_one_api=False' "
github zalando / connexion / tests / aiohttp / test_aiohttp_app.py View on Github external
def test_app_get_root_path_not_in_sys_modules(sys_modules_mock, aiohttp_api_spec_dir):
    app = AioHttpApp('connexion', port=5001,
                     specification_dir=aiohttp_api_spec_dir)
    assert app.get_root_path().endswith(os.sep + 'connexion') == True
github zalando / connexion / tests / aiohttp / test_aiohttp_api_secure.py View on Github external
def test_secure_app(oauth_requests, aiohttp_api_spec_dir, aiohttp_client):
    # Create the app and run the test_app testcase below.
    app = AioHttpApp(__name__, port=5001,
                     specification_dir=aiohttp_api_spec_dir,
                     debug=True)
    app.add_api('swagger_secure.yaml')
    app_client = yield from aiohttp_client(app.app)

    post_hello = yield from app_client.post('/v1.0/greeting/jsantos')
    assert post_hello.status == 401

    headers = {'Authorization': 'Bearer 100'}
    post_hello = yield from app_client.post(
        '/v1.0/greeting/jsantos',
        headers=headers
    )

    assert post_hello.status == 200
    assert (yield from post_hello.json()) == {"greeting": "Hello jsantos"}
github OpenAPITools / openapi-generator / samples / server / petstore / python-aiohttp / openapi_server / __init__.py View on Github external
def main():
    options = {
        "swagger_ui": True
        }
    specification_dir = os.path.join(os.path.dirname(__file__), 'openapi')
    app = connexion.AioHttpApp(__name__, specification_dir=specification_dir, options=options)
    app.add_api('openapi.yaml',
                arguments={'title': 'OpenAPI Petstore'},
                pythonic_params=True,
                pass_context_arg_name='request')
    app.run(port=8080)
github zalando / connexion / examples / openapi3 / reverseproxy_aiohttp / app.py View on Github external
exc.log(request)
        await self.raise_error(request)


def hello(request):
    ret = {
        "host": request.host,
        "scheme": request.scheme,
        "path": request.path,
        "_href": str(request.url)
    }
    return web.Response(text=json.dumps(ret), status=200)


if __name__ == '__main__':
    app = connexion.AioHttpApp(__name__)
    app.add_api('openapi.yaml', pass_context_arg_name='request')
    aio = app.app
    reverse_proxied = XPathForwarded()
    aio.middlewares.append(reverse_proxied.middleware)
    app.run(port=8080)