我想为控制器get/post方法指定所需的JSON,以便在SwaggerUI中显示它。
例如,我希望request.json看起来像这样:
{
'key1': <int>,
'key2': <string>
}我按如下方式初始化SwaggerUI:
from sanic_openapi import swagger_blueprint, openapi_blueprint
app = Sanic(__name__)
# Set up SwaggerUI
app.blueprint(openapi_blueprint)
app.blueprint(swagger_blueprint)如何在parameters中同时显示两个密钥?

发布于 2018-02-10 20:16:57
有一个用于装饰视图函数的sanic_openapi.doc.consumes装饰器,用于记录它们的输入。这个装饰器函数的命名来自于OpenAPI specification。
以下是应用它的一种方法:
@app.post('/recording_test')
@doc.summary('Tests a recording')
@doc.consumes({'key1': str, 'key2': int}, location='body')
async def create_recording_test(request):
...您可以使用类对输入进行建模。
class RecordingTest:
key1 = str
key2 = int按照以下方式使用上面的模型化输入
@app.post('/recording_test')
@doc.summary('Tests a recording')
@doc.consumes(RecordingTest, location='body')
async def create_recording_test(request):
...发布于 2019-01-31 02:45:02
您没有在swagger中看到这个参数,因为您的get方法在class上。Sanic-openapi和Sanic-swagger还不支持基于类的视图。:(
https://stackoverflow.com/questions/48720482
复制相似问题