gpt4 book ai didi

python - 为什么 @api.doc 装饰器 python flask restplus 不更新我所做的更改?

转载 作者:太空宇宙 更新时间:2023-11-04 02:07:19 25 4
gpt4 key购买 nike

我使用 Flask-Restplus 开发我的 API。我想问一下,为什么 @api.doc 装饰器不更新我在 Swagger UI 中的更改?

这里是我定义的端点

@api.route('/create_user')
class User(Resource):
@api.response(201, 'User successfully created.')
@api.doc('create a new user')
@api.expect(_user, validate=True)
@api.marshal_list_with(_user, envelope='data')
def post(self):
"""Creates a new User """
data = request.json
return create_user(data=data)


@api.route('/get_user_list')
class UserList(Resource):
@api.doc('list_of_registered') //even I change here,in Swagger is still not update
@api.marshal_list_with(_user, envelope='data')
def get(self):
"""List all registered users"""
return get_all_users()

@api.route('/create_product')
class Product(Resource):
@api.response(201, 'Product successfully created.')
@api.doc('12345678') //here I state to this
@api.expect(_product, validate=True)
def post(self):
"""Creates a new User """
data = request.json
return create_product(data=data)

所以这是我浏览器中的结果:

enter image description here

正如您在这里看到的,文档没有根据我在 @api.doc 装饰器中定义的字符串进行更新。

所以谁能告诉我为什么会这样?以及如何解决这个问题?

最佳答案

事实上,它首先生成的文档是紧跟在函数声明之后的注释

改变它:

@api.route('/create_product')
class Product(Resource):
@api.response(201, 'Product successfully created.')
@api.doc('12345678') //here I state to this
@api.expect(_product, validate=True)
def post(self):
"""Creates a new User """
data = request.json
return create_product(data=data)

对此:

@api.route('/create_product')
class Product(Resource):
@api.response(201, 'Product successfully created.')
@api.doc('12345678') //here I state to this
@api.expect(_product, validate=True)
def post(self):
"""Creates a new Product """
data = request.json
return create_product(data=data)

关于python - 为什么 @api.doc 装饰器 python flask restplus 不更新我所做的更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54373759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com