You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extending the code generator is non-trivial and undocumented.
This issue attempts to outline a standard approach for third parties to extend the code generator. This outline should be fleshed out in a extension.mdserver section of the book.
Consider the common scenario:
I, as a third-party, am interested in implementing code generation for a trait which is not supported via vanilla smithy-rs. The trait adds some additional semantics the shapes defined in the model.
Define a Rust trait, in a third party crate, which acts as an interface to the Smithy traits desired effects. For example, if we had a @log trait which identified a field which should be logged per request then the interface might look like
traitLog{fnlog(&self,writer:&mutdynWrite);}
Extend the code generator to implement the Log trait when @log is present. This should be an addition to the server SDK and be easy for us to provide the extension points. Each Smithy shape has an associated Rust struct so we have a consistent surface to do this over.
In the third party crate, define a Plugin which assumes the existence of these traits.
Extend the service config to apply the LogPlugin, adding methods to configure it when needed.
Each of these steps is designed to be non-invasive and robust to internal changes. This approach attempts to minimize the amount of Kotlin required, relying on the more stable Rust interfaces. The third party will maintain one Rust crate, containing the semantics and business logic, and one Kotlin package which extracts information from the Smithy model and presents it via the trait Log implementation.
The text was updated successfully, but these errors were encountered:
Extending the code generator is non-trivial and undocumented.
This issue attempts to outline a standard approach for third parties to extend the code generator. This outline should be fleshed out in a
extension.md
server section of the book.Consider the common scenario:
trait
, in a third party crate, which acts as an interface to the Smithy traits desired effects. For example, if we had a@log
trait which identified a field which should be logged per request then the interface might look likeLog
trait when@log
is present. This should be an addition to the server SDK and be easy for us to provide the extension points. Each Smithy shape has an associated Rust struct so we have a consistent surface to do this over.Plugin
which assumes the existence of these traits.LogPlugin
, adding methods to configure it when needed.Each of these steps is designed to be non-invasive and robust to internal changes. This approach attempts to minimize the amount of Kotlin required, relying on the more stable Rust interfaces. The third party will maintain one Rust crate, containing the semantics and business logic, and one Kotlin package which extracts information from the Smithy model and presents it via the
trait Log
implementation.The text was updated successfully, but these errors were encountered: