Swagger UI 显示 API 不支持的 HTTP HEAD 方法
Swagger UI showing HTTP HEAD method which is not supported by the API
我使用 python 的 aiohttp 模块开发了一个 API 网关。
现在,我正在尝试为同一台服务器开发 swagger UI。
现在,我通过在函数中指定 commends 来实现。
下面是一个例子 -
async def list_models(request):
"""
List models API.
---
tags:
- models
summary: List models
description: This API lists models created till date.
produces:
- application/json
responses:
"200":
description: List of all the models created.
"""
url = MODELPERSISTENCE_SERVICE_URL + '/models/'
return await execute_get_request(url)
然而,当我部署服务器并访问 swagger UI 时,我发现此 API 也支持 HTTP HEAD 方法,这是错误的。
如您所见,我没有在规范中的任何地方提及 HEAD 或 GET 方法。如何防止 HEAD 方法在 swagger UI 中弹出?
这是显示 HEAD 方法的图片 -
你用add_get
添加路由吗?那么Swagger也没有错
aiohttp creates HTTP HEAD handlers by default when using the router
's add_get
method. If you don't want them, register the routes with the allow_head=False
named parameter.
我使用 python 的 aiohttp 模块开发了一个 API 网关。
现在,我正在尝试为同一台服务器开发 swagger UI。 现在,我通过在函数中指定 commends 来实现。 下面是一个例子 -
async def list_models(request):
"""
List models API.
---
tags:
- models
summary: List models
description: This API lists models created till date.
produces:
- application/json
responses:
"200":
description: List of all the models created.
"""
url = MODELPERSISTENCE_SERVICE_URL + '/models/'
return await execute_get_request(url)
然而,当我部署服务器并访问 swagger UI 时,我发现此 API 也支持 HTTP HEAD 方法,这是错误的。
如您所见,我没有在规范中的任何地方提及 HEAD 或 GET 方法。如何防止 HEAD 方法在 swagger UI 中弹出?
这是显示 HEAD 方法的图片 -
你用add_get
添加路由吗?那么Swagger也没有错
aiohttp creates HTTP HEAD handlers by default when using the router
's add_get
method. If you don't want them, register the routes with the allow_head=False
named parameter.