Skip to content

Commit 855399b

Browse files
committed
Merge branch 'release/1.1.2'
2 parents 7ceefb1 + 06c0433 commit 855399b

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
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(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "aiohttp-deps"
33
description = "Dependency injection for AioHTTP"
44
authors = ["Taskiq team <taskiq@no-reply.com>"]
55
maintainers = ["Taskiq team <taskiq@no-reply.com>"]
6-
version = "1.1.1"
6+
version = "1.1.2"
77
readme = "README.md"
88
license = "LICENSE"
99
classifiers = [

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)