diff --git a/src/apispec_webframeworks/aiohttp.py b/src/apispec_webframeworks/aiohttp.py index 25ee994..2394d37 100644 --- a/src/apispec_webframeworks/aiohttp.py +++ b/src/apispec_webframeworks/aiohttp.py @@ -60,8 +60,9 @@ def path_helper( **kwargs: Any, ) -> str | None: """Path helper that allows passing a aiohttp AbstractRoute""" + if route is None: + return None assert operations is not None - assert route is not None docstring = route.handler.__doc__ or "" operations.update( diff --git a/src/apispec_webframeworks/bottle.py b/src/apispec_webframeworks/bottle.py index ee1465e..77b97fd 100644 --- a/src/apispec_webframeworks/bottle.py +++ b/src/apispec_webframeworks/bottle.py @@ -67,8 +67,9 @@ def path_helper( **kwargs: Any, ) -> str | None: """Path helper that allows passing a bottle view function.""" + if view is None: + return None assert operations is not None - assert view is not None docstring = view.__doc__ or "" operations.update(yaml_utils.load_operations_from_docstring(docstring)) diff --git a/src/apispec_webframeworks/flask.py b/src/apispec_webframeworks/flask.py index c90e5dc..7c82cb5 100644 --- a/src/apispec_webframeworks/flask.py +++ b/src/apispec_webframeworks/flask.py @@ -132,7 +132,8 @@ def path_helper( **kwargs: Any, ) -> str | None: """Path helper that allows passing a Flask view function.""" - assert view is not None + if view is None: + return None assert operations is not None rule = self._rule_for_view(view, app=app) diff --git a/src/apispec_webframeworks/tornado.py b/src/apispec_webframeworks/tornado.py index 3025651..9ad3f0f 100644 --- a/src/apispec_webframeworks/tornado.py +++ b/src/apispec_webframeworks/tornado.py @@ -115,8 +115,9 @@ def path_helper( **kwargs: Any, ) -> str | None: """Path helper that allows passing a Tornado URLSpec or tuple.""" + if urlspec is None: + return None assert operations is not None - assert urlspec is not None if not isinstance(urlspec, URLSpec): urlspec = URLSpec(*urlspec) diff --git a/tests/test_ext_aiohttp.py b/tests/test_ext_aiohttp.py index 73521a1..107149d 100644 --- a/tests/test_ext_aiohttp.py +++ b/tests/test_ext_aiohttp.py @@ -99,3 +99,10 @@ async def hello(request): "responses": {"200": {"description": "A greeting to the client"}}, } assert paths["/hello"]["get"] == expected + + def test_path_without_route(self, spec): + spec.path( + path="/hello", + operations={"get": {"responses": {"200": {}}}}, + ) + assert "/hello" in get_paths(spec) diff --git a/tests/test_ext_bottle.py b/tests/test_ext_bottle.py index 45da63b..c8a6dc6 100644 --- a/tests/test_ext_bottle.py +++ b/tests/test_ext_bottle.py @@ -109,3 +109,10 @@ def handler(): spec.path(view=handler) assert "/pet/{pet_id}/{shop_id}" in get_paths(spec) + + def test_path_without_view(self, spec): + spec.path( + path="/hello", + operations={"get": {"responses": {"200": {}}}}, + ) + assert "/hello" in get_paths(spec) diff --git a/tests/test_ext_flask.py b/tests/test_ext_flask.py index c3356d4..b23674c 100644 --- a/tests/test_ext_flask.py +++ b/tests/test_ext_flask.py @@ -180,3 +180,10 @@ def get_pet(pet_id): spec.path(view=get_pet, app=app) assert "/pet/{pet_id}" in get_paths(spec) + + def test_path_without_view(self, spec): + spec.path( + path="/hello", + operations={"get": {"responses": {"200": {}}}}, + ) + assert "/hello" in get_paths(spec) diff --git a/tests/test_ext_tornado.py b/tests/test_ext_tornado.py index 6ab9013..1f163ef 100644 --- a/tests/test_ext_tornado.py +++ b/tests/test_ext_tornado.py @@ -154,3 +154,10 @@ def test_no_groups_in_path_with_extra_params(self, spec, Handler): path = "/helloworld" paths = get_paths(spec) assert path in paths + + def test_path_without_urlspec(self, spec): + spec.path( + path="/hello", + operations={"get": {"responses": {"200": {}}}}, + ) + assert "/hello" in get_paths(spec)