Skip to content

Update XML serialization for unions to properly handle unit struct members#4306

Merged
aws-sdk-rust-ci merged 6 commits intomainfrom
landonxjames/s3-control-fix
Sep 17, 2025
Merged

Update XML serialization for unions to properly handle unit struct members#4306
aws-sdk-rust-ci merged 6 commits intomainfrom
landonxjames/s3-control-fix

Conversation

@landonxjames
Copy link
Contributor

@landonxjames landonxjames commented Sep 16, 2025

Motivation and Context

Fixing two CI issues that recently popped up. See https://github.com/smithy-lang/smithy-rs/actions/runs/17771171675/job/50511115119#step:4:1340 for a CI run that exhibited both failures.

Codegen Bug

Fixes a bug in XmlBindingTraitSerializerGenerator.kt exposed by a change to the S3-Control model .
The model change introduced a smithy union type that contained a unit struct as a member. This generated a match arm like:

crate::types::ObjectEncryptionFilter::Sses3(inner) =>
{
    scope_writer.start_el("SSE-S3").finish();
}

inner is never used since there is nothing to serialize for a unit struct, so this caused a warning and CI failure. The change here fixes that warning by prefixing _inner in these cases.

Some other serializer generators also appear to have this bug. Created #4308 to track.

Incompatible lambda-http Version Bug

To unblock CI, this PR also bumps lambda_http to 0.8.4 in aws-smithy-http-server.

Testing

Failed CI tasks are now passing


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

"$memberName(_inner)"
} else {
"${symbolProvider.toMemberName(member)}(inner)"
"$memberName(inner)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, is it possible to use _inner unconditionally and update line 476 (new revision)

serializeMember(member, Ctx.Scope("scope_writer", "_inner"))

??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we could, cargo check doesn't complain about it. I assumed it would complain about using a _ prefixed value. But I do think that makes the generated code less idiomatic since it would be making use of _inner. I don't have a strong preference either way if you do

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do use under scored variables across the codegen to handle cases where "this variable may/may not be used" but in a way that doesn't require if else. It'll simplify the codgen code, i.e. can just be back to

val variantName =
    if (member.isTargetUnit()) {
        // ...
    } else {
        "$memberName(_inner)"
    }

While _ is convenient, it hides the fact why the variable is unused in some cases. The code changes in the PR are "honest" about what might happen.

I'm fine with what we have, I was just curious.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@landonxjames landonxjames marked this pull request as ready for review September 17, 2025 19:20
@landonxjames landonxjames requested review from a team as code owners September 17, 2025 19:20
@aws-sdk-rust-ci aws-sdk-rust-ci merged commit 12da47b into main Sep 17, 2025
90 of 92 checks passed
@aws-sdk-rust-ci aws-sdk-rust-ci deleted the landonxjames/s3-control-fix branch September 17, 2025 20:52
vcjana added a commit that referenced this pull request Sep 24, 2025
…nd Query protocols

- Change 'inner' to '_inner' in union variant pattern matching for unit structs
- Prevents unused variable warnings when unit struct members don't use the inner value
- Fixes JsonSerializerGenerator.kt, CborSerializerGenerator.kt, and QuerySerializerGenerator.kt
- Follows same pattern as XML serialization fix in PR #4306
vcjana added a commit that referenced this pull request Oct 10, 2025
## Motivation and Context
Addresses unused variable warnings identified in #4306. While #4306 fixed XmlBindingTraitSerializerGenerator, it noted that QuerySerializerGenerator contained the same bug when handling union variants with empty structs. 

This PR completes the fix for RestXml and AwsQuery protocols. The issue was discovered in S3Control's ObjectEncryptionFilter where builds with -D warnings were failing.

## Description
Modified `QuerySerializerGenerator` to prefix unused variables with
underscore for empty struct variants:

- Added `isEmptyStruct()` to detect empty structures
- Use `_inner` for empty structs, `inner` for non-empty structs
- No changes to JsonSerializerGenerator or CborSerializerGenerator (as these are not affected)

## Testing
Added tests for RestXml, AwsQuery, and RestJson (documents immunity)
Tests enforce `-D warnings` via `clientIntegrationTest`
Verified S3Control compiles cleanly with `RUSTFLAGS="-D warnings"`

<!---## 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.-->
----

_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: ysaito1001 <awsaito@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants