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

Support Operation class decorators #106

Open
dnephin opened this issue Feb 27, 2015 · 0 comments
Open

Support Operation class decorators #106

dnephin opened this issue Feb 27, 2015 · 0 comments

Comments

@dnephin
Copy link
Contributor

dnephin commented Feb 27, 2015

There are many use-cases for decorating a client to provide additional functionality. Some common ones that have come up before are:

  • wrapping exceptions, either to cast them to another type, log them, or catch them and prevent them from raising
  • providing defaults for _request_options (especially headers) to every service call. This is useful for things like tracking ids, authentication headers, force-master-read, etc.
  • retry and timeout behaviour. Within a single application it's likely that these will remain pretty consistent, so providing a decorator allows you to re-use the values for all calls

Since our service calls aren't exposed directly from the SwaggerClient there is a bit more work involved to create a decorator (the SwaggerClient only exposes resources, the resources expose operation calls, which are what we want to decorate).

I think we should provide some support for this in bravado (potentially swagger-py as well, they should be reusable for both since the external interface is basically identical).

I think there are two potential options.

  • provide a ClientDecorator that knows how to decorate both the resources and operations. This option is less coupled with swagger-py itself, but requires more code.
  • have SwaggerClient accept a list of IOperationDecorator objects which conform to some interface and apply the decorators directly to the operation. More tightly coupled with swagger-py, but easier to implement.

I prefer the second option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants