Skip to content

Commit 4c7c2c1

Browse files
authored
Merge pull request #20 from taskiq-python/bugfix/hiding-methods
2 parents e84f4ba + 8d62c63 commit 4c7c2c1

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

aiohttp_deps/swagger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ async def event_handler(app: web.Application) -> None: # noqa: C901
247247
for route in app.router.routes():
248248
if route.resource is None: # pragma: no cover
249249
continue
250-
if hide_heads and route.method.lower() == "HEAD": # pragma: no cover
250+
if hide_heads and route.method.upper() == "HEAD":
251251
continue
252-
if hide_options and route.method.lower() == "OPTIONS": # pragma: no cover
252+
if hide_options and route.method.upper() == "OPTIONS":
253253
continue
254254
if isinstance(route._handler, InjectableFuncHandler):
255255
extra_openapi = getattr(

tests/test_swagger.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,33 @@ async def my_handler(param: TestModel = Depends(Json())) -> None:
750750
"schema"
751751
]["properties"]["mt"]["type"]
752752
assert oapi_validation_type == validation_type
753+
754+
755+
@pytest.mark.anyio
756+
@pytest.mark.parametrize(
757+
["method", "option_name"],
758+
[("HEAD", "hide_heads"), ("OPTIONS", "hide_options")],
759+
)
760+
async def test_method_skips(
761+
my_app: web.Application,
762+
aiohttp_client: ClientGenerator,
763+
method: str,
764+
option_name: str,
765+
) -> None:
766+
openapi_url = "/my_api_def.json"
767+
my_app.on_startup.append(
768+
setup_swagger(schema_url=openapi_url, **{option_name: True}),
769+
)
770+
771+
async def my_handler() -> None:
772+
"""Nothing."""
773+
return web.Response()
774+
775+
my_app.router.add_route(method, "/", my_handler)
776+
my_app.router.add_route("GET", "/", my_handler)
777+
778+
client = await aiohttp_client(my_app)
779+
response = await client.get(openapi_url)
780+
schema = await response.json()
781+
assert "get" in schema["paths"]["/"]
782+
assert method.lower() not in schema["paths"]["/"]

0 commit comments

Comments
 (0)