Skip to content

Commit 1e09b66

Browse files
committed
Merge branch 'main' of github.com:smithy-lang/smithy-kotlin into kn-refactor-plugin
2 parents cbdfb3f + f0df363 commit 1e09b66

File tree

27 files changed

+496
-29
lines changed

27 files changed

+496
-29
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## [1.3.19] - 11/05/2024
4+
5+
## [1.3.18] - 10/31/2024
6+
7+
### Fixes
8+
* [#1214](https://github.com/awslabs/aws-sdk-kotlin/issues/1214) Add support for connection idle monitoring for OkHttp via the engine config parameter `connectionIdlePollingInterval`. Monitoring is disabled by default to match previous behavior. This monitoring will switch to enabled by default in an upcoming minor version release.
9+
10+
### Miscellaneous
11+
* Add `Accept` header to all RpcV2Cbor requests
12+
* Correct documentation for `ByteStream.writeToOutputStream`, add `ByteStream.appendToOutputStream`
13+
314
## [1.3.17] - 10/16/2024
415

516
### Miscellaneous

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait
2626
import software.amazon.smithy.model.traits.UnitTypeTrait
2727
import software.amazon.smithy.protocol.traits.Rpcv2CborTrait
2828

29+
private const val ACCEPT_HEADER = "application/cbor"
30+
private const val ACCEPT_HEADER_EVENT_STREAM = "application/vnd.amazon.eventstream"
31+
2932
class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
3033
override val protocol: ShapeId = Rpcv2CborTrait.ID
3134

@@ -59,13 +62,16 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
5962
}
6063
}
6164

62-
// Requests with event stream responses MUST include an `Accept` header set to the value `application/vnd.amazon.eventstream`
63-
val eventStreamsAcceptHeaderMiddleware = object : ProtocolMiddleware {
64-
private val mutateHeadersMiddleware = MutateHeadersMiddleware(extraHeaders = mapOf("Accept" to "application/vnd.amazon.eventstream"))
65-
66-
override fun isEnabledFor(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Boolean = op.isOutputEventStream(ctx.model)
67-
override val name: String = "RpcV2CborEventStreamsAcceptHeaderMiddleware"
68-
override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) = mutateHeadersMiddleware.render(ctx, op, writer)
65+
// Add `Accept` header with value `application/cbor` for standard responses
66+
// and `application/vnd.amazon.eventstream` for event stream responses
67+
val acceptHeaderMiddleware = object : ProtocolMiddleware {
68+
override val name: String = "RpcV2CborAcceptHeaderMiddleware"
69+
override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
70+
val acceptHeaderValue = if (op.isOutputEventStream(ctx.model)) ACCEPT_HEADER_EVENT_STREAM else ACCEPT_HEADER
71+
MutateHeadersMiddleware(
72+
extraHeaders = mapOf("Accept" to acceptHeaderValue),
73+
).render(ctx, op, writer)
74+
}
6975
}
7076

7177
// Emit a metric to track usage of RpcV2Cbor
@@ -79,7 +85,7 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
7985
return super.getDefaultHttpMiddleware(ctx) + listOf(
8086
smithyProtocolHeaderMiddleware,
8187
validateSmithyProtocolHeaderMiddleware,
82-
eventStreamsAcceptHeaderMiddleware,
88+
acceptHeaderMiddleware,
8389
businessMetricsMiddleware,
8490
)
8591
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package software.amazon.smithy.kotlin.codegen.aws.protocols
6+
7+
import software.amazon.smithy.kotlin.codegen.test.*
8+
import kotlin.test.Test
9+
10+
class RpcV2CborTest {
11+
val model = """
12+
${"$"}version: "2"
13+
14+
namespace com.test
15+
16+
use smithy.protocols#rpcv2Cbor
17+
use aws.api#service
18+
19+
@rpcv2Cbor
20+
@service(sdkId: "CborExample")
21+
service CborExample {
22+
version: "1.0.0",
23+
operations: [GetFoo, GetFooStreaming]
24+
}
25+
26+
@http(method: "POST", uri: "/foo")
27+
operation GetFoo {}
28+
29+
@http(method: "POST", uri: "/foo-streaming")
30+
operation GetFooStreaming {
31+
input := {}
32+
output := {
33+
events: FooEvents
34+
}
35+
}
36+
37+
// Model taken from https://smithy.io/2.0/spec/streaming.html#event-streams
38+
@streaming
39+
union FooEvents {
40+
up: Movement
41+
down: Movement
42+
left: Movement
43+
right: Movement
44+
throttlingError: ThrottlingError
45+
}
46+
47+
structure Movement {
48+
velocity: Float
49+
}
50+
51+
@error("client")
52+
@retryable(throttling: true)
53+
structure ThrottlingError {}
54+
""".toSmithyModel()
55+
56+
@Test
57+
fun testStandardAcceptHeader() {
58+
val ctx = model.newTestContext("CborExample")
59+
60+
val generator = RpcV2Cbor()
61+
generator.generateProtocolClient(ctx.generationCtx)
62+
63+
ctx.generationCtx.delegator.finalize()
64+
ctx.generationCtx.delegator.flushWriters()
65+
66+
val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt")
67+
val getFooMethod = actual.lines(" override suspend fun getFoo(input: GetFooRequest): GetFooResponse {", " }")
68+
69+
val expectedHeaderMutation = """
70+
op.install(
71+
MutateHeaders().apply {
72+
append("Accept", "application/cbor")
73+
}
74+
)
75+
""".replaceIndent(" ")
76+
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation)
77+
}
78+
79+
@Test
80+
fun testEventStreamAcceptHeader() {
81+
val ctx = model.newTestContext("CborExample")
82+
83+
val generator = RpcV2Cbor()
84+
generator.generateProtocolClient(ctx.generationCtx)
85+
86+
ctx.generationCtx.delegator.finalize()
87+
ctx.generationCtx.delegator.flushWriters()
88+
89+
val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt")
90+
val getFooMethod = actual.lines(" override suspend fun <T> getFooStreaming(input: GetFooStreamingRequest, block: suspend (GetFooStreamingResponse) -> T): T {", " }")
91+
92+
val expectedHeaderMutation = """
93+
op.install(
94+
MutateHeaders().apply {
95+
append("Accept", "application/vnd.amazon.eventstream")
96+
}
97+
)
98+
""".replaceIndent(" ")
99+
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation)
100+
}
101+
}

codegen/smithy-kotlin-codegen-testutils/src/main/kotlin/software/amazon/smithy/kotlin/codegen/test/CodegenTestUtils.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait
2828
import software.amazon.smithy.model.traits.Trait
2929
import software.amazon.smithy.protocol.traits.Rpcv2CborTrait
3030
import software.amazon.smithy.utils.StringUtils
31+
import kotlin.test.assertNotEquals
3132

3233
// This file houses test classes and functions relating to the code generator (protocols, serializers, etc)
3334
// Items contained here should be relatively high-level, utilizing all members of codegen classes, Smithy, and
@@ -274,3 +275,19 @@ fun KotlinCodegenPlugin.Companion.createSymbolProvider(
274275
* create a new [KotlinWriter] using the test context package name
275276
*/
276277
fun TestContext.newWriter(): KotlinWriter = KotlinWriter(generationCtx.settings.pkg.name)
278+
279+
/**
280+
* Get all the lines between [fromLine] and [toLine]
281+
*/
282+
fun String.lines(fromLine: String, toLine: String): String {
283+
val allLines = lines()
284+
285+
val fromIdx = allLines.indexOf(fromLine)
286+
assertNotEquals(-1, fromIdx, """Could not find from line "$fromLine" in all lines""")
287+
288+
val toIdxOffset = allLines.drop(fromIdx + 1).indexOf(toLine)
289+
assertNotEquals(-1, toIdxOffset, """Could not find to line "$toLine" in all lines""")
290+
291+
val toIdx = toIdxOffset + fromIdx + 1
292+
return allLines.subList(fromIdx, toIdx + 1).joinToString("\n")
293+
}

codegen/smithy-kotlin-codegen/src/test/resources/sdk-ids-test-output.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ Neptune,Neptune
236236
neptunedata,Neptunedata
237237
Network Firewall,NetworkFirewall
238238
NetworkManager,NetworkManager
239-
nimble,Nimble
240239
OAM,Oam
241240
Omics,Omics
242241
OpenSearch,OpenSearch

codegen/smithy-kotlin-codegen/src/test/resources/sdk-ids.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ Neptune
236236
neptunedata
237237
Network Firewall
238238
NetworkManager
239-
nimble
240239
OAM
241240
Omics
242241
OpenSearch

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ kotlinx.atomicfu.enableNativeIrTransformation=false
1313
org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=1G
1414

1515
# SDK
16-
sdkVersion=1.3.18-SNAPSHOT
16+
sdkVersion=1.3.20-SNAPSHOT
1717

1818
# codegen
19-
codegenVersion=0.33.18-SNAPSHOT
19+
codegenVersion=0.33.20-SNAPSHOT

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ktor-http-cio = { module = "io.ktor:ktor-http-cio", version.ref = "ktor-version"
9292
ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor-version" }
9393
ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor-version" }
9494
ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor-version" }
95-
ktor-server-jetty = { module = "io.ktor:ktor-server-jetty", version.ref = "ktor-version" }
95+
ktor-server-jetty-jakarta = { module = "io.ktor:ktor-server-jetty-jakarta", version.ref = "ktor-version" }
9696
ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor-version" }
9797
ktor-network-tls-certificates = { module = "io.ktor:ktor-network-tls-certificates", version.ref = "ktor-version" }
9898

runtime/auth/aws-credentials/api/aws-credentials.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ public final class aws/smithy/kotlin/runtime/auth/awscredentials/CachedCredentia
33
public synthetic fun <init> (Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;JJLaws/smithy/kotlin/runtime/time/Clock;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
44
public fun close ()V
55
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
6+
public fun toString ()Ljava/lang/String;
67
}
78

89
public final class aws/smithy/kotlin/runtime/auth/awscredentials/CachedCredentialsProviderKt {
@@ -45,6 +46,7 @@ public final class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProv
4546
public fun <init> (Ljava/util/List;)V
4647
public fun <init> ([Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;)V
4748
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
49+
public fun toString ()Ljava/lang/String;
4850
}
4951

5052
public abstract interface class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProviderConfig {
@@ -61,6 +63,10 @@ public final class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProv
6163
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
6264
}
6365

66+
public final class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProviderKt {
67+
public static final fun getSimpleClassName (Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;)Ljava/lang/String;
68+
}
69+
6470
public abstract interface class aws/smithy/kotlin/runtime/auth/awscredentials/SigV4aClientConfig {
6571
public abstract fun getSigV4aSigningRegionSet ()Ljava/util/Set;
6672
}

runtime/auth/aws-credentials/common/src/aws/smithy/kotlin/runtime/auth/awscredentials/CachedCredentialsProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public class CachedCredentialsProvider(
7373
cachedCredentials.close()
7474
source.closeIfCloseable()
7575
}
76+
77+
override fun toString(): String = this.simpleClassName + ": " + this.source.simpleClassName
7678
}
7779

7880
/**

0 commit comments

Comments
 (0)