Unverified Commit 12da47b1 authored by Landon James's avatar Landon James Committed by GitHub
Browse files

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

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->
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
](https://github.com/awslabs/aws-sdk-rust/commit/effdaf98b3eb49e8900838176c18f72db48644ff#diff-101f9ff3d2e67a2122db6bc609ccf4baffc6aee548757139badd8d1c41ab11ab).
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](https://github.com/smithy-lang/smithy-rs/actions/runs/17771171675/job/50511115119#step:4:1340).
The change here fixes that warning by prefixing `_inner` in these cases.

Some other serializer generators also appear to have this bug. Created
https://github.com/smithy-lang/smithy-rs/issues/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
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
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._

---------

Co-authored-by: default avatarysaito1001 <awsaito@amazon.com>
parent b570622e
Loading
Loading
Loading
Loading
+22438 −21537

File changed.

Preview size limit exceeded, changes collapsed.

+13 −3
Original line number Diff line number Diff line
@@ -336,7 +336,8 @@ class XmlBindingTraitSerializerGenerator(
                        HttpLocation.DOCUMENT,
                        TimestampFormatTrait.Format.DATE_TIME, model,
                    )
                val timestampFormatType = RuntimeType.parseTimestampFormat(codegenTarget, runtimeConfig, timestampFormat)
                val timestampFormatType =
                    RuntimeType.parseTimestampFormat(codegenTarget, runtimeConfig, timestampFormat)
                rust("$input.fmt(#T)?.as_ref()", timestampFormatType)
            }

@@ -455,12 +456,21 @@ class XmlBindingTraitSerializerGenerator(
                    rust("let mut scope_writer = writer.finish();")
                    rustBlock("match input") {
                        val members = unionShape.members()

                        members.forEach { member ->
                            val memberShape = model.expectShape(member.target)
                            val memberName = symbolProvider.toMemberName(member)
                            val variantName =
                                if (member.isTargetUnit()) {
                                    "${symbolProvider.toMemberName(member)}"
                                    "$memberName"
                                } else if (memberShape.isStructureShape &&
                                    memberShape.asStructureShape()
                                        .get().allMembers.isEmpty()
                                ) {
                                    // Unit structs don't serialize inner, so it is never accessed
                                    "$memberName(_inner)"
                                } else {
                                    "${symbolProvider.toMemberName(member)}(inner)"
                                    "$memberName(inner)"
                                }
                            withBlock("#T::$variantName =>", ",", unionSymbol) {
                                serializeMember(member, Ctx.Scope("scope_writer", "inner"))
+1 −1
Original line number Diff line number Diff line
@@ -18,4 +18,4 @@ allowLocalDeps=false
isTestingEnabled=true

# codegen publication version
codegenVersion=0.1.0
codegenVersion=0.1.1
+2 −2
Original line number Diff line number Diff line
[package]
name = "aws-smithy-http-server-python"
version = "0.66.2"
version = "0.66.3"
authors = ["Smithy Rust Server <smithy-rs-server@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
@@ -25,7 +25,7 @@ hyper = { version = "0.14.26", features = ["server", "http1", "http2", "tcp", "s
tls-listener = { version = "0.7.0", features = ["rustls", "hyper-h2"] }
rustls-pemfile = "1.0.1"
tokio-rustls = "0.24.0"
lambda_http = { version = "0.8.3" }
lambda_http = { version = "0.8.4" }
num_cpus = "1.13.1"
parking_lot = "0.12.1"
pin-project-lite = "0.2.14"
+2 −2
Original line number Diff line number Diff line
[package]
name = "aws-smithy-http-server"
version = "0.65.5"
version = "0.65.6"
authors = ["Smithy Rust Server <smithy-rs-server@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
@@ -29,7 +29,7 @@ futures-util = { version = "0.3.29", default-features = false }
http = "0.2.9"
http-body = "0.4.5"
hyper = { version = "0.14.26", features = ["server", "http1", "http2", "tcp", "stream"] }
lambda_http = { version = "0.8.3", optional = true }
lambda_http = { version = "0.8.4", optional = true }
mime = "0.3.17"
nom = "7.1.3"
pin-project-lite = "0.2.14"