我们可以自动将 Marshmallow shemas 添加到 swagger `api.doc()` 中吗?

GRS*_*GRS 4 python api flask marshmallow

我有一个 API,我想通过 Swagger UI 显示它。我这样做是通过:

bp = Blueprint("api", __name__)
api = Api(bp)

@api.doc(
    description="Description, I want to add schema here",
    responses={200: "Success"},
)
def post(self):
    """ Appears in Title of Swagger
        Authorization: Bearer <auth-key>
    """
    return jsonify(200)
Run Code Online (Sandbox Code Playgroud)

假设我有以下架构:

class SomeSchema(Schema):
    id = fields.String(required=True)
Run Code Online (Sandbox Code Playgroud)

有没有办法自动为 swagger 显示此架构?比如我想填写:

在此输入图像描述

自动包含字段。

Jér*_*ôme 6

这正是apispec的用途。它是由棉花糖团队开发的。

(您可能还对使用 Marshmallow 解析输入的webargs感兴趣。以及将 apispec 和 webargs 集成到完整 API 框架中的Flask-smorest 。)

免责声明:marshmallow/apispec/webargs/flask-smorest 维护者。