Skip to content

Commit

Permalink
fix: correctly serialize subset of shape's members when configured (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis authored Jan 6, 2025
1 parent e9d16a9 commit 48849a1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ abstract class AbstractQueryFormUrlSerializerGenerator(
return shape.documentSerializer(ctx.settings, symbol, members) { writer ->
writer.openBlock("internal fun #identifier.name:L(serializer: #T, input: #T) {", RuntimeTypes.Serde.Serializer, symbol)
.call {
renderSerializerBody(ctx, shape, shape.members().toList(), writer)
renderSerializerBody(ctx, shape, members.toList(), writer)
}
.closeBlock("}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package software.amazon.smithy.kotlin.codegen.aws.protocols

import io.kotest.matchers.string.shouldNotContain
import software.amazon.smithy.kotlin.codegen.test.*
import kotlin.test.Test

Expand Down Expand Up @@ -145,4 +146,20 @@ class RpcV2CborTest {
val serializeBody = serializer.lines(" override suspend fun serialize(context: ExecutionContext, input: PutFooStreamingRequest): HttpRequestBuilder {", "}")
serializeBody.shouldContainOnlyOnceWithDiff("""builder.headers.setMissing("Content-Type", "application/vnd.amazon.eventstream")""")
}

@Test
fun testEventStreamInitialRequestDoesNotSerializeStreamMember() {
val ctx = model.newTestContext("CborExample")

val generator = RpcV2Cbor()
generator.generateProtocolClient(ctx.generationCtx)

ctx.generationCtx.delegator.finalize()
ctx.generationCtx.delegator.flushWriters()

val documentSerializer = ctx.manifest.expectFileString("/src/main/kotlin/com/test/serde/PutFooStreamingRequestDocumentSerializer.kt")

val serializeBody = documentSerializer.lines(" serializer.serializeStruct(OBJ_DESCRIPTOR) {", "}")
serializeBody.shouldNotContain("input.messages") // `messages` is the stream member and should not be serialized in the initial request
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CborSerializerGenerator(
val symbol = ctx.symbolProvider.toSymbol(shape)
return shape.documentSerializer(ctx.settings, symbol, members) { writer ->
writer.withBlock("internal fun #identifier.name:L(serializer: #T, input: #T) {", "}", RuntimeTypes.Serde.Serializer, symbol) {
call { renderSerializerBody(ctx, shape, shape.members().toList(), writer) }
call { renderSerializerBody(ctx, shape, members.toList(), writer) }
}
}
}
Expand Down

0 comments on commit 48849a1

Please sign in to comment.