diff --git a/codegen-client-test/model/rest-xml-extras.smithy b/codegen-client-test/model/rest-xml-extras.smithy index 9c520676ed..76a6bbd9fa 100644 --- a/codegen-client-test/model/rest-xml-extras.smithy +++ b/codegen-client-test/model/rest-xml-extras.smithy @@ -20,6 +20,7 @@ service RestXmlExtras { ChecksumRequired, StringHeader, CreateFoo, + RequiredMember, ] } @@ -242,5 +243,17 @@ structure StringHeaderOutput { field: String, @httpHeader("x-enum") - enumHeader: StringEnum + enumHeader: StringEnum, +} + +/// This operation tests that we can serialize `required` members. +@http(uri: "/required-member", method: "GET") +operation RequiredMember { + input: RequiredMemberInputOutput + output: RequiredMemberInputOutput +} + +structure RequiredMemberInputOutput { + @required + requiredString: String } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt index 4d7a2ce3e5..6ab3aea1e3 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt @@ -5,6 +5,8 @@ package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize +import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref + sealed class ValueExpression { abstract val name: String @@ -12,7 +14,7 @@ sealed class ValueExpression { data class Value(override val name: String) : ValueExpression() fun asValue(): String = when (this) { - is Reference -> "*$name" + is Reference -> autoDeref(name) is Value -> name } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index 8f83d8fe6a..285f362f36 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -19,7 +19,6 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlFlattenedTrait import software.amazon.smithy.model.traits.XmlNamespaceTrait @@ -285,11 +284,9 @@ class XmlBindingTraitSerializerGenerator( } private fun RustWriter.serializeRawMember(member: MemberShape, input: String) { - when (val shape = model.expectShape(member.target)) { - is StringShape -> if (shape.hasTrait()) { + when (model.expectShape(member.target)) { + is StringShape -> { rust("$input.as_str()") - } else { - rust("$input.as_ref()") } is BooleanShape, is NumberShape -> { rust( @@ -444,7 +441,7 @@ class XmlBindingTraitSerializerGenerator( * ``` * * If [member] is not an optional shape, generate code like: - * `{ .. Block }` + * `{ .. BLOCK }` * * [inner] is passed a new `ctx` object to use for code generation which handles the * potentially new name of the input. @@ -462,7 +459,12 @@ class XmlBindingTraitSerializerGenerator( } } else { with(util) { - ignoreZeroValues(member, ValueExpression.Value(autoDeref(ctx.input))) { + val valueExpression = if (ctx.input.startsWith("&")) { + ValueExpression.Reference(ctx.input) + } else { + ValueExpression.Value(ctx.input) + } + ignoreZeroValues(member, valueExpression) { inner(ctx) } }