Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Construct endpoint function signatures based on operation spec #8

Open
berislavlopac opened this issue Nov 29, 2019 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@berislavlopac
Copy link
Owner

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 OpenAPIschemas 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.

@berislavlopac berislavlopac added enhancement New feature or request help wanted Extra attention is needed question Further information is requested labels Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant