def add_swagger_api_route(app, target_route, swagger_json_route): """ mount a swagger statics page. app: the aiohttp app object target_route: the path to mount the statics page. swagger_json_route: the path where the swagger json definitions is expected to be. """ static_root = get_swagger_static_root() swagger_body = generate_swagger( STATIC_ROOT, swagger_json_route ).encode("utf-8") async def swagger_ui(request): return web.Response(body=swagger_body) app.router.add_route("GET", target_route, swagger_ui) app.router.add_static(STATIC_ROOT, static_root)
def add_swagger_api_route(app, target_route, swagger_json_route): """ mount a swagger statics page. app: the aiohttp app object target_route: the path to mount the statics page. swagger_json_route: the path where the swagger json definitions is expected to be. """ static_root = get_swagger_static_root() swagger_body = generate_swagger( STATIC_ROOT, swagger_json_route ).encode("utf-8") async def swagger_ui(request): return web.Response(body=swagger_body, content_type="text/html") app.router.add_route("GET", target_route, swagger_ui) app.router.add_static(STATIC_ROOT, static_root)
def test_generate_swagger(): swagger_static_root = "/statics/_swagger" swagger_json_url = "/swagger.json" body = generate_swagger(swagger_static_root, swagger_json_url) assert swagger_static_root in body assert swagger_json_url in body