Skip to content

Commit

Permalink
Merge branch 'release/1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Feb 5, 2024
2 parents 7ceefb1 + 06c0433 commit 855399b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions aiohttp_deps/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ async def event_handler(app: web.Application) -> None: # noqa: C901
for route in app.router.routes():
if route.resource is None: # pragma: no cover
continue
if hide_heads and route.method.lower() == "HEAD": # pragma: no cover
if hide_heads and route.method.upper() == "HEAD":
continue
if hide_options and route.method.lower() == "OPTIONS": # pragma: no cover
if hide_options and route.method.upper() == "OPTIONS":
continue
if isinstance(route._handler, InjectableFuncHandler):
extra_openapi = getattr(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "aiohttp-deps"
description = "Dependency injection for AioHTTP"
authors = ["Taskiq team <[email protected]>"]
maintainers = ["Taskiq team <[email protected]>"]
version = "1.1.1"
version = "1.1.2"
readme = "README.md"
license = "LICENSE"
classifiers = [
Expand Down
30 changes: 30 additions & 0 deletions tests/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,33 @@ async def my_handler(param: TestModel = Depends(Json())) -> None:
"schema"
]["properties"]["mt"]["type"]
assert oapi_validation_type == validation_type


@pytest.mark.anyio
@pytest.mark.parametrize(
["method", "option_name"],
[("HEAD", "hide_heads"), ("OPTIONS", "hide_options")],
)
async def test_method_skips(
my_app: web.Application,
aiohttp_client: ClientGenerator,
method: str,
option_name: str,
) -> None:
openapi_url = "/my_api_def.json"
my_app.on_startup.append(
setup_swagger(schema_url=openapi_url, **{option_name: True}),
)

async def my_handler() -> None:
"""Nothing."""
return web.Response()

my_app.router.add_route(method, "/", my_handler)
my_app.router.add_route("GET", "/", my_handler)

client = await aiohttp_client(my_app)
response = await client.get(openapi_url)
schema = await response.json()
assert "get" in schema["paths"]["/"]
assert method.lower() not in schema["paths"]["/"]

0 comments on commit 855399b

Please sign in to comment.