代码之家  ›  专栏  ›  技术社区  ›  ken

为什么@api.doc decorator.restplus不更新我所做的更改?

  •  1
  • ken  · 技术社区  · 7 年前

    @api.doc decorator不更新我在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

    正如您在这里看到的,文档没有根据我在中定义的字符串进行更新 室内装修设计师

    所以任何人都可以告诉我为什么会这样?如何解决这个问题?

    1 回复  |  直到 7 年前
        1
  •  3
  •   wamba kevin    7 年前

    事实上,它生成的第一条注释直接跟在函数声明后面的文档

    更改为:

    @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)