mirror of https://github.com/smithy-lang/smithy-rs
a107c0154a
## Motivation and Context Customers want to be able to use `serde` with Smithy models. For details, see the [RFC](https://github.com/smithy-lang/smithy-rs/blob/configurable-serde/design/src/rfcs/rfc0045_configurable_serde.md) ## Description <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> Implementation of `serde::Serialize` for smithy-rs code generators. This takes the approach of a trait, `SerializeConfigured` which _returns_ a type that implements `Serialize`. This allows customers to control serde behavior for their use case. ```rust /// Trait that allows configuring serialization /// **This trait should not be implemented directly!** Instead, `impl Serialize for ConfigurableSerdeRef<T>`** pub trait SerializeConfigured { /// Return a `Serialize` implementation for this object that owns the object. This is what you want /// If you need to pass something that `impl`s serialize elsewhere. fn serialize_owned(self, settings: SerializationSettings) -> impl Serialize; /// Return a `Serialize` implementation for this object that borrows from the given object fn serialize_ref<'a>(&'a self, settings: &'a SerializationSettings) -> impl Serialize + 'a; } ``` This can be used as follows: ```rust serde_json::to_string(&my_struct.serialize_ref(&SerializationSettings::redact_sensitive_fields()); ``` Currently, this codegen plugin is not used by anything. It can be enabled by bringing it in scope during code generation & adding the `@serde` trait to the model for the fields where serialization is desired. This will allow the SDK (if they choose to) roll it out only for specific types or services that have customer demand. There are a number of follow on items required: - [x] Ensure the generated impls work for `Server` codegen - [ ] Generate `Deserialize` implementations - [x] Test the implementation all Smithy protocol test models (ensure it compiles) ## Testing Unit test testing serialization with a kitchen-sink model ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: david-perez <d@vidp.dev> |
||
---|---|---|
.. | ||
python | ||
typescript | ||
.gitignore | ||
README.md | ||
build.gradle.kts |
README.md
Server Codegen Integration Tests
Refer to ../codegen-client-test/README.md
for documentation on how to use this
module. This module is analogous to the codegen-client-test
one, but it's named
codegen-server-test
and it runs the rust-server-codegen
Smithy build
plugin instead.