Skip to content

Commit 48849a1

Browse files
authored
fix: correctly serialize subset of shape's members when configured (#1199)
1 parent e9d16a9 commit 48849a1

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ abstract class AbstractQueryFormUrlSerializerGenerator(
145145
return shape.documentSerializer(ctx.settings, symbol, members) { writer ->
146146
writer.openBlock("internal fun #identifier.name:L(serializer: #T, input: #T) {", RuntimeTypes.Serde.Serializer, symbol)
147147
.call {
148-
renderSerializerBody(ctx, shape, shape.members().toList(), writer)
148+
renderSerializerBody(ctx, shape, members.toList(), writer)
149149
}
150150
.closeBlock("}")
151151
}

codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RpcV2CborTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package software.amazon.smithy.kotlin.codegen.aws.protocols
66

7+
import io.kotest.matchers.string.shouldNotContain
78
import software.amazon.smithy.kotlin.codegen.test.*
89
import kotlin.test.Test
910

@@ -145,4 +146,20 @@ class RpcV2CborTest {
145146
val serializeBody = serializer.lines(" override suspend fun serialize(context: ExecutionContext, input: PutFooStreamingRequest): HttpRequestBuilder {", "}")
146147
serializeBody.shouldContainOnlyOnceWithDiff("""builder.headers.setMissing("Content-Type", "application/vnd.amazon.eventstream")""")
147148
}
149+
150+
@Test
151+
fun testEventStreamInitialRequestDoesNotSerializeStreamMember() {
152+
val ctx = model.newTestContext("CborExample")
153+
154+
val generator = RpcV2Cbor()
155+
generator.generateProtocolClient(ctx.generationCtx)
156+
157+
ctx.generationCtx.delegator.finalize()
158+
ctx.generationCtx.delegator.flushWriters()
159+
160+
val documentSerializer = ctx.manifest.expectFileString("/src/main/kotlin/com/test/serde/PutFooStreamingRequestDocumentSerializer.kt")
161+
162+
val serializeBody = documentSerializer.lines(" serializer.serializeStruct(OBJ_DESCRIPTOR) {", "}")
163+
serializeBody.shouldNotContain("input.messages") // `messages` is the stream member and should not be serialized in the initial request
164+
}
148165
}

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/serde/CborSerializerGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class CborSerializerGenerator(
108108
val symbol = ctx.symbolProvider.toSymbol(shape)
109109
return shape.documentSerializer(ctx.settings, symbol, members) { writer ->
110110
writer.withBlock("internal fun #identifier.name:L(serializer: #T, input: #T) {", "}", RuntimeTypes.Serde.Serializer, symbol) {
111-
call { renderSerializerBody(ctx, shape, shape.members().toList(), writer) }
111+
call { renderSerializerBody(ctx, shape, members.toList(), writer) }
112112
}
113113
}
114114
}

0 commit comments

Comments
 (0)