添加“值示例”昂首阔步,使用flask-restx

发布于 2025-01-20 14:59:09 字数 665 浏览 6 评论 0原文

如何在不使用装饰器 marshall_with/marshall_list_with 的情况下将“值示例”(如图 3 所示)添加到 swagger 文档中(图 4 是我想要放入“值示例”的位置)?因为该函数根据两个端点得到了两个响应 输入图片此处描述

在此处输入图像描述

在此处输入图像描述输入图片此处描述

how can i add 'value example' (like on picture 3) to swagger documentation (picture 4 is that where i want to put 'value example' in) without using decorator marshall_with/marshall_list_with? Cuz the function got two responses depending on two endpoints
enter image description here

enter image description here

enter image description here
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2025-01-27 14:59:09

您可以使用该模型来定义一个示例,例如:

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

You can use the model to define an example, like this:

...
# 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
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文