diff --git a/.changes/1669a4b4-4b10-4ca6-b11a-43bf5413de19.json b/.changes/1669a4b4-4b10-4ca6-b11a-43bf5413de19.json new file mode 100644 index 0000000000..6c08e1378d --- /dev/null +++ b/.changes/1669a4b4-4b10-4ca6-b11a-43bf5413de19.json @@ -0,0 +1,5 @@ +{ + "id": "1669a4b4-4b10-4ca6-b11a-43bf5413de19", + "type": "misc", + "description": "Upgrade to Smithy 1.49.0" +} \ No newline at end of file diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt index e318804322..10be8bfc6e 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt @@ -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 /** @@ -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, + 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, @@ -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, + 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) + } + } + } + } +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt index c79bc20bc1..21fac173ef 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt @@ -151,7 +151,7 @@ abstract class AbstractQueryFormUrlSerializerGenerator( } } - private fun renderSerializerBody( + open fun renderSerializerBody( ctx: ProtocolGenerator.GenerationContext, shape: Shape, members: List, diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/model/RulesEngineExt.kt b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/model/RulesEngineExt.kt index 67057f1087..1428516fc9 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/model/RulesEngineExt.kt +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/model/RulesEngineExt.kt @@ -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. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a5a39af9e3..7db994687f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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