2

Try to create custom decorator to all method on class(the class is flask-restplus resoucure)

from flask_restplus import Resource, Api

test_blueprint = Blueprint('test', __name__)

test_api = Api(test_blueprint)

test_namespace = test_api.namespace('tests', description='Tests operations')

doc_messages = {
    200: "Success",
    400: "Validation Error",
    500: "Server Error"
}


@test_namespace.route("")

class TestApi(Resource):

      method_decorators = [test_namespace.doc(responses=doc_messages)]

      def get(self):
        return {"name": 2}


Not work like:

@test_namespace.route("")
class TestApi(Resource):
@test_namespace.doc(responses=doc_messages)
     def get(self):
        return {"name": 2}

The result is in the swagger, when on the first example i don't show the description of the responses but on the second example i see although they should be equal. My goal is to use the second example to create more complex decorators that should be in all the class methods, but I don't find a way to do it without duplicate cope

Dan Cohen
  • 43
  • 5

0 Answers0