Skip to content

Commit b6efb80

Browse files
committed
Merge branch 'main' of github.com:smithy-lang/smithy-kotlin into jmespath-flatten
2 parents 6952cb0 + f0df363 commit b6efb80

File tree

44 files changed

+615
-83
lines changed

Some content is hidden

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

44 files changed

+615
-83
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Kat Transform
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, reopened, labeled, unlabeled ]
6+
branches: [ main ]
7+
8+
# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
9+
concurrency:
10+
group: kat-pr-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
id-token: write
15+
contents: read
16+
17+
env:
18+
RUN: ${{ github.run_id }}-${{ github.run_number }}
19+
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dkotlin.incremental=false"
20+
21+
jobs:
22+
verify-transform:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout sources
26+
uses: actions/checkout@v4
27+
with:
28+
path: 'smithy-kotlin'
29+
30+
- name: Configure AWS Credentials
31+
uses: aws-actions/configure-aws-credentials@v4
32+
with:
33+
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
34+
aws-region: us-west-2
35+
36+
- name: Setup kat
37+
uses: awslabs/aws-kotlin-repo-tools/.github/actions/setup-kat@main
38+
39+
- name: Configure JDK
40+
uses: actions/setup-java@v3
41+
with:
42+
distribution: 'corretto'
43+
java-version: 17
44+
cache: 'gradle'
45+
46+
- name: Build
47+
working-directory: ./smithy-kotlin
48+
shell: bash
49+
run: |
50+
pwd
51+
ls -lsa
52+
kat bump-version # Bump from `vNext-SNAPSHOT` to `vNext`. kat transform only works on non-SNAPSHOT versions
53+
kat bump-version --property codegenVersion
54+
./gradlew build
55+
./gradlew publishAllPublicationsToTestLocalRepository
56+
57+
- name: Transform
58+
working-directory: ./smithy-kotlin
59+
shell: bash
60+
run: |
61+
pwd
62+
ls -lsa
63+
kat brazil transform -i ./build/m2 -o ./transformed -t .brazil.json -v live
64+
65+
# Check for manifest file
66+
if [ ! -f "./transformed/brazil-import-manifest.json" ]; then
67+
echo "Error: brazil-import-manifest.json not found in the transformed artifact"
68+
exit 1
69+
fi
70+
71+
echo "Transformation succeeded!"

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
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+
14+
## [1.3.17] - 10/16/2024
15+
16+
### Miscellaneous
17+
* Upgrade to Kotlin 2.0.21
18+
319
## [1.3.16] - 10/10/2024
420

521
## [1.3.15] - 10/08/2024

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/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ group = "software.amazon.smithy.kotlin"
2121
version = codegenVersion
2222

2323
dependencies {
24-
implementation(kotlin("stdlib-jdk8"))
2524
implementation(libs.smithy.aws.traits)
2625
implementation(libs.smithy.protocol.traits)
2726
api(project(":codegen:smithy-kotlin-codegen"))

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/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ val sdkVersion: String by project
2424
val runtimeVersion = sdkVersion
2525

2626
dependencies {
27-
implementation(kotlin("stdlib-jdk8"))
2827
api(libs.smithy.codegen.core)
2928
api(libs.smithy.waiters)
3029
implementation(libs.smithy.rules.engine)

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.17-SNAPSHOT
16+
sdkVersion=1.3.20-SNAPSHOT
1717

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

0 commit comments

Comments
 (0)