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

标签 python swagger swagger-ui flask-restplus

我使用 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/

相关文章:

python - Django ModelFormSet 单击 "Submit"保存表单但不更新到数据库

python - python中的模板

python - 命令提示符 : Set up for Python 2. 默认为 7

java - 使用 Swagger 的 CXF REST API 文档

servicestack - 如何隐藏不受 ServiceStack 的 SwaggerFeature 控制的路由?

python - 使用 CTypes 时检测从 Windows DLL 调用 Python 脚本

azure-devops - Azure Functions V2中的OpenAPI(又名Swagger)

gradle - Springfox swagger - 没有带有 spring boot jersey 和 gradle 的 api-docs

java - Swagger 不解析@XmlElementWrapper 注释

java - Swagger API 文档通过@ApiResponse 与映射作为responseContainer 不起作用