Skip to content

Commit

Permalink
Add the option for not register a docs route
Browse files Browse the repository at this point in the history
  • Loading branch information
TruePack committed Nov 20, 2019
1 parent 23acc4d commit 6e68c7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aiohttp_apispec/aiohttp_apispec.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ async def doc_routes(app_):

self._registered = True

async def swagger_handler(request):
return web.json_response(request.app["swagger_dict"])
if self.url is not None:
async def swagger_handler(request):
return web.json_response(request.app["swagger_dict"])

app.router.add_routes([web.get(self.url, swagger_handler)])
app.router.add_routes([web.get(self.url, swagger_handler)])

if self.swagger_path is not None:
self._add_swagger_web_page(app, self.static_path, self.swagger_path)
if self.swagger_path is not None:
self._add_swagger_web_page(app, self.static_path, self.swagger_path)

def _add_swagger_web_page(
self, app: web.Application, static_path: str, view_path: str
Expand Down
10 changes: 10 additions & 0 deletions tests/test_documentation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from aiohttp import web
from aiohttp_apispec import setup_aiohttp_apispec
from yarl import URL


Expand Down Expand Up @@ -137,3 +139,11 @@ async def test_app_swagger_json(aiohttp_app):
},
sort_keys=True,
)


async def test_not_register_route_for_none_url():
app = web.Application()
routes_count = len(app.router.routes())
setup_aiohttp_apispec(app=app, url=None)
routes_count_after_setup_apispec = len(app.router.routes())
assert routes_count == routes_count_after_setup_apispec

0 comments on commit 6e68c7d

Please sign in to comment.