Open torx-cz opened 4 months ago
Hi @torx-cz
You can do it with @decorate_view - which decorates your view function before any validation
from ninja.decorators import decorate_view
def my_header_checker(func):
def wrapper(request, *a, **kw):
# check here !<----
return func(request, *a, **kw)
return wrapper
@router.get(...)
@decorate_view(my_header_checker)
def some_endpoint_handler(request: HttpRequest, data: SomeSchema)
...
Hello, I'd like to ask for your opinion.
I need to do a header check (if the version is correct), but it needs to be before the input schema validation. The problem I'm having is that as soon as I use the decorator, a validation error (
422
) is thrown before my custom check, (it can throw406
status code). I want a different order.This would be fairly easy using Django-middleware however, I only need to do this on certain endpoints.
Example decorator:
I want to ask if there is any way to run some checks before input validation.
Thank you for your time and reply.