diff --git a/example/example_serpyco_aiohttp.py b/example/example_serpyco_aiohttp.py index b3b8db4..113d804 100644 --- a/example/example_serpyco_aiohttp.py +++ b/example/example_serpyco_aiohttp.py @@ -47,11 +47,13 @@ async def get_user(request, hapic_data: HapicData): web.get(r'/user/{id}', get_user), ]) +context = AiohttpContext( + app, + default_error_builder=SerpycoDefaultErrorBuilder() +) hapic.set_context( - AiohttpContext( - app, - default_error_builder=SerpycoDefaultErrorBuilder() - ) + context ) +hapic.add_documentation_view("/api/doc") print(json.dumps(hapic.generate_doc())) web.run_app(app) diff --git a/hapic/ext/aiohttp/context.py b/hapic/ext/aiohttp/context.py index bae729b..e9df696 100644 --- a/hapic/ext/aiohttp/context.py +++ b/hapic/ext/aiohttp/context.py @@ -207,12 +207,10 @@ def add_view( http_method: str, view_func: typing.Callable[..., typing.Any], ) -> None: - # TODO BS 2018-07-15: to do - raise NotImplementedError("todo") + self.app.router.add_routes([web.route(http_method, path=route, handler=view_func)]) def serve_directory(self, route_prefix: str, directory_path: str) -> None: - # TODO BS 2018-07-15: to do - raise NotImplementedError("todo") + self.app.router.add_static(route_prefix, path=directory_path) def is_debug(self,) -> bool: return self._debug