[server] Construct endpoint function signatures based on operation spec #8
Labels
enhancement
New feature or request
help wanted
Extra attention is needed
question
Further information is requested
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 (specificallystarlette
).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 handlesGET /foo/{bar_id}
, with thebar_id
defined (in theparameters
property) as being oftype: integer
, the expected endpoint function would have the signature: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 theOpenAPI
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.
The text was updated successfully, but these errors were encountered: