-
-
Notifications
You must be signed in to change notification settings - Fork 546
Description
Is your feature request related to a problem? Please describe.
In your docs for the new add_decorator functionality, you describe middleware as a suggested use-case.
Unfortunately, the order of decorator application is exactly the opposite of what I would expect to see for middleware!
For example, imagine the following definitions:
api = ninja.NinjaAPI()
api.add_decorator(decorator_1())
api.add_decorator(decorator_2())
router = ninja.Router()
router.add_decorator(decorator_3())
router.add_decorator(decorator_4())
api.add_router("/foo", router)
@router.get("/bar")
def my_op(...):
...I would expect the code to be run in the following order:
decorator_1decorator_2decorator_3decorator_4my_op
It is actually run in the following order:
decorator_4decorator_3decorator_2decorator_1my_op
Describe the solution you'd like
I'd like it to run in declaration order, outside-in:
decorator_1decorator_2decorator_3decorator_4my_op
It's currently running in reverse-declaration order, inside-out!
As someone used to how Django middleware works, this is extremely unintuitive. Worse, it means it's impossible to declare API-wide security-related decorators that are expected to run before any other decorators or operations.