smithy-rs/codegen-server-test
Russell Cohen a107c0154a
Add initial implementation of a Serde Decorator (#3753)
## 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>
2024-08-12 16:44:32 +00:00
..
python Upgrade Smithy to 1.50.0 (#3728) 2024-07-05 14:58:17 +00:00
typescript Add initial implementation of a Serde Decorator (#3753) 2024-08-12 16:44:32 +00:00
.gitignore [POC] Basic server type serde for RestJson1 (#737) 2021-10-05 13:05:00 -04:00
README.md Establish the `codegen-core` module (#1697) 2022-09-07 09:31:46 -07:00
build.gradle.kts Add server RPC v2 CBOR support (#2544) 2024-07-17 09:50:52 +00:00

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.