Skip to content

Commit

Permalink
misc: upgrade to Smithy 1.49.0 (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis authored Jun 14, 2024
1 parent 4b5e50d commit 976bb90
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/1669a4b4-4b10-4ca6-b11a-43bf5413de19.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1669a4b4-4b10-4ca6-b11a-43bf5413de19",
"type": "misc",
"description": "Upgrade to Smithy 1.49.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AbstractQueryFormUrlSerializerGenerator
import software.amazon.smithy.kotlin.codegen.aws.protocols.core.QueryHttpBindingProtocolGenerator
import software.amazon.smithy.kotlin.codegen.aws.protocols.formurl.QuerySerdeFormUrlDescriptorGenerator
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
import software.amazon.smithy.kotlin.codegen.core.RenderingContext
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
import software.amazon.smithy.kotlin.codegen.core.withBlock
import software.amazon.smithy.kotlin.codegen.core.*
import software.amazon.smithy.kotlin.codegen.model.buildSymbol
import software.amazon.smithy.kotlin.codegen.model.getTrait
import software.amazon.smithy.kotlin.codegen.model.isNullable
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator
import software.amazon.smithy.kotlin.codegen.rendering.protocol.toRenderingContext
import software.amazon.smithy.kotlin.codegen.rendering.serde.*
import software.amazon.smithy.model.shapes.*
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.model.traits.XmlNameTrait

/**
Expand Down Expand Up @@ -76,6 +75,20 @@ private class Ec2QuerySerializerGenerator(
private val protocolGenerator: Ec2Query,
) : AbstractQueryFormUrlSerializerGenerator(protocolGenerator, protocolGenerator.defaultTimestampFormat) {

override fun renderSerializerBody(
ctx: ProtocolGenerator.GenerationContext,
shape: Shape,
members: List<MemberShape>,
writer: KotlinWriter,
) {
// render the serde descriptors
descriptorGenerator(ctx, shape, members, writer).render()
when (shape) {
is UnionShape -> SerializeUnionGenerator(ctx, shape, members, writer, protocolGenerator.defaultTimestampFormat).render()
else -> Ec2QuerySerializeStructGenerator(ctx, members, writer, protocolGenerator.defaultTimestampFormat).render()
}
}

override fun descriptorGenerator(
ctx: ProtocolGenerator.GenerationContext,
shape: Shape,
Expand Down Expand Up @@ -155,3 +168,34 @@ private class Ec2QueryParserGenerator(
}
}
}

/**
* An EC2 Query implementation of [SerializeStructGenerator] which ensures that empty lists are not serialized.
*/
private class Ec2QuerySerializeStructGenerator(
ctx: ProtocolGenerator.GenerationContext,
members: List<MemberShape>,
writer: KotlinWriter,
defaultTimestampFormat: TimestampFormatTrait.Format,
) : SerializeStructGenerator(ctx, members, writer, defaultTimestampFormat) {
override fun renderListMemberSerializer(memberShape: MemberShape, targetShape: CollectionShape) {
val memberName = ctx.symbolProvider.toMemberName(memberShape)
val descriptorName = memberShape.descriptorName()
val nestingLevel = 0
val memberSymbol = ctx.symbolProvider.toSymbol(memberShape)

if (memberSymbol.isNullable) {
writer.withBlock("if (!input.$memberName.isNullOrEmpty()) {", "}") {
writer.withBlock("listField($descriptorName) {", "}") {
delegateListSerialization(memberShape, targetShape, nestingLevel, memberName)
}
}
} else {
writer.withBlock("if (input.$memberName.isNotEmpty()) {", "}") {
writer.withBlock("listField($descriptorName) {", "}") {
delegateListSerialization(memberShape, targetShape, nestingLevel, memberName)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ abstract class AbstractQueryFormUrlSerializerGenerator(
}
}

private fun renderSerializerBody(
open fun renderSerializerBody(
ctx: ProtocolGenerator.GenerationContext,
shape: Shape,
members: List<MemberShape>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fun ParameterType.toSymbol(): Symbol =
when (this) {
ParameterType.STRING -> KotlinTypes.String
ParameterType.BOOLEAN -> KotlinTypes.Boolean
}
.asNullable()
ParameterType.STRING_ARRAY -> KotlinTypes.Collections.MutableList
}.asNullable()

/**
* Get the writable literal for a rules engine value.
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ slf4j-v1x-version = "1.7.36"
crt-kotlin-version = "0.8.5"

# codegen
smithy-version = "1.47.0"
smithy-version = "1.49.0"
smithy-gradle-version = "0.9.0"

# testing
Expand Down

0 comments on commit 976bb90

Please sign in to comment.