Skip to content
Unverified Commit 84f5464a authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Avoid treating `addedDefault` as `default` when serializing numbers and bools (#4117)

## Description
This PR fixes a regression in input serializers. Previously, fields of
numbers/bool annotated with the `required` trait were always serialized.
With the introduction of the
[addedDefault](https://smithy.io/2.0/spec/type-refinement-traits.html#addeddefault-trait)
trait, they stopped being serialized when an input values match the
default even if explicitly set by the user.

An example is `LoggingConfig` in CloudFront
([change](https://github.com/awslabs/aws-sdk-rust/commit/3465444a0f6b66816febdeb6441110ec283c1317#diff-8ff83311bcd0649ac0bee175e8a1f3d1fce9c8863c64b896c58f41ac17051bf0R8)).
The previously required fields `enabled` and `include_cookies` were
annotated with the `addedDefault` trait and the `LoggingConfig`'s
serializer made serialization of those fields conditional:
```
pub fn ser_logging_config(...) -> ... {
    #[allow(unused_mut)]
    let mut scope = writer.finish();
    if input.enabled {
        let mut inner_writer = scope.start_el("Enabled").finish();
        inner_writer.data(::aws_smithy_types::primitive::Encoder::from(input.enabled).encode());
    }
    if input.include_cookies {
        let mut inner_writer = scope.start_el("IncludeCookies").finish();
        inner_writer.data(::aws_smithy_types::primitive::Encoder::from(input.include_cookies).encode());
    }
   ...
``` 
When their values were `false`, they did not get serialized, regardless
of whether they were explicitly set; when they were `required` fields
previously, they had always been serialized.

This has caused CloudFront SDK users to encounter an error response from
the service, e.g,
```
You must specify IncludeCookies when Enabled is missing or set to true within a Logging object
``` 

This PR treats the `addedDefault` trait as non `default`, making the
fields always be serialized.

## Testing
- CI and release pipeline
- Confirmed that `LoggingConfig`'s serializer always serializes the
fields in question

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] For changes to the smithy-rs codegen or runtime crates, I have
created a changelog entry Markdown file in the `.changelog` directory,
specifying "client," "server," or both in the `applies_to` key.
- [x] For changes to the AWS SDK, generated SDK code, or SDK runtime
crates, I have created a changelog entry Markdown file in the
`.changelog` directory, specifying "aws-sdk-rust" in the `applies_to`
key.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 9db6b04a
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment