Update XML serialization for unions to properly handle unit struct members#4306
Update XML serialization for unions to properly handle unit struct members#4306aws-sdk-rust-ci merged 6 commits intomainfrom
Conversation
| "$memberName(_inner)" | ||
| } else { | ||
| "${symbolProvider.toMemberName(member)}(inner)" | ||
| "$memberName(inner)" |
There was a problem hiding this comment.
Curious, is it possible to use _inner unconditionally and update line 476 (new revision)
serializeMember(member, Ctx.Scope("scope_writer", "_inner"))
??
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
A new generated diff is ready to view.
A new doc preview is ready to view. |
…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
## 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>
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.ktexposed 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:
inneris 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_innerin 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_httpto 0.8.4 inaws-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.