Description
Is your feature request related to a problem? Please describe.
Currently, an endpoint function is supposed to expect the starlette
Request
object, and it is responsible to extract the raw data (body, parameters, headers, cookies etc) itself. This can lead to a lot of repeated code through various endpoints, and it also couples the endpoints implementation with the underlying system (specifically starlette
).
Describe the solution you'd like
Ideally, we can use the OpenAPI spec to automatically determine which arguments are expected by the operation the endpoint is responsible for, and require the endpoint function to have the same arguments in the signature. For example if we have an operation named fooBar
which handles GET /foo/{bar_id}
, with the bar_id
defined (in the parameters
property) as being of type: integer
, the expected endpoint function would have the signature:
def foo_bar(bar_id: int):
...
Body arguments could be specified as kwargs, with potentially a special extra_
kwarg for things like headers and cookies. Complex types could be defined from the OpenAPI
schemas using something like python-jsonschema-objects.
Describe alternatives you've considered
An alternative would be to replace the single Request
argument with a new type of object, which would encapsulate the request and include additional information, e.g. the specification itself. It could also make some of the request's information (like arguments) more easily available through its own attributes and properties.
Additional context
I haven't quite yet decided which of the two options above makes more sense, so would appreciate any comments on the topic.