Open trim21 opened 2 years ago
Good job! Have a decorator for HTTP handler function is a great feature but the handler decorator should works with aiohttp_pydantic.oas.view.generate_oas()
. and the decorator should take the on_validation_error
hook in optional parameter.
Do you want to try to create a Pull requests ?
Sorry to say that, but I'm lazy to create a PR for this...
And I don't use this OAS feature.
No problem, I try to do that the next week. Thanks for your message it's always good to know how people use aiohttp-pydantic or what's it need.
No problem, I try to do that the next week.
@Maillol Is it now possible to use decorator instead of class based view?
You can try this branch.
https://github.com/Maillol/aiohttp-pydantic/tree/add-decorator-to-use-with-web-handler-fonction
from aiohttp_pydantic.decorator import inject_params
@inject_params
async def get(request, name: str = "") -> r200[list[Friend]]:
# request parameter is optional
@inject_params
async def get(name: str = "") -> r200[list[Friend]]:
# You can add custom on_validation_error function
async def on_validation_error(exception: ValidationError, context: CONTEXT) -> StreamResponse:
...
@inject_params(on_validation_error=on_validation_error)
async def get(name: str = "") -> r200[list[Friend]]:
...
I'm using handle (
async def handle(request) -> Response
) in my aiohttp application.it looks like currently it only support class based view, not request.
I try a code snippet to make it work: (most of code are copied from inner)
there is another sugestion:
all
*Getter.inject
can be asynchronous function, and just callawait injector.inject(request, args, kwargs)
withoutiscoroutinefunction
call. ( and putBodyGetter
at last )