我使用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)
这是我的浏览器中的结果:
正如您在此处看到的那样,文档未按照我在@api.doc
装饰器中定义的字符串进行更新。
所以任何人都可以让我知道为什么会这样吗?以及如何解决这个问题?
答案 0 :(得分:2)
实际上,它生成的文档的注释首先是在函数声明之后的
更改为:
@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)