在使用 Flask-RESTX 中为 Swagger 添加“值示例”

3
我该如何在 Swagger 文档中添加“值示例”(如图片 3 所示),而不使用装饰器 marshall_with/marshall_list_with?因为该函数根据两个端点有两个响应。(图片 4 是我想要放置“值示例”的位置)enter image description here

enter image description here

enter image description here enter image description here

1个回答

0

您可以使用模型来定义一个示例,就像这样:

...
# 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
...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接