Skip to content

Commit fe34b22

Browse files
committed
Merge branch 'main' of github.com:smithy-lang/smithy-kotlin into kn-main
2 parents 9d9faf3 + 4886087 commit fe34b22

File tree

52 files changed

+366
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+366
-302
lines changed

CHANGELOG.md

Lines changed: 107 additions & 85 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ of your request may disagree and ask that you add one anyway.
8484
"type": "feature",
8585
"description": "Add multiplatform support for URL parsing",
8686
"issues": [
87-
"awslabs/smithy-kotlin#12345"
87+
"smithy-lang/smithy-kotlin#12345"
8888
]
8989
}
9090
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# <img alt="Smithy" src="https://github.com/smithy-lang/smithy/blob/main/docs/_static/favicon.png?raw=true" width="28"> Smithy Kotlin
1+
# <img alt="Smithy" src="https://github.com/smithy-lang/smithy/blob/main/docs/_static/smithy-anvil.svg?raw=true" width="32"> Smithy Kotlin
22

33
[Smithy](https://smithy.io/2.0/index.html) code generators for [Kotlin](https://kotlinlang.org/).
44

bom/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ fun DependencyConstraintHandler.api(constraintNotation: Any) =
6969

7070
createBomConstraintsAndVersionCatalog()
7171

72-
configurePublishing("smithy-kotlin")
73-
72+
configurePublishing("smithy-kotlin", "smithy-lang")
7473
publishing {
7574
publications {
7675
create("bom", MavenPublication::class) {

codegen/smithy-aws-kotlin-codegen/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@ publishing {
107107
}
108108
}
109109

110-
configurePublishing("smithy-kotlin")
110+
configurePublishing("smithy-kotlin", "smithy-lang")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
4646

4747
// restjson1 has some different semantics and expectations around empty structures bound via @httpPayload trait
4848
// * empty structures get serialized to `{}`
49-
// see: https://github.com/awslabs/smithy/pull/924
49+
// see: https://github.com/smithy-lang/smithy/pull/924
5050
val requestBindings = resolver.requestBindings(op)
5151
val httpPayload = requestBindings.firstOrNull { it.location == HttpBinding.Location.PAYLOAD }
5252
if (httpPayload != null) {
@@ -58,7 +58,7 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
5858
write("builder.body = #T.fromBytes(#S.encodeToByteArray())", RuntimeTypes.Http.HttpBody, "{}")
5959
}
6060
// Content-Type still needs to be set for non-structured payloads
61-
// https://github.com/awslabs/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy#L174
61+
// https://github.com/smithy-lang/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy#L174
6262
write("builder.headers.setMissing(\"Content-Type\", #S)", resolver.determineRequestContentType(op))
6363
}
6464
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
139139
writer: KotlinWriter,
140140
resolver: HttpBindingResolver,
141141
) {
142-
writer.write("builder.headers.setMissing(\"Content-Type\", #S)", resolver.determineRequestContentType(op))
142+
val contentTypeHeader = when {
143+
op.isInputEventStream(ctx.model) -> "application/vnd.amazon.eventstream"
144+
else -> "application/cbor"
145+
}
146+
147+
writer.write("builder.headers.setMissing(\"Content-Type\", #S)", contentTypeHeader)
143148
}
144149

145150
class RpcV2CborHttpBindingResolver(
@@ -152,17 +157,13 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
152157
"application/cbor",
153158
TimestampFormatTrait.Format.UNKNOWN,
154159
) {
155-
156160
override fun httpTrait(operationShape: OperationShape): HttpTrait = HttpTrait
157161
.builder()
158162
.code(200)
159163
.method("POST")
160164
.uri(UriPattern.parse("/service/${serviceShape.id.name}/operation/${operationShape.id.name}"))
161165
.build()
162166

163-
override fun determineRequestContentType(operationShape: OperationShape): String = when {
164-
operationShape.isInputEventStream(model) -> "application/vnd.amazon.eventstream"
165-
else -> "application/cbor"
166-
}
167+
override fun determineRequestContentType(operationShape: OperationShape): String = "application/cbor"
167168
}
168169
}

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/eventstream/EventStreamParserGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ val RPC_BOUND_PROTOCOLS = setOf(
2828
"awsJson1_1",
2929
"awsQuery",
3030
"ec2Query",
31+
"rpcv2Cbor",
3132
)
3233

3334
/**

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/xml/RestXmlSerdeDescriptorGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class RestXmlSerdeDescriptorGenerator(
3434
val serialName = getSerialName(member, nameSuffix)
3535
if (serialName.equals("message", ignoreCase = true)) {
3636
// Need to be able to read error messages from "Message" or "message"
37-
// https://github.com/awslabs/smithy-kotlin/issues/352
37+
// https://github.com/smithy-lang/smithy-kotlin/issues/352
3838
traitList.add(RuntimeTypes.Serde.SerdeXml.XmlAliasName, serialName.toggleFirstCharacterCase().dq())
3939
}
4040
}

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RpcV2CborTest {
2020
@service(sdkId: "CborExample")
2121
service CborExample {
2222
version: "1.0.0",
23-
operations: [GetFoo, GetFooStreaming]
23+
operations: [GetFoo, GetFooStreaming, PutFooStreaming]
2424
}
2525
2626
@http(method: "POST", uri: "/foo")
@@ -34,7 +34,29 @@ class RpcV2CborTest {
3434
}
3535
}
3636
37+
@http(method: "POST", uri: "/put-foo-streaming")
38+
operation PutFooStreaming {
39+
input: PutFooStreamingInput
40+
}
41+
42+
structure PutFooStreamingInput {
43+
room: String
44+
messages: PublishEvents
45+
}
46+
3747
// Model taken from https://smithy.io/2.0/spec/streaming.html#event-streams
48+
@streaming
49+
union PublishEvents {
50+
message: Message
51+
leave: LeaveEvent
52+
}
53+
54+
structure Message {
55+
message: String
56+
}
57+
58+
structure LeaveEvent {}
59+
3860
@streaming
3961
union FooEvents {
4062
up: Movement
@@ -98,4 +120,29 @@ class RpcV2CborTest {
98120
""".replaceIndent(" ")
99121
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation)
100122
}
123+
124+
@Test
125+
fun testEventStreamContentTypeHeaders() {
126+
val ctx = model.newTestContext("CborExample")
127+
128+
val generator = RpcV2Cbor()
129+
generator.generateProtocolClient(ctx.generationCtx)
130+
131+
ctx.generationCtx.delegator.finalize()
132+
ctx.generationCtx.delegator.flushWriters()
133+
134+
val serializer = ctx.manifest.expectFileString("/src/main/kotlin/com/test/serde/PutFooStreamingOperationSerializer.kt")
135+
136+
// Event stream messages should have `:content-type: application/cbor`
137+
val encodeMessage = serializer.lines("private fun encodePutFooStreamingPublishEventsEventMessage(input: PublishEvents): Message = buildMessage {", "}")
138+
encodeMessage.shouldContainOnlyOnceWithDiff(
139+
"""
140+
addHeader(":content-type", HeaderValue.String("application/cbor"))
141+
""".trimIndent(),
142+
)
143+
144+
// Event stream requests should have Content-Type=application/vnd.amazon.eventstream
145+
val serializeBody = serializer.lines(" override suspend fun serialize(context: ExecutionContext, input: PutFooStreamingRequest): HttpRequestBuilder {", "}")
146+
serializeBody.shouldContainOnlyOnceWithDiff("""builder.headers.setMissing("Content-Type", "application/vnd.amazon.eventstream")""")
147+
}
101148
}

0 commit comments

Comments
 (0)