Skip to content

Commit 21aff4e

Browse files
authored
feat: support initial-request and initial-response event stream types for RPC-bound protocols (#929)
1 parent ce0dcde commit 21aff4e

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ object RuntimeTypes {
344344
object Flow {
345345
// NOTE: smithy-kotlin core has an API dependency on this already
346346
val Flow = "kotlinx.coroutines.flow.Flow".toSymbol()
347+
val flowOf = "kotlinx.coroutines.flow.flowOf".toSymbol()
348+
val merge = "kotlinx.coroutines.flow.merge".toSymbol()
347349
val map = "kotlinx.coroutines.flow.map".toSymbol()
350+
val take = "kotlinx.coroutines.flow.take".toSymbol()
351+
val drop = "kotlinx.coroutines.flow.drop".toSymbol()
352+
val single = "kotlinx.coroutines.flow.single".toSymbol()
348353
}
349354
}
350355

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/model/knowledge/SerdeIndex.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import software.amazon.smithy.model.Model
99
import software.amazon.smithy.model.knowledge.KnowledgeIndex
1010
import software.amazon.smithy.model.neighbor.RelationshipType
1111
import software.amazon.smithy.model.neighbor.Walker
12-
import software.amazon.smithy.model.shapes.CollectionShape
13-
import software.amazon.smithy.model.shapes.OperationShape
14-
import software.amazon.smithy.model.shapes.Shape
15-
import software.amazon.smithy.model.shapes.ShapeType
12+
import software.amazon.smithy.model.shapes.*
1613

1714
/**
1815
* Knowledge index that provides access to shapes requiring serialize and deserialize implementations.
@@ -51,11 +48,11 @@ class SerdeIndex(private val model: Model) : KnowledgeIndex {
5148
* Find and return the set of shapes reachable from the given shape that would require a "document" serializer.
5249
* @return The set of shapes that require a serializer implementation
5350
*/
54-
fun requiresDocumentSerializer(shape: Shape): Set<Shape> =
51+
fun requiresDocumentSerializer(shape: Shape, members: Collection<MemberShape> = shape.members()): Set<Shape> =
5552
when (shape) {
5653
is OperationShape -> requiresDocumentSerializer(listOf(shape))
5754
else -> {
58-
val topLevelMembers = shape.members()
55+
val topLevelMembers = members
5956
.map { model.expectShape(it.target) }
6057
.filter { it.isStructureShape || it.isUnionShape || it is CollectionShape || it.isMapShape }
6158
.toSet()
@@ -104,11 +101,11 @@ class SerdeIndex(private val model: Model) : KnowledgeIndex {
104101
* Find and return the set of shapes reachable from the given shape that would require a "document" deserializer.
105102
* @return The set of shapes that require a deserializer implementation
106103
*/
107-
fun requiresDocumentDeserializer(shape: Shape): Set<Shape> =
104+
fun requiresDocumentDeserializer(shape: Shape, members: Collection<MemberShape> = shape.members()): Set<Shape> =
108105
when (shape) {
109106
is OperationShape -> requiresDocumentDeserializer(listOf(shape))
110107
else -> {
111-
val topLevelMembers = shape.members()
108+
val topLevelMembers = members
112109
.map { model.expectShape(it.target) }
113110
.filter { it.isStructureShape || it.isUnionShape || it is CollectionShape || it.isMapShape }
114111
.toMutableSet()

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ open class JsonParserGenerator(
4040
/**
4141
* Register nested structure/map shapes reachable from the operation input shape that require a "document" deserializer
4242
* implementation
43+
* @param ctx the generation context
44+
* @param shape the shape to generated nested document deserializers for
45+
* @param writer the writer to write with
46+
* @param members the subset of shapes to generated nested document deserializers for
4347
*/
44-
private fun addNestedDocumentDeserializers(ctx: ProtocolGenerator.GenerationContext, shape: Shape, writer: KotlinWriter) {
48+
private fun addNestedDocumentDeserializers(ctx: ProtocolGenerator.GenerationContext, shape: Shape, writer: KotlinWriter, members: Collection<MemberShape> = shape.members()) {
4549
val serdeIndex = SerdeIndex.of(ctx.model)
46-
val shapesRequiringDocumentDeserializer = serdeIndex.requiresDocumentDeserializer(shape)
50+
val shapesRequiringDocumentDeserializer = serdeIndex.requiresDocumentDeserializer(shape, members)
4751

4852
// register a dependency on each of the members that require a deserializer impl
4953
// ensuring they get generated
@@ -141,7 +145,7 @@ open class JsonParserGenerator(
141145
val forMembers = members ?: target.members()
142146
val deserializeFn = documentDeserializer(ctx, target, forMembers)
143147
return target.payloadDeserializer(ctx.settings, symbol, forMembers) { writer ->
144-
addNestedDocumentDeserializers(ctx, target, writer)
148+
addNestedDocumentDeserializers(ctx, target, writer, forMembers)
145149
writer.withBlock("internal fun #identifier.name:L(payload: ByteArray): #T {", "}", symbol) {
146150
if (target.members().isEmpty() && !target.isDocumentShape) {
147151
// short circuit when the shape has no modeled members to deserialize

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ open class JsonSerializerGenerator(
4444
* Register nested structure/map shapes reachable from the operation input shape that require a "document" serializer
4545
* implementation
4646
*/
47-
private fun addNestedDocumentSerializers(ctx: ProtocolGenerator.GenerationContext, shape: Shape, writer: KotlinWriter) {
47+
private fun addNestedDocumentSerializers(ctx: ProtocolGenerator.GenerationContext, shape: Shape, writer: KotlinWriter, members: Collection<MemberShape> = shape.members()) {
4848
val serdeIndex = SerdeIndex.of(ctx.model)
49-
val shapesRequiringDocumentSerializer = serdeIndex.requiresDocumentSerializer(shape)
49+
val shapesRequiringDocumentSerializer = serdeIndex.requiresDocumentSerializer(shape, members)
5050
// register a dependency on each of the members that require a serializer impl
5151
// ensuring they get generated
5252
shapesRequiringDocumentSerializer.forEach {
@@ -109,7 +109,7 @@ open class JsonSerializerGenerator(
109109

110110
val serializeFn = documentSerializer(ctx, target, forMembers)
111111
return target.payloadSerializer(ctx.settings, symbol, forMembers) { writer ->
112-
addNestedDocumentSerializers(ctx, target, writer)
112+
addNestedDocumentSerializers(ctx, target, writer, forMembers)
113113
writer.addImportReferences(symbol, SymbolReference.ContextOption.USE)
114114
writer.withBlock("internal fun #identifier.name:L(input: #T): ByteArray {", "}", symbol) {
115115
write("val serializer = #T()", RuntimeTypes.Serde.SerdeJson.JsonSerializer)

0 commit comments

Comments
 (0)