Skip to content

Commit

Permalink
Merge pull request #102 from 3GSDev/relative_url_path
Browse files Browse the repository at this point in the history
Relative url param.
  • Loading branch information
maximdanilchenko authored Aug 31, 2020
2 parents 4697941 + 3fe6a73 commit 9b110f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion aiohttp_apispec/aiohttp_apispec.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ async def doc_routes(app_):
async def swagger_handler(request):
return web.json_response(request.app["swagger_dict"])

app.router.add_route("GET", self.url, swagger_handler, name=NAME_SWAGGER_SPEC)
route_url = self.url
if not self.url.startswith("/"):
route_url = "/{}".format(self.url)
app.router.add_route("GET", route_url, swagger_handler, name=NAME_SWAGGER_SPEC)

if self.swagger_path is not None:
self._add_swagger_web_page(app, self.static_path, self.swagger_path)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,11 @@ async def test_not_register_route_for_none_url():
setup_aiohttp_apispec(app=app, url=None)
routes_count_after_setup_apispec = len(app.router.routes())
assert routes_count == routes_count_after_setup_apispec


async def test_register_route_for_relative_url():
app = web.Application()
routes_count = len(app.router.routes())
setup_aiohttp_apispec(app=app, url="api/swagger")
routes_count_after_setup_apispec = len(app.router.routes())
assert routes_count == routes_count_after_setup_apispec

0 comments on commit 9b110f7

Please sign in to comment.