flask-rest-jsonapi icon indicating copy to clipboard operation
flask-rest-jsonapi copied to clipboard

afer 0.27.0 decorators supplied through Api.__init__ no longer work

Open tadams42 opened this issue 5 years ago • 2 comments

Following code:

from flask_rest_jsonapi import Api
from flask_jwt_extended import jwt_required

api = Api(decorators=(jwt_required,))

no longer causes JWT validation meaning I'm able to access endpoints with or without JWT.

Documentation still claims it should work.

In 0c212bd71e9f46ab633d93703bc29c1009222554 we see that using supplied decorators is removed but it is not clear why.

  • What is alternative way of decorating all endpoints with one or more decorators?
  • Can you please document this or at least remove no longer true docs from api.rst?

tadams42 avatar Apr 29 '19 11:04 tadams42

Indeed, that commit should be reverted unless there is a good alternative. One alternative is to register the Api() as a blueprint and apply a decorator to before_request:

bp = Blueprint("api", __name__)
@bp.before_request
@decorator
def before_request():
    """ Apply decorator to all endpoints. """
    pass
api = Api(app, bp)

https://stackoverflow.com/questions/37323089/how-to-apply-decorator-to-all-blueprint-urls-in-flask

fmorato avatar May 12 '19 20:05 fmorato

Any follow ups. It will be good just to remove it form documentaiton if it not plan to support it

igieon avatar Feb 17 '21 10:02 igieon