如何让 aiohttp-swagger 识别 GET 查询变量?
How do I get aiohttp-swagger to recognize GET query variables?
我想在我的 python 项目中使用 aiohttp-swagger,但我不知道它如何处理 GET URL 和 POST 有效负载变量。我有这个基于 quick start example here 的示例代码。我所做的唯一更改是我在 GET URL.
中包含了一个查询参数
from aiohttp import web
from aiohttp_swagger import *
async def ping(request):
"""
---
description: This end-point allow to test that service is up.
tags:
- Health check
produces:
- text/plain
responses:
"200":
description: successful operation. Return "pong" text
"405":
description: invalid HTTP Method
"""
return web.Response(text="pong %s" % request.match_info['var']) # change here (1/2)
app = web.Application()
app.router.add_route('GET', "/ping/{var}", ping) # change here (2/2)
setup_swagger(app)
web.run_app(app, host="127.0.0.1")
生成的 Swagger/OpenAPI 页面似乎不知道该变量。我预计它会生成一个文本框,我可以在其中填写 "var" 查询变量的值。我如何使用 aio-http 执行此操作?可能吗?如果没有,是否有另一个库可以处理这个问题?
郑重声明,我有 C# 背景,并且我过去曾使用 Swashbuckle library.
您必须在注释中添加 parameters
属性。
工作示例:
from aiohttp import web
from aiohttp_swagger import *
async def ping(request):
"""
---
description: This end-point allow to test that service is up.
tags:
- Health check
parameters:
- in: query
name: var
produces:
- text/plain
responses:
"200":
description: successful operation. Return "pong" text
"405":
description: invalid HTTP Method
"""
return web.Response(text="pong %s" % request.match_info['var']) # change here (1/2)
app = web.Application()
app.router.add_route('GET', "/ping/{var}", ping) # change here (2/2)
setup_swagger(app)
web.run_app(app, host="127.0.0.1")
我想在我的 python 项目中使用 aiohttp-swagger,但我不知道它如何处理 GET URL 和 POST 有效负载变量。我有这个基于 quick start example here 的示例代码。我所做的唯一更改是我在 GET URL.
中包含了一个查询参数from aiohttp import web
from aiohttp_swagger import *
async def ping(request):
"""
---
description: This end-point allow to test that service is up.
tags:
- Health check
produces:
- text/plain
responses:
"200":
description: successful operation. Return "pong" text
"405":
description: invalid HTTP Method
"""
return web.Response(text="pong %s" % request.match_info['var']) # change here (1/2)
app = web.Application()
app.router.add_route('GET', "/ping/{var}", ping) # change here (2/2)
setup_swagger(app)
web.run_app(app, host="127.0.0.1")
生成的 Swagger/OpenAPI 页面似乎不知道该变量。我预计它会生成一个文本框,我可以在其中填写 "var" 查询变量的值。我如何使用 aio-http 执行此操作?可能吗?如果没有,是否有另一个库可以处理这个问题?
郑重声明,我有 C# 背景,并且我过去曾使用 Swashbuckle library.
您必须在注释中添加 parameters
属性。
工作示例:
from aiohttp import web
from aiohttp_swagger import *
async def ping(request):
"""
---
description: This end-point allow to test that service is up.
tags:
- Health check
parameters:
- in: query
name: var
produces:
- text/plain
responses:
"200":
description: successful operation. Return "pong" text
"405":
description: invalid HTTP Method
"""
return web.Response(text="pong %s" % request.match_info['var']) # change here (1/2)
app = web.Application()
app.router.add_route('GET', "/ping/{var}", ping) # change here (2/2)
setup_swagger(app)
web.run_app(app, host="127.0.0.1")