Skip to content

Commit 4e86b3e

Browse files
luigi617luigi
andauthored
Service sdk json (#1367)
Co-authored-by: luigi <[email protected]>
1 parent 65ca841 commit 4e86b3e

File tree

34 files changed

+1656
-306
lines changed

34 files changed

+1656
-306
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package software.amazon.smithy.kotlin.codegen.aws.protocols
77

88
import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait
99
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait
10+
import software.amazon.smithy.codegen.core.Symbol
1011
import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AbstractQueryFormUrlSerializerGenerator
1112
import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator
1213
import software.amazon.smithy.kotlin.codegen.aws.protocols.core.QueryHttpBindingProtocolGenerator
@@ -86,6 +87,14 @@ private class AwsQuerySerializerGenerator(
8687
members: List<MemberShape>,
8788
writer: KotlinWriter,
8889
): FormUrlSerdeDescriptorGenerator = AwsQuerySerdeFormUrlDescriptorGenerator(ctx.toRenderingContext(protocolGenerator, shape, writer), members)
90+
91+
override fun errorSerializer(
92+
ctx: ProtocolGenerator.GenerationContext,
93+
errorShape: StructureShape,
94+
members: List<MemberShape>,
95+
): Symbol {
96+
TODO("Used for service-codegen. Not yet implemented")
97+
}
8998
}
9099

91100
private class AwsQueryXmlParserGenerator(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ private class Ec2QuerySerializerGenerator(
9898
members: List<MemberShape>,
9999
writer: KotlinWriter,
100100
): FormUrlSerdeDescriptorGenerator = Ec2QuerySerdeFormUrlDescriptorGenerator(ctx.toRenderingContext(protocolGenerator, shape, writer), members)
101+
102+
override fun errorSerializer(
103+
ctx: ProtocolGenerator.GenerationContext,
104+
errorShape: StructureShape,
105+
members: List<MemberShape>,
106+
): Symbol {
107+
TODO("Used for service-codegen. Not yet implemented")
108+
}
101109
}
102110

103111
private class Ec2QueryParserGenerator(

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
4040
writer: KotlinWriter,
4141
) {
4242
super.renderSerializeHttpBody(ctx, op, writer)
43+
if (ctx.settings.build.generateServiceProject) return
4344

4445
val resolver = getProtocolHttpBindingResolver(ctx.model, ctx.service)
45-
if (!resolver.hasHttpBody(op)) return
46+
47+
if (!resolver.hasHttpRequestBody(op)) return
4648

4749
// restjson1 has some different semantics and expectations around empty structures bound via @httpPayload trait
4850
// * empty structures get serialized to `{}`

codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ class AwsHttpBindingProtocolGeneratorTest {
123123
): Symbol {
124124
error("Unneeded for test")
125125
}
126+
127+
override fun errorSerializer(
128+
ctx: ProtocolGenerator.GenerationContext,
129+
errorShape: StructureShape,
130+
members: List<MemberShape>,
131+
): Symbol {
132+
error("Unneeded for test")
133+
}
126134
}
127135

128136
override val protocol: ShapeId

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ class MockHttpProtocolGenerator(model: Model) : HttpBindingProtocolGenerator() {
214214
val symbol = ctx.symbolProvider.toSymbol(shape)
215215
name = "serialize" + StringUtils.capitalize(symbol.name) + "Payload"
216216
}
217+
218+
override fun errorSerializer(
219+
ctx: ProtocolGenerator.GenerationContext,
220+
errorShape: StructureShape,
221+
members: List<MemberShape>,
222+
): Symbol {
223+
error("Unneeded for test")
224+
}
217225
}
218226

219227
override fun operationErrorHandler(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Symbol = buildSymbol {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ data class KotlinDependency(
143143
// Ktor server dependencies
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)
146+
val KTOR_SERVER_UTILS = KotlinDependency(GradleConfiguration.Implementation, "io.ktor", "io.ktor", "ktor-server-core", KTOR_VERSION)
146147
val KTOR_SERVER_NETTY = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.netty", "io.ktor", "ktor-server-netty", KTOR_VERSION)
147148
val KTOR_SERVER_CIO = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.cio", "io.ktor", "ktor-server-cio", KTOR_VERSION)
148149
val KTOR_SERVER_JETTY_JAKARTA = KotlinDependency(GradleConfiguration.Implementation, "io.ktor.server.jetty.jakarta", "io.ktor", "ktor-server-jetty-jakarta", KTOR_VERSION)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,10 @@ object RuntimeTypes {
513513
val BadRequestException = symbol("BadRequestException", "plugins")
514514
}
515515

516+
object KtorServerUtils : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_UTILS) {
517+
val AttributeKey = symbol("AttributeKey", "util")
518+
}
519+
516520
object KtorServerRouting : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_CORE) {
517521
val routing = symbol("routing", "routing")
518522
val route = symbol("route", "routing")
@@ -558,6 +562,9 @@ object RuntimeTypes {
558562
val HttpHeaders = symbol("HttpHeaders")
559563
val Cbor = symbol("Cbor", "ContentType.Application")
560564
val Json = symbol("Json", "ContentType.Application")
565+
val Any = symbol("Any", "ContentType.Application")
566+
val OctetStream = symbol("OctetStream", "ContentType.Application")
567+
val PlainText = symbol("Plain", "ContentType.Text")
561568
}
562569

563570
object KtorServerLogging : RuntimeTypePackage(KotlinDependency.KTOR_SERVER_LOGGING) {

0 commit comments

Comments
 (0)