diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index e5dcda5393c..66ef942dc5c 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -186,3 +186,15 @@ message = "Smithy IDL v2 mixins are now supported" references = ["smithy-rs#1680"] meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all"} author = "ogudavid" + +[[smithy-rs]] +message = "Upgrade Smithy to 1.25.0" +references = ["smithy-rs#1725"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all"} +author = "sugmanue" + +[[smithy-rs]] +message = "Correctly determine nullability of members in IDLv2 models" +references = ["smithy-rs#1725"] +meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "all"} +author = "sugmanue" diff --git a/aws/sdk-adhoc-test/build.gradle.kts b/aws/sdk-adhoc-test/build.gradle.kts index b6d59ef47c8..9edc1aab731 100644 --- a/aws/sdk-adhoc-test/build.gradle.kts +++ b/aws/sdk-adhoc-test/build.gradle.kts @@ -25,6 +25,12 @@ configure { } buildscript { + repositories { + mavenLocal() + mavenCentral() + google() + } + val smithyVersion: String by project dependencies { classpath("software.amazon.smithy:smithy-cli:$smithyVersion") diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapes.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapes.kt deleted file mode 100644 index 7f2cc008eff..00000000000 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapes.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rustsdk.customize.ec2 - -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.AbstractShapeBuilder -import software.amazon.smithy.model.shapes.BigDecimalShape -import software.amazon.smithy.model.shapes.BigIntegerShape -import software.amazon.smithy.model.shapes.BooleanShape -import software.amazon.smithy.model.shapes.ByteShape -import software.amazon.smithy.model.shapes.DoubleShape -import software.amazon.smithy.model.shapes.FloatShape -import software.amazon.smithy.model.shapes.IntegerShape -import software.amazon.smithy.model.shapes.LongShape -import software.amazon.smithy.model.shapes.NumberShape -import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.model.shapes.ShortShape -import software.amazon.smithy.model.traits.BoxTrait -import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.util.UNREACHABLE -import software.amazon.smithy.utils.ToSmithyBuilder - -object BoxPrimitiveShapes { - fun processModel(model: Model): Model { - val transformer = ModelTransformer.create() - return transformer.mapShapes(model, ::boxPrimitives) - } - - private fun boxPrimitives(shape: Shape): Shape { - return when (shape) { - is NumberShape -> { - when (shape) { - is ByteShape -> box(shape) - is DoubleShape -> box(shape) - is LongShape -> box(shape) - is ShortShape -> box(shape) - is FloatShape -> box(shape) - is BigDecimalShape -> box(shape) - is BigIntegerShape -> box(shape) - is IntegerShape -> box(shape) - else -> UNREACHABLE("unhandled numeric shape: $shape") - } - } - is BooleanShape -> box(shape) - else -> shape - } - } - - private fun box(shape: T): Shape where T : Shape, T : ToSmithyBuilder { - return (shape.toBuilder() as AbstractShapeBuilder<*, T>).addTrait(BoxTrait()).build() - } -} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptional.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptional.kt new file mode 100644 index 00000000000..bff87c0d5d5 --- /dev/null +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptional.kt @@ -0,0 +1,24 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rustsdk.customize.ec2 + +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.Shape +import software.amazon.smithy.model.traits.ClientOptionalTrait +import software.amazon.smithy.model.transform.ModelTransformer + +object EC2MakePrimitivesOptional { + fun processModel(model: Model): Model { + val updates = arrayListOf() + for (struct in model.structureShapes) { + for (member in struct.allMembers.values) { + updates.add(member.toBuilder().addTrait(ClientOptionalTrait()).build()) + } + + } + return ModelTransformer.create().replaceShapes(model, updates) + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt index d4152dc324d..784ed2c47a1 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt @@ -26,7 +26,7 @@ class Ec2Decorator : RustCodegenDecorator { // need to be boxed for the API to work properly return model.letIf( applies(service), - BoxPrimitiveShapes::processModel, + EC2MakePrimitivesOptional::processModel, ) } diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapesTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/AddClientOptionalToShapesTest.kt similarity index 69% rename from aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapesTest.kt rename to aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/AddClientOptionalToShapesTest.kt index ff9a944c3df..2d5f7325a72 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapesTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/AddClientOptionalToShapesTest.kt @@ -7,13 +7,12 @@ package software.amazon.smithy.rustsdk.customize.ec2 import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test +import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.model.traits.BoxTrait import software.amazon.smithy.rust.codegen.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.util.hasTrait import software.amazon.smithy.rust.codegen.util.lookup -internal class BoxPrimitiveShapesTest { +internal class AddClientOptionalToShapesTest { @Test fun `primitive shapes are boxed`() { val baseModel = """ @@ -33,15 +32,11 @@ internal class BoxPrimitiveShapesTest { structure Other {} """.asSmithyModel() - val model = BoxPrimitiveShapes.processModel(baseModel) - + val model = EC2MakePrimitivesOptional.processModel(baseModel) + val nullableIndex = NullableIndex(model) val struct = model.lookup("test#Primitives") struct.members().forEach { - val target = model.expectShape(it.target) - when (target) { - is StructureShape -> target.hasTrait() shouldBe false - else -> target.hasTrait() shouldBe true - } + nullableIndex.isMemberNullable(it, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1) shouldBe true } } } diff --git a/aws/sdk/build.gradle.kts b/aws/sdk/build.gradle.kts index e09f62b44a3..be8857614ce 100644 --- a/aws/sdk/build.gradle.kts +++ b/aws/sdk/build.gradle.kts @@ -35,6 +35,12 @@ val sdkOutputDir = outputDir.resolve("sdk") val examplesOutputDir = outputDir.resolve("examples") buildscript { + repositories { + mavenLocal() + mavenCentral() + google() + } + val smithyVersion: String by project dependencies { classpath("software.amazon.smithy:smithy-aws-traits:$smithyVersion") diff --git a/build.gradle.kts b/build.gradle.kts index c6ff9c783bb..dd0d11b1e9e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,6 +4,7 @@ */ buildscript { repositories { + mavenLocal() mavenCentral() google() } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index b1d48a62e5c..85ddfe20412 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -11,6 +11,7 @@ plugins { jacoco } repositories { + mavenLocal() mavenCentral() google() } diff --git a/codegen-client-test/build.gradle.kts b/codegen-client-test/build.gradle.kts index 0fb9ea9482f..8155ebeda3e 100644 --- a/codegen-client-test/build.gradle.kts +++ b/codegen-client-test/build.gradle.kts @@ -21,6 +21,11 @@ val pluginName = "rust-codegen" val workingDirUnderBuildDir = "smithyprojections/codegen-client-test/" buildscript { + repositories { + mavenLocal() + mavenCentral() + google() + } val smithyVersion: String by project dependencies { classpath("software.amazon.smithy:smithy-cli:$smithyVersion") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt index 184b94581c3..834f6806e73 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.smithy import software.amazon.smithy.build.PluginContext import software.amazon.smithy.model.Model +import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.neighbor.Walker import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.Shape @@ -62,6 +63,7 @@ class CodegenVisitor(context: PluginContext, private val codegenDecorator: RustC renameExceptions = settings.codegenConfig.renameExceptions, handleRequired = false, handleRustBoxing = true, + nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT, ) val baseModel = baselineTransform(context.model) val service = settings.getService(baseModel) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt index 4b49387c5cd..dda0d9b3def 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt @@ -65,6 +65,7 @@ data class SymbolVisitorConfig( val renameExceptions: Boolean, val handleRustBoxing: Boolean, val handleRequired: Boolean, + val nullabilityCheckMode: NullableIndex.CheckMode, ) /** @@ -211,7 +212,7 @@ open class SymbolVisitor( private fun handleOptionality(symbol: Symbol, member: MemberShape): Symbol = if (config.handleRequired && member.isRequired) { symbol - } else if (nullableIndex.isNullable(member)) { + } else if (nullableIndex.isMemberNullable(member, config.nullabilityCheckMode)) { symbol.makeOptional() } else { symbol diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/testutil/TestHelpers.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/testutil/TestHelpers.kt index 55cc877c22a..3c2a3eff0ef 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/testutil/TestHelpers.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/testutil/TestHelpers.kt @@ -94,6 +94,7 @@ fun String.asSmithyModel(sourceLocation: String? = null, smithyVersion: String = .unwrap() } + /** * In tests, we frequently need to generate a struct, a builder, and an impl block to access said builder. */ diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt index 951c389b047..f2c6e40b0cf 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt @@ -125,17 +125,13 @@ class SymbolBuilderTest { "PrimitiveBoolean, false, bool", ) fun `creates primitives`(primitiveType: String, optional: Boolean, rustName: String) { - val memberBuilder = MemberShape.builder().id("foo.bar#MyStruct\$quux").target("smithy.api#$primitiveType") - val member = memberBuilder.build() - val struct = StructureShape.builder() - .id("foo.bar#MyStruct") - .addMember(member) - .build() - val model = Model.assembler() - .addShapes(struct, member) - .assemble() - .unwrap() - + val model = """ + namespace foo.bar + structure MyStruct { + quux: $primitiveType + } +""".asSmithyModel() + var member = model.expectShape(ShapeId.from("foo.bar#MyStruct\$quux")) val provider: SymbolProvider = testSymbolProvider(model) val memberSymbol = provider.toSymbol(member) // builtins should not have a namespace set diff --git a/codegen-server-test/build.gradle.kts b/codegen-server-test/build.gradle.kts index 8912b9b35af..eb2430bdfc1 100644 --- a/codegen-server-test/build.gradle.kts +++ b/codegen-server-test/build.gradle.kts @@ -22,6 +22,11 @@ val pluginName = "rust-server-codegen" val workingDirUnderBuildDir = "smithyprojections/codegen-server-test/" buildscript { + repositories { + mavenLocal() + mavenCentral() + google() + } val smithyVersion: String by project dependencies { classpath("software.amazon.smithy:smithy-cli:$smithyVersion") diff --git a/codegen-server-test/python/build.gradle.kts b/codegen-server-test/python/build.gradle.kts index 004060e48fc..ddf15804ab1 100644 --- a/codegen-server-test/python/build.gradle.kts +++ b/codegen-server-test/python/build.gradle.kts @@ -26,6 +26,11 @@ configure { } buildscript { + repositories { + mavenLocal() + mavenCentral() + google() + } val smithyVersion: String by project dependencies { classpath("software.amazon.smithy:smithy-cli:$smithyVersion") diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 1b28ee8599a..0b0ba93a18e 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.build.PluginContext import software.amazon.smithy.model.Model +import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.neighbor.Walker import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.Shape @@ -70,6 +71,7 @@ open class ServerCodegenVisitor( renameExceptions = false, handleRequired = true, handleRustBoxing = true, + nullabilityCheckMode = NullableIndex.CheckMode.SERVER, ) val baseModel = baselineTransform(context.model) val service = settings.getService(baseModel) diff --git a/gradle.properties b/gradle.properties index a5e8c71f08f..9e739d51a7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ kotlin.code.style=official # codegen smithyGradlePluginVersion=0.6.0 -smithyVersion=1.23.1 +smithyVersion=1.25.0 # kotlin kotlinVersion=1.6.21