More robust dependency injection rule generation
so1n opened this issue · 0 comments
Is your feature request related to a problem? Please describe.
Currently, the function signature of the routing function is extracted in the initialization phase, and then when the request hits the route, the corresponding value is obtained from the request object based on the function signature and the value is injected into the routing function.
In the current version this is a viable solution, but each new function related to reading routing function signatures requires a different parsing method (e.g. openapi is a different set of parsing methods), forcing the project to generate redundant code
Describe the solution you'd like
The following code:
def demo(
a: str = Query.t(),
b: int = Query.t()
) -> None:
pass
When Pait
resolves the routing function during the initialization phase, the following rules are generated for this routing function:
PaitRule(name="a", type_=str, field=Query.t())
PaitRule(name="b", type_=int, field=Query.t())
This is the most basic rule, based on which the method of generating OpenAPI documents can be made easier and the speed of dependency injection can be accelerated.
In addition to this, some additional features can be added, such as auto-fill type, such as route code
def demo(
a = Query.t(default=""),
b: int = Query.t()
) -> None:
pass
Pait
has the ability to generate rules for routing, as follows:
PaitRule(name="a", type_=str, field=Query.t())
PaitRule(name="b", type_=int, field=Query.t())
However, there is one drawback, Pait
cannot properly resolve the properties of Cbv routes during the initialization phase