【发布时间】:2022-10-05 20:08:58
【问题描述】:
如何在不使用装饰器 marshall_with/marshall_list_with 的情况下将 \'value example\'(如图 3 所示)添加到 swagger 文档(图 4 是我想要放置 \'value example\' 的地方)?因为函数根据两个端点得到两个响应
标签: flask swagger swagger-ui marshalling flask-restx
如何在不使用装饰器 marshall_with/marshall_list_with 的情况下将 \'value example\'(如图 3 所示)添加到 swagger 文档(图 4 是我想要放置 \'value example\' 的地方)?因为函数根据两个端点得到两个响应
标签: flask swagger swagger-ui marshalling flask-restx
您可以使用模型来定义示例,如下所示:
...
# define model with example
example_response = api.model('ExampleResponse', {
'field_you_want': fields.String(example="Example Value")
})
@api.route("/")
class Example(Resource):
@api.marshal_with(example_response)
def get(self):
response = get_response()
return response, 200
...
【讨论】: