-
Notifications
You must be signed in to change notification settings - Fork 190
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
Allow third-party devs to write custom plugins for service builders #1736
Conversation
Third-party developers can add custom functions to a service builder, through a `BuilderModifier`. These functionalities are applied to every operation of that service. An example of a builder modifier can be found in rust-runtime/aws-smithy-http-server/examples/pokemon-service/lib.rs Signed-off-by: Harry Barber <[email protected]> Signed-off-by: Daniele Ahmed <[email protected]> Co-authored-by: Harry Barber <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
rust-runtime/aws-smithy-http-server/examples/pokemon-service/tests/helpers.rs
Outdated
Show resolved
Hide resolved
@@ -213,6 +224,17 @@ class ServerServiceGeneratorV2( | |||
} | |||
} | |||
} | |||
|
|||
impl<$builderGenerics, NewPlugin> #{SmithyHttpServer}::plugin::Pluggable<NewPlugin> for $builderName<$builderGenerics> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a ,
here in $builderGenerics, NewPlugin
might cause problems when $builderGenerics
is empty? I'm not entirely sure. It might be worth generating this using .joinToString(", ")
so we don't get a comma when $builderGenerics
is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same below with $builderGenericsNoPlugin, aws_smithy_http_server::plugin::PluginStack<$pluginName, NewPlugin>
.
I'm not sure this is worth changing - there might be a ton of other existing instances where the codegen breaks in the case of no operations.
Maybe we should batch it up into single effort and write a standalone PR to check whether it works nicely in this degenerate case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It breaks the operation registry too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: #1369
...lin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt
Outdated
Show resolved
Hide resolved
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
e31ea59
to
f01a08a
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
Motivation and Context
With the new service and service builder types, it is verbose to add layers to add middleware. Third-party developers can't write an ergonomic middleware to add to services.
Description
With this change, third-parties can write middleware that add a function to service builder,
which smithy service owners can incorporate by calling that function.
Having implemented a trait that adds a custom printing facility to every (any) operation, a third-party owner provides a
.print()
plugin to a service builder:Multiple plugins can be added to provide some functionality:
.print().auth()...
Testing
Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesCHANGELOG.next.toml
if I made changes to the AWS SDK, generated SDK code, or SDK runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.