Skip to content

Commit c0cd07a

Browse files
author
luigi
committed
fix
1 parent 1052703 commit c0cd07a

File tree

11 files changed

+55
-64
lines changed

11 files changed

+55
-64
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ dependencies {
3434

3535
tasks.withType<KotlinCompile> {
3636
compilerOptions {
37-
jvmTarget.set(JvmTarget.JVM_17)
38-
freeCompilerArgs.add("-Xjdk-release=17")
37+
jvmTarget.set(JvmTarget.JVM_1_8)
38+
freeCompilerArgs.add("-Xjdk-release=1.8")
3939
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
4040
}
4141
}
4242

4343
tasks.withType<JavaCompile> {
44-
sourceCompatibility = JavaVersion.VERSION_17.toString()
45-
targetCompatibility = JavaVersion.VERSION_17.toString()
44+
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
45+
targetCompatibility = JavaVersion.VERSION_1_8.toString()
4646
}
4747

4848
// Reusable license copySpec

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ val generateSdkRuntimeVersion by tasks.registering {
5757

5858
tasks.withType<KotlinCompile> {
5959
compilerOptions {
60-
jvmTarget.set(JvmTarget.JVM_17)
61-
freeCompilerArgs.add("-Xjdk-release=17")
60+
jvmTarget.set(JvmTarget.JVM_1_8)
61+
freeCompilerArgs.add("-Xjdk-release=1.8")
6262
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
6363
}
6464
dependsOn(generateSdkRuntimeVersion)
6565
}
6666

6767
tasks.withType<JavaCompile> {
68-
sourceCompatibility = JavaVersion.VERSION_17.toString()
69-
targetCompatibility = JavaVersion.VERSION_17.toString()
68+
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
69+
targetCompatibility = JavaVersion.VERSION_1_8.toString()
7070
}
7171

7272
// Reusable license copySpec

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,9 @@ object RuntimeTypes {
530530
val requestApplicationRequest = symbol("ApplicationRequest", "request")
531531
val requestContentLength = symbol("contentLength", "request")
532532
val requestContentType = symbol("contentType", "request")
533-
val requestacceptItems = symbol("acceptItems", "request")
533+
val requestAcceptItems = symbol("acceptItems", "request")
534534

535-
val responseText = symbol("respondText", "response")
536-
val responseRespond = symbol("respond", "response")
535+
val responseResponseText = symbol("respondText", "response")
537536
val responseRespondBytes = symbol("respondBytes", "response")
538537
}
539538

@@ -602,8 +601,4 @@ object RuntimeTypes {
602601
object KotlinxJsonSerde : RuntimeTypePackage(KotlinDependency.KOTLINX_JSON_SERDE) {
603602
val Json = symbol("Json")
604603
}
605-
606-
object Duration {
607-
val seconds = "kotlin.time.Duration.Companion.seconds".toSymbol()
608-
}
609604
}

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/lang/KotlinTypes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ object KotlinTypes {
117117
val Duration = stdlibSymbol("Duration")
118118
val milliseconds = stdlibSymbol("milliseconds", "time.Duration.Companion")
119119
val minutes = stdlibSymbol("minutes", "time.Duration.Companion")
120+
val seconds = stdlibSymbol("seconds", "time.Duration.Companion")
120121
}
121122

122123
object Coroutines {

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import software.amazon.smithy.codegen.core.SymbolReference
99
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
1010
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
1111
import software.amazon.smithy.kotlin.codegen.core.withBlock
12+
import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes
1213
import software.amazon.smithy.kotlin.codegen.model.knowledge.SerdeIndex
1314
import software.amazon.smithy.kotlin.codegen.model.targetOrSelf
1415
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator
@@ -27,22 +28,23 @@ class CborSerializerGenerator(
2728
}
2829
val serializationShape = serializationTarget.get().let { ctx.model.expectShape(it) }
2930
val serializationSymbol = ctx.symbolProvider.toSymbol(serializationShape)
30-
if (ctx.settings.build.generateServiceProject) {
31-
return op.bodySerializer(ctx.settings) { writer ->
32-
addNestedDocumentSerializers(ctx, op, writer)
33-
writer.withBlock("private fun #L(context: #T, input: #T): ByteArray {", "}", op.bodySerializerName(), RuntimeTypes.Core.ExecutionContext, serializationSymbol) {
34-
call {
35-
renderSerializeOperationBody(ctx, op, members, writer)
36-
}
37-
}
38-
}
39-
} else {
40-
return op.bodySerializer(ctx.settings) { writer ->
41-
addNestedDocumentSerializers(ctx, op, writer)
42-
writer.withBlock("private fun #L(context: #T, input: #T): #T {", "}", op.bodySerializerName(), RuntimeTypes.Core.ExecutionContext, serializationSymbol, RuntimeTypes.Http.HttpBody) {
43-
call {
44-
renderSerializeOperationBody(ctx, op, members, writer)
45-
}
31+
32+
val serializerResultSymbol = when {
33+
ctx.settings.build.generateServiceProject -> KotlinTypes.ByteArray
34+
else -> RuntimeTypes.Http.HttpBody
35+
}
36+
return op.bodySerializer(ctx.settings) { writer ->
37+
addNestedDocumentSerializers(ctx, op, writer)
38+
writer.withBlock(
39+
"private fun #L(context: #T, input: #T): #T {",
40+
"}",
41+
op.bodySerializerName(),
42+
RuntimeTypes.Core.ExecutionContext,
43+
serializationSymbol,
44+
serializerResultSymbol,
45+
) {
46+
call {
47+
renderSerializeOperationBody(ctx, op, members, writer)
4648
}
4749
}
4850
}

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/KtorStubGenerator.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
88
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
99
import software.amazon.smithy.kotlin.codegen.core.withBlock
1010
import software.amazon.smithy.kotlin.codegen.core.withInlineBlock
11+
import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes
1112
import software.amazon.smithy.kotlin.codegen.model.getTrait
1213
import software.amazon.smithy.model.shapes.OperationShape
1314
import software.amazon.smithy.model.traits.AuthTrait
@@ -45,7 +46,6 @@ internal class KtorStubGenerator(
4546
writer.withBlock("internal class KtorServiceFramework() : ServiceFramework {", "}") {
4647
write("private var engine: #T<*, *>? = null", RuntimeTypes.KtorServerCore.EmbeddedServerType)
4748
write("")
48-
write("@Suppress(#S)", "UNCHECKED_CAST")
4949
write("private val engineFactory = #T.engine.toEngineFactory()", ServiceTypes(pkgName).serviceFrameworkConfig)
5050

5151
write("")
@@ -71,7 +71,7 @@ internal class KtorStubGenerator(
7171
write(
7272
"idleTimeout = #T.requestReadTimeoutSeconds.#T",
7373
ServiceTypes(pkgName).serviceFrameworkConfig,
74-
RuntimeTypes.Duration.seconds,
74+
KotlinTypes.Time.seconds,
7575
)
7676
}
7777
}
@@ -220,7 +220,7 @@ internal class KtorStubGenerator(
220220
writer.withBlock("internal fun #T.configureRouting(): Unit {", "}", RuntimeTypes.KtorServerCore.Application) {
221221
withBlock("#T {", "}", RuntimeTypes.KtorServerRouting.routing) {
222222
withBlock("#T(#S) {", "}", RuntimeTypes.KtorServerRouting.get, "/") {
223-
write(" #T.#T(#S)", RuntimeTypes.KtorServerCore.applicationCall, RuntimeTypes.KtorServerRouting.responseText, "hello world")
223+
write(" #T.#T(#S)", RuntimeTypes.KtorServerCore.applicationCall, RuntimeTypes.KtorServerRouting.responseResponseText, "hello world")
224224
}
225225
operations.filter { it.hasTrait(HttpTrait.ID) }
226226
.forEach { shape ->
@@ -337,9 +337,9 @@ internal class KtorStubGenerator(
337337
"#T.#T(",
338338
")",
339339
RuntimeTypes.KtorServerCore.applicationCall,
340-
RuntimeTypes.KtorServerRouting.responseRespond,
340+
RuntimeTypes.KtorServerRouting.responseResponseText,
341341
) {
342-
write("bytes = response.decodeToString(),")
342+
write("text = response,")
343343
write("contentType = #T,", RuntimeTypes.KtorServerHttp.Json)
344344
write(
345345
"status = #T.fromValue($successCode),",
@@ -383,8 +383,8 @@ internal class KtorStubGenerator(
383383
write("status: #T,", RuntimeTypes.KtorServerHttp.HttpStatusCode)
384384
}
385385
.withBlock("{", "}") {
386-
write("val acceptsCbor = request.#T().any { it.value == #S }", RuntimeTypes.KtorServerRouting.requestacceptItems, "application/cbor")
387-
write("val acceptsJson = request.#T().any { it.value == #S }", RuntimeTypes.KtorServerRouting.requestacceptItems, "application/json")
386+
write("val acceptsCbor = request.#T().any { it.value == #S }", RuntimeTypes.KtorServerRouting.requestAcceptItems, "application/cbor")
387+
write("val acceptsJson = request.#T().any { it.value == #S }", RuntimeTypes.KtorServerRouting.requestAcceptItems, "application/json")
388388
write("")
389389
write("val log = #T.getLogger(#S)", RuntimeTypes.KtorLoggingSlf4j.LoggerFactory, ctx.settings.pkg.name)
390390
write("log.info(#S)", "Route Error Message: \${envelope.msg}")
@@ -398,14 +398,14 @@ internal class KtorStubGenerator(
398398
}
399399
}
400400
withBlock("acceptsJson -> {", "}") {
401-
withBlock("#T(", ")", RuntimeTypes.KtorServerRouting.responseText) {
401+
withBlock("#T(", ")", RuntimeTypes.KtorServerRouting.responseResponseText) {
402402
write("envelope.toJson(),")
403403
write("status = status,")
404404
write("contentType = #T", RuntimeTypes.KtorServerHttp.Json)
405405
}
406406
}
407407
withBlock("else -> {", "}") {
408-
withBlock("#T(", ")", RuntimeTypes.KtorServerRouting.responseText) {
408+
withBlock("#T(", ")", RuntimeTypes.KtorServerRouting.responseResponseText) {
409409
write("envelope.msg,")
410410
write("status = status")
411411
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ kotlin-compile-testing-version = "0.7.0"
2727
kotlinx-benchmark-version = "0.4.12"
2828
kotlinx-serialization-version = "1.7.3"
2929
docker-java-version = "3.4.0"
30-
ktor-version = "3.1.1"
30+
ktor-version = "3.2.2"
3131
kaml-version = "0.55.0"
3232
jsoup-version = "1.19.1"
3333

tests/codegen/service-codegen-tests/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ tasks.test {
3434
}
3535
}
3636

37+
val optInAnnotations = listOf(
38+
"aws.smithy.kotlin.runtime.InternalApi",
39+
"kotlinx.serialization.ExperimentalSerializationApi",
40+
"kotlin.io.path.ExperimentalPathApi",
41+
)
42+
43+
kotlin {
44+
explicitApi()
45+
sourceSets.all {
46+
optInAnnotations.forEach { languageSettings.optIn(it) }
47+
}
48+
}
49+
3750
dependencies {
3851

3952
compileOnly(project(":codegen:smithy-kotlin-codegen"))

tests/codegen/service-codegen-tests/model/service-generator-test.smithy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$version: "1.0"
1+
$version: "2.0"
22

33
namespace com.test
44

tests/codegen/service-codegen-tests/src/main/kotlin/com/test/DefaultServiceGeneratorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.nio.file.Files
1010
import java.nio.file.Path
1111
import java.nio.file.Paths
1212

13-
fun main() {
13+
internal fun main() {
1414
val modelPath: Path = Paths.get("model", "service-generator-test.smithy")
1515
val defaultModel = ModelAssembler()
1616
.discoverModels()

0 commit comments

Comments
 (0)