Skip to content

Commit 2597990

Browse files
authored
Merge pull request #19 from taskiq-python/feature/skip-options
2 parents 8181574 + 3e418e7 commit 2597990

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

aiohttp_deps/swagger.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def setup_swagger( # noqa: C901
203203
swagger_ui_url: str = "/docs",
204204
enable_ui: bool = True,
205205
hide_heads: bool = True,
206+
hide_options: bool = True,
206207
title: str = "AioHTTP",
207208
description: Optional[str] = None,
208209
version: str = "1.0.0",
@@ -225,13 +226,14 @@ def setup_swagger( # noqa: C901
225226
:param swagger_ui_url: URL where swagger ui will be served.
226227
:param enable_ui: whether you want to enable bundled swagger ui.
227228
:param hide_heads: hide HEAD requests.
229+
:param hide_options: hide OPTIONS requests.
228230
:param title: Title of an application.
229231
:param description: description of an application.
230232
:param version: version of an application.
231233
:return: startup event handler.
232234
"""
233235

234-
async def event_handler(app: web.Application) -> None:
236+
async def event_handler(app: web.Application) -> None: # noqa: C901
235237
openapi_schema = {
236238
"openapi": "3.0.0",
237239
"info": {
@@ -245,7 +247,9 @@ async def event_handler(app: web.Application) -> None:
245247
for route in app.router.routes():
246248
if route.resource is None: # pragma: no cover
247249
continue
248-
if hide_heads and route.method == "HEAD":
250+
if hide_heads and route.method.lower() == "HEAD": # pragma: no cover
251+
continue
252+
if hide_options and route.method.lower() == "OPTIONS": # pragma: no cover
249253
continue
250254
if isinstance(route._handler, InjectableFuncHandler):
251255
extra_openapi = getattr(

0 commit comments

Comments
 (0)