Skip to content

Commit 7806f7d

Browse files
luigi617luigiianbotsfaws-sdk-kotlin-ci
authored
Service sdk testing (#1330)
Co-authored-by: luigi <[email protected]> Co-authored-by: Ian Botsford <[email protected]> Co-authored-by: aws-sdk-kotlin-ci <[email protected]>
1 parent b14626d commit 7806f7d

File tree

17 files changed

+1077
-82
lines changed

17 files changed

+1077
-82
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ apiValidation {
114114
"nullability-tests",
115115
"paginator-tests",
116116
"waiter-tests",
117+
"service-codegen-tests",
117118
"compile",
118119
"slf4j-1x-consumer",
119120
"slf4j-2x-consumer",

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
109109
resolver.requestBindings(op)
110110
}
111111
val httpPayload = bindings.firstOrNull { it.location == HttpBinding.Location.PAYLOAD }
112+
112113
if (httpPayload != null) {
113114
renderExplicitHttpPayloadSerializer(ctx, httpPayload, writer)
114115
} else {
@@ -117,9 +118,15 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
117118
// delegate to the generate operation body serializer function
118119
val sdg = structuredDataSerializer(ctx)
119120
val opBodySerializerFn = sdg.operationSerializer(ctx, op, documentMembers)
120-
writer.write("builder.body = #T(context, input)", opBodySerializerFn)
121+
if (ctx.settings.build.generateServiceProject) {
122+
writer.write("response = #T(context, input)", opBodySerializerFn)
123+
} else {
124+
writer.write("builder.body = #T(context, input)", opBodySerializerFn)
125+
}
126+
}
127+
if (!ctx.settings.build.generateServiceProject) {
128+
renderContentTypeHeader(ctx, op, writer, resolver)
121129
}
122-
renderContentTypeHeader(ctx, op, writer, resolver)
123130
}
124131

125132
/**

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private fun getDefaultRuntimeVersion(): String {
3838
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.2.0")
41-
val KTOR_VERSION: String = System.getProperty("smithy.kotlin.codegen.ktorVersion", "3.1.3")
41+
val KTOR_VERSION: String = System.getProperty("smithy.kotlin.codegen.ktorVersion", "3.2.2")
4242
val SERIALIZATION_PLUGIN: String = System.getProperty("smithy.kotlin.codegen.SerializationPlugin", "2.0.20")
4343
val KOTLINX_VERSION: String = System.getProperty("smithy.kotlin.codegen.ktorKotlinxVersion", "1.9.0")
4444
val KTOR_LOGGING_BACKEND_VERSION: String = System.getProperty("smithy.kotlin.codegen.ktorLoggingBackendVersion", "1.4.14")
@@ -144,8 +144,11 @@ data class KotlinDependency(
144144
// FIXME: version numbers should not be hardcoded, they should be setting dynamically based on the Gradle library versions
145145
val KTOR_SERVER_CORE = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server", "io.ktor", "ktor-server-core", KTOR_VERSION)
146146
val KTOR_SERVER_NETTY = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.netty", "io.ktor", "ktor-server-netty", KTOR_VERSION)
147+
val KTOR_SERVER_CIO = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.cio", "io.ktor", "ktor-server-cio", KTOR_VERSION)
148+
val KTOR_SERVER_JETTY_JAKARTA = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.jetty.jakarta", "io.ktor", "ktor-server-jetty-jakarta", KTOR_VERSION)
147149
val KTOR_SERVER_HTTP = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.http", "io.ktor", "ktor-http-jvm", KTOR_VERSION)
148150
val KTOR_SERVER_LOGGING = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.plugins.calllogging", "io.ktor", "ktor-server-call-logging", KTOR_VERSION)
151+
val KTOR_SERVER_BODY_LIMIT = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.plugins", "io.ktor", "ktor-server-body-limit", KTOR_VERSION)
149152
val KTOR_LOGGING_SLF4J = KotlinDependency(GradleConfiguration.Implementation, "org.slf4j", "ch.qos.logback", "logback-classic", KTOR_LOGGING_BACKEND_VERSION)
150153
val KTOR_LOGGING_LOGBACK = KotlinDependency(GradleConfiguration.Implementation, "ch.qos.logback", "ch.qos.logback", "logback-classic", KTOR_LOGGING_BACKEND_VERSION)
151154
val KTOR_SERVER_STATUS_PAGE = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.plugins.statuspages", "io.ktor", "ktor-server-status-pages-jvm", KTOR_VERSION)

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,12 @@ object RuntimeTypes {
497497
val embeddedServer = symbol("embeddedServer", "engine")
498498
val EmbeddedServerType = symbol("EmbeddedServer", "engine")
499499
val ApplicationEngineFactory = symbol("ApplicationEngineFactory", "engine")
500+
val connector = symbol("connector", "engine")
500501

501502
val Application = symbol("Application", "application")
502503
val ApplicationCallClass = symbol("ApplicationCall", "application")
504+
val ApplicationStarting = symbol("ApplicationStarting", "application")
505+
val ApplicationStarted = symbol("ApplicationStarted", "application")
503506
val ApplicationStopping = symbol("ApplicationStopping", "application")
504507
val ApplicationStopped = symbol("ApplicationStopped", "application")
505508
val ApplicationCreateRouteScopedPlugin = symbol("createRouteScopedPlugin", "application")
@@ -527,20 +530,31 @@ object RuntimeTypes {
527530
val requestApplicationRequest = symbol("ApplicationRequest", "request")
528531
val requestContentLength = symbol("contentLength", "request")
529532
val requestContentType = symbol("contentType", "request")
530-
val requestacceptItems = symbol("acceptItems", "request")
533+
val requestAcceptItems = symbol("acceptItems", "request")
531534

532-
val responseText = symbol("respondText", "response")
533-
val responseRespond = symbol("respond", "response")
535+
val responseResponseText = symbol("respondText", "response")
534536
val responseRespondBytes = symbol("respondBytes", "response")
535537
}
536538

537539
object KtorServerNetty : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_NETTY) {
538540
val Netty = symbol("Netty")
541+
val Configuration = symbol("Configuration", "NettyApplicationEngine")
542+
}
543+
544+
object KtorServerCio : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_CIO) {
545+
val CIO = symbol("CIO")
546+
val Configuration = symbol("Configuration", "CIOApplicationEngine")
547+
}
548+
549+
object KtorServerJettyJakarta : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_JETTY_JAKARTA) {
550+
val Jetty = symbol("Jetty")
551+
val Configuration = symbol("Configuration", "JettyApplicationEngineBase")
539552
}
540553

541554
object KtorServerHttp : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_HTTP) {
542555
val ContentType = symbol("ContentType")
543556
val HttpStatusCode = symbol("HttpStatusCode")
557+
val parseAndSortHeader = symbol("parseAndSortHeader")
544558
val HttpHeaders = symbol("HttpHeaders")
545559
val Cbor = symbol("Cbor", "ContentType.Application")
546560
val Json = symbol("Json", "ContentType.Application")
@@ -550,6 +564,11 @@ object RuntimeTypes {
550564
val CallLogging = symbol("CallLogging")
551565
}
552566

567+
object KtorServerBodyLimit : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_BODY_LIMIT) {
568+
val RequestBodyLimit = symbol("RequestBodyLimit", "bodylimit")
569+
val PayloadTooLargeException = symbol("PayloadTooLargeException")
570+
}
571+
553572
object KtorLoggingSlf4j : RuntimeTypePackage(KotlinDependency.KTOR_LOGGING_SLF4J) {
554573
val Level = symbol("Level", "event")
555574
val LoggerFactory = symbol("LoggerFactory")

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/protocol/HttpBindingProtocolGenerator.kt

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
136136
}
137137

138138
override fun generateProtocolClient(ctx: ProtocolGenerator.GenerationContext) {
139+
if (ctx.settings.build.generateServiceProject) {
140+
require(protocolName == "smithyRpcv2cbor") { "service project accepts only Cbor protocol" }
141+
}
139142
if (!ctx.settings.build.generateServiceProject) {
140143
val symbol = ctx.symbolProvider.toSymbol(ctx.service)
141144
ctx.delegator.useFileWriter("Default${symbol.name}.kt", ctx.settings.pkg.name) { writer ->
@@ -182,27 +185,47 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
182185
val serdeMeta = HttpSerdeMeta(op.isInputEventStream(ctx.model))
183186

184187
ctx.delegator.useSymbolWriter(serializerSymbol) { writer ->
185-
writer
186-
.addImport(operationSerializerSymbols)
187-
.write("")
188-
.openBlock("internal class #T: #T.#L<#T> {", serializerSymbol, RuntimeTypes.HttpClient.Operation.HttpSerializer, serdeMeta.variantName, serializationSymbol)
189-
.call {
190-
val modifier = if (serdeMeta.isStreaming) "suspend " else ""
191-
writer.openBlock(
192-
"override #Lfun serialize(context: #T, input: #T): #T {",
193-
modifier,
194-
RuntimeTypes.Core.ExecutionContext,
195-
serializationSymbol,
196-
RuntimeTypes.Http.Request.HttpRequestBuilder,
197-
)
198-
.write("val builder = #T()", RuntimeTypes.Http.Request.HttpRequestBuilder)
199-
.call {
200-
renderHttpSerialize(ctx, op, writer)
201-
}
202-
.write("return builder")
203-
.closeBlock("}")
204-
}
205-
.closeBlock("}")
188+
// FIXME: this works only for Cbor protocol now
189+
if (ctx.settings.build.generateServiceProject) {
190+
writer
191+
.openBlock("internal class #T {", serializerSymbol)
192+
.call {
193+
writer.openBlock(
194+
"public fun serialize(context: #T, input: #T): ByteArray {",
195+
RuntimeTypes.Core.ExecutionContext,
196+
serializationSymbol,
197+
)
198+
.write("var response: Any")
199+
.call {
200+
renderSerializeHttpBody(ctx, op, writer)
201+
}
202+
.write("return response")
203+
.closeBlock("}")
204+
}
205+
.closeBlock("}")
206+
} else {
207+
writer
208+
.addImport(operationSerializerSymbols)
209+
.write("")
210+
.openBlock("internal class #T: #T.#L<#T> {", serializerSymbol, RuntimeTypes.HttpClient.Operation.HttpSerializer, serdeMeta.variantName, serializationSymbol)
211+
.call {
212+
val modifier = if (serdeMeta.isStreaming) "suspend " else ""
213+
writer.openBlock(
214+
"override #Lfun serialize(context: #T, input: #T): #T {",
215+
modifier,
216+
RuntimeTypes.Core.ExecutionContext,
217+
serializationSymbol,
218+
RuntimeTypes.Http.Request.HttpRequestBuilder,
219+
)
220+
.write("val builder = #T()", RuntimeTypes.Http.Request.HttpRequestBuilder)
221+
.call {
222+
renderHttpSerialize(ctx, op, writer)
223+
}
224+
.write("return builder")
225+
.closeBlock("}")
226+
}
227+
.closeBlock("}")
228+
}
206229
}
207230
}
208231

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

Lines changed: 18 additions & 2 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
@@ -28,9 +29,20 @@ class CborSerializerGenerator(
2829
val serializationShape = serializationTarget.get().let { ctx.model.expectShape(it) }
2930
val serializationSymbol = ctx.symbolProvider.toSymbol(serializationShape)
3031

32+
val serializerResultSymbol = when {
33+
ctx.settings.build.generateServiceProject -> KotlinTypes.ByteArray
34+
else -> RuntimeTypes.Http.HttpBody
35+
}
3136
return op.bodySerializer(ctx.settings) { writer ->
3237
addNestedDocumentSerializers(ctx, op, writer)
33-
writer.withBlock("private fun #L(context: #T, input: #T): #T {", "}", op.bodySerializerName(), RuntimeTypes.Core.ExecutionContext, serializationSymbol, RuntimeTypes.Http.HttpBody) {
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+
) {
3446
call {
3547
renderSerializeOperationBody(ctx, op, members, writer)
3648
}
@@ -52,7 +64,11 @@ class CborSerializerGenerator(
5264
val serializationshape = ctx.model.expectShape(serializationTarget.get())
5365
writer.write("val serializer = #T()", RuntimeTypes.Serde.SerdeCbor.CborSerializer)
5466
renderSerializerBody(ctx, serializationshape, documentMembers, writer)
55-
writer.write("return serializer.toHttpBody()")
67+
if (ctx.settings.build.generateServiceProject) {
68+
writer.write("return serializer.toByteArray()")
69+
} else {
70+
writer.write("return serializer.toHttpBody()")
71+
}
5672
}
5773

5874
private fun renderSerializerBody(

0 commit comments

Comments
 (0)