Skip to content

Commit 0bcfbad

Browse files
luigi617luigi
andauthored
Service sdk error (#1319)
* service init, code to separate client and service * server can be ran * application in build.gradle.kts * detele non-finished code * ktlintformat * change style * ktlintformat * add abstraction for service * minor fix * minor fix * cbor serde * fix * formatting * comment * fix * fix * generate routing based on smithy file * ktlint format * service framework abstraction * ktlint foramt * logging * ktlint format * add ContentTypeGuard * ktlint * fix content type guard * ktlint * move some parameters, e.g. engine, port, log level to be chosen in runtime rather than compile * ktlint * fix * error handler * ktlint * fix logging * error handler message envelope * use error handler for content guard type * fix * fix * ktlint * ktlint * fix * remove manual input * fix * abstraction of service framework and run type * simplify the code * fix --------- Co-authored-by: luigi <[email protected]>
1 parent 7d3b630 commit 0bcfbad

File tree

8 files changed

+623
-301
lines changed

8 files changed

+623
-301
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/CodegenVisitor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import software.amazon.smithy.kotlin.codegen.model.hasTrait
2020
import software.amazon.smithy.kotlin.codegen.rendering.*
2121
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ApplicationProtocol
2222
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator
23-
import software.amazon.smithy.kotlin.codegen.service.ServiceStubGenerator
23+
import software.amazon.smithy.kotlin.codegen.service.AbstractStubGenerator
2424
import software.amazon.smithy.model.Model
2525
import software.amazon.smithy.model.knowledge.ServiceIndex
2626
import software.amazon.smithy.model.neighbor.Walker
@@ -153,7 +153,7 @@ class CodegenVisitor(context: PluginContext) : ShapeVisitor.Default<Unit>() {
153153
}
154154

155155
if (generateServiceProject) {
156-
val serviceStubGenerator = ServiceStubGenerator(baseGenerationContext, writers, fileManifest)
156+
val serviceStubGenerator: AbstractStubGenerator = settings.serviceStub.framework.getServiceFrameworkGenerator(baseGenerationContext, writers, fileManifest)
157157
serviceStubGenerator.render()
158158
}
159159

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const val RUNTIME_GROUP: String = "aws.smithy.kotlin"
3939
val RUNTIME_VERSION: String = System.getProperty("smithy.kotlin.codegen.clientRuntimeVersion", getDefaultRuntimeVersion())
4040
val KOTLIN_COMPILER_VERSION: String = System.getProperty("smithy.kotlin.codegen.kotlinCompilerVersion", "2.1.0")
4141
val KTOR_VERSION: String = System.getProperty("smithy.kotlin.codegen.ktorVersion", "3.1.3")
42-
val COROUTINES_VERSION: String = System.getProperty("smithy.kotlin.codegen.coroutinesVersion", "1.10.2")
42+
val SERIALIZATION_PLUGIN: String = System.getProperty("smithy.kotlin.codegen.SerializationPlugin", "2.0.20")
43+
val KOTLINX_VERSION: String = System.getProperty("smithy.kotlin.codegen.ktorKotlinxVersion", "1.9.0")
4344
val KTOR_LOGGING_BACKEND_VERSION: String = System.getProperty("smithy.kotlin.codegen.ktorLoggingBackendVersion", "1.4.14")
4445

4546
enum class SourceSet {
@@ -146,8 +147,9 @@ data class KotlinDependency(
146147
val KTOR_SERVER_LOGGING = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.plugins.calllogging", "io.ktor", "ktor-server-call-logging", KTOR_VERSION)
147148
val KTOR_LOGGING_SLF4J = KotlinDependency(GradleConfiguration.Implementation, "org.slf4j", "ch.qos.logback", "logback-classic", KTOR_LOGGING_BACKEND_VERSION)
148149
val KTOR_LOGGING_LOGBACK = KotlinDependency(GradleConfiguration.Implementation, "ch.qos.logback", "ch.qos.logback", "logback-classic", KTOR_LOGGING_BACKEND_VERSION)
149-
val KTOR_SERVER_CONTENT_NEGOTIATION = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.plugins.contentnegotiation", "io.ktor", "ktor-server-content-negotiation", KTOR_VERSION)
150-
val KTOR_SERVER_CBOR_SERDE = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.serialization.kotlinx.cbor", "io.ktor", "ktor-serialization-kotlinx-cbor", KTOR_VERSION)
150+
val KTOR_SERVER_STATUS_PAGE = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.plugins.statuspages", "io.ktor", "ktor-server-status-pages-jvm", KTOR_VERSION)
151+
val KOTLINX_CBOR_SERDE = KotlinDependency(GradleConfiguration.Implementation, "kotlinx.serialization", "org.jetbrains.kotlinx", "kotlinx-serialization-cbor", KOTLINX_VERSION)
152+
val KOTLINX_JSON_SERDE = KotlinDependency(GradleConfiguration.Implementation, "kotlinx.serialization.json", "org.jetbrains.kotlinx", "kotlinx-serialization-json", KOTLINX_VERSION)
151153
}
152154

153155
override fun getDependencies(): List<SymbolDependency> {

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,15 @@ object RuntimeTypes {
491491
val ApplicationEngineFactory = symbol("ApplicationEngineFactory", "engine")
492492

493493
val Application = symbol("Application", "application")
494+
val ApplicationCallClass = symbol("ApplicationCall", "application")
494495
val ApplicationStopping = symbol("ApplicationStopping", "application")
495496
val ApplicationStopped = symbol("ApplicationStopped", "application")
496497
val ApplicationCreateRouteScopedPlugin = symbol("createRouteScopedPlugin", "application")
497498
val ApplicationRouteScopedPlugin = symbol("RouteScopedPlugin", "application")
498499
val applicationCall = symbol("call", "application")
499500
val install = symbol("install", "application")
501+
502+
val BadRequestException = symbol("BadRequestException", "plugins")
500503
}
501504

502505
object KtorServerRouting : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_CORE) {
@@ -513,11 +516,14 @@ object RuntimeTypes {
513516
val requestReceive = symbol("receive", "request")
514517
val requestUri = symbol("uri", "request")
515518
val requestHttpMethod = symbol("httpMethod", "request")
519+
val requestApplicationRequest = symbol("ApplicationRequest", "request")
520+
val requestContentLength = symbol("contentLength", "request")
521+
val requestContentType = symbol("contentType", "request")
522+
val requestacceptItems = symbol("acceptItems", "request")
516523

517524
val responseText = symbol("respondText", "response")
518525
val responseRespond = symbol("respond", "response")
519526
val responseRespondBytes = symbol("respondBytes", "response")
520-
val requestContentType = symbol("contentType", "request")
521527
}
522528

523529
object KtorServerNetty : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_NETTY) {
@@ -527,6 +533,7 @@ object RuntimeTypes {
527533
object KtorServerHttp : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_HTTP) {
528534
val ContentType = symbol("ContentType")
529535
val HttpStatusCode = symbol("HttpStatusCode")
536+
val HttpHeaders = symbol("HttpHeaders")
530537
val Cbor = symbol("Cbor", "ContentType.Application")
531538
val Json = symbol("Json", "ContentType.Application")
532539
}
@@ -545,4 +552,19 @@ object RuntimeTypes {
545552
val Level = symbol("Level", "classic")
546553
val LoggerContext = symbol("LoggerContext", "classic")
547554
}
555+
556+
object KtorServerStatusPage : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_STATUS_PAGE) {
557+
val StatusPages = symbol("StatusPages")
558+
val exception = symbol("exception")
559+
}
560+
561+
object KotlinxCborSerde : RuntimeTypePackage(KotlinDependency.KOTLINX_CBOR_SERDE) {
562+
val Serializable = symbol("Serializable")
563+
val Cbor = symbol("Cbor", "cbor")
564+
val encodeToByteArray = symbol("encodeToByteArray")
565+
}
566+
567+
object KotlinxJsonSerde : RuntimeTypePackage(KotlinDependency.KOTLINX_JSON_SERDE) {
568+
val Json = symbol("Json")
569+
}
548570
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fun writeGradleBuild(
5656
{ w: AbstractCodeWriter<*> ->
5757
if (generateServiceProject) {
5858
w.write("application")
59+
w.write("kotlin(#S) version #S", "plugin.serialization", SERIALIZATION_PLUGIN)
5960
}
6061
},
6162
)

0 commit comments

Comments
 (0)