Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/apispec_webframeworks/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/apispec_webframeworks/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion src/apispec_webframeworks/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/apispec_webframeworks/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_ext_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions tests/test_ext_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions tests/test_ext_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions tests/test_ext_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)