【问题标题】:Adding 'Value Example' to swagger, using flask-restx使用 flask-restx 将 \'Value Example\' 添加到招摇中
【发布时间】: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


    【解决方案1】:

    您可以使用模型来定义示例,如下所示:

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

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      • 2021-08-22
      • 2017-10-06
      • 2021-05-15
      相关资源
      最近更新 更多