From 9b7028826e4fc7df6af7283e6b02b087db1c23bd Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 8 Jan 2023 03:49:20 +0000 Subject: [PATCH 01/27] add CfgUnstable for feature-gate --- .../smithy/rust/codegen/core/rustlang/CargoDependency.kt | 4 ++++ .../rust/codegen/core/smithy/generators/CargoTomlGenerator.kt | 2 ++ 2 files changed, 6 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index 6d355da68a..6083b73d72 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -16,6 +16,7 @@ import java.nio.file.Path sealed class DependencyScope { object Dev : DependencyScope() object Compile : DependencyScope() + object CfgUnstable : DependencyScope() } sealed class DependencyLocation @@ -245,5 +246,8 @@ data class CargoDependency( fun smithyQuery(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-query") fun smithyTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-types") fun smithyXml(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-xml") + + // behind feature-gate + val Serde = CargoDependency("serde", CratesIo("1.0"), features = setOf("derive"), scope = DependencyScope.CfgUnstable) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt index cceced878b..fee9e4e0e1 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt @@ -74,6 +74,8 @@ class CargoTomlGenerator( .associate { it.name to it.toMap() }, "dev-dependencies" to dependencies.filter { it.scope == DependencyScope.Dev } .associate { it.name to it.toMap() }, + "target.'cfg(aws_sdk_unstable)'.dependencies" to dependencies.filter { it.scope == DependencyScope.CfgUnstable } + .associate { it.name to it.toMap() }, "features" to cargoFeatures.toMap(), ).deepMergeWith(manifestCustomizations) From 5c794cff9730231bfcd79987df498dcbbb77db9c Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 8 Jan 2023 04:29:23 +0000 Subject: [PATCH 02/27] add features --- .../codegen/core/smithy/generators/CargoTomlGenerator.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt index fee9e4e0e1..3f2d5e42e8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt @@ -54,6 +54,9 @@ class CargoTomlGenerator( if (features.isNotEmpty()) { cargoFeatures.add("default" to features.filter { it.default }.map { it.name }) } + // add serde related features + cargoFeatures.add("serialize" to listOf("aws-smithy-types/serialize")) + cargoFeatures.add("deserialize" to listOf("aws-smithy-types/deserialize")) val cargoToml = mapOf( "package" to listOfNotNull( @@ -74,7 +77,7 @@ class CargoTomlGenerator( .associate { it.name to it.toMap() }, "dev-dependencies" to dependencies.filter { it.scope == DependencyScope.Dev } .associate { it.name to it.toMap() }, - "target.'cfg(aws_sdk_unstable)'.dependencies" to dependencies.filter { it.scope == DependencyScope.CfgUnstable } + "target.'cfg(aws_sdk_unstable)'" to dependencies.filter { it.scope == DependencyScope.CfgUnstable } .associate { it.name to it.toMap() }, "features" to cargoFeatures.toMap(), ).deepMergeWith(manifestCustomizations) From 6403cecec1807972f2849e4dfe0747898b1e53d1 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 8 Jan 2023 07:44:19 +0000 Subject: [PATCH 03/27] add feature-gate --- .../amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index 1ad33d9e95..b7ab185f9a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -239,6 +239,10 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null) val ConstrainedTrait = RuntimeType("crate::constrained::Constrained", InlineDependency.constrained()) val MaybeConstrained = RuntimeType("crate::constrained::MaybeConstrained", InlineDependency.constrained()) + // serde types. They will be behind feature gates + val SerdeSerialize = CargoDependency.Serde.toType().resolve("Serialize") + val SerdeDeserialize = CargoDependency.Serde.toType().resolve("Deserialize") + // smithy runtime types fun smithyAsync(runtimeConfig: RuntimeConfig) = CargoDependency.smithyAsync(runtimeConfig).toType() fun smithyChecksums(runtimeConfig: RuntimeConfig) = CargoDependency.smithyChecksums(runtimeConfig).toType() From 1f33a5c83bc865a462f2239408b58f695a616f60 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 8 Jan 2023 07:45:54 +0000 Subject: [PATCH 04/27] strings for feature gate --- .../rust/codegen/core/smithy/FeatureGate.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt new file mode 100644 index 0000000000..74db04284a --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt @@ -0,0 +1,22 @@ +// / this object holds constants for feature gate +object FeatureGate { + val AwsSdkUnstable = "aws_sdk_unstable" + + // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` + val AttrUnstableSerdeAny = """ + ##[cfg(all($AwsSdkUnstable, any(feature = "serialize", feature = "deserialize")))] + """ + val AttrUnstableSerdeBoth = """ + all($AwsSdkUnstable, all(feature = "serialize", feature = "deserialize")) + """ + val AttrUnstableSerialize = """ + all($AwsSdkUnstable, feature = "serialize") + """ + val AttrUnstableDeserialize = """ + all($AwsSdkUnstable, feature = "deserialize") + """ + + // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` + val UnstableDerive = """##[cfg_attr(all($AwsSdkUnstable, feature = "serialize"), derive(serde::Serialize))] +##[cfg_attr(all($AwsSdkUnstable, feature = "deserialize"), derive(serde::Deserialize))]""" +} From 2fb7178e2ecc0d81226b2346c6aacdeeb2dd71b9 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 8 Jan 2023 08:26:34 +0000 Subject: [PATCH 05/27] Revert "strings for feature gate" This reverts commit 1f33a5c83bc865a462f2239408b58f695a616f60. --- .../rust/codegen/core/smithy/FeatureGate.kt | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt deleted file mode 100644 index 74db04284a..0000000000 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/FeatureGate.kt +++ /dev/null @@ -1,22 +0,0 @@ -// / this object holds constants for feature gate -object FeatureGate { - val AwsSdkUnstable = "aws_sdk_unstable" - - // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` - val AttrUnstableSerdeAny = """ - ##[cfg(all($AwsSdkUnstable, any(feature = "serialize", feature = "deserialize")))] - """ - val AttrUnstableSerdeBoth = """ - all($AwsSdkUnstable, all(feature = "serialize", feature = "deserialize")) - """ - val AttrUnstableSerialize = """ - all($AwsSdkUnstable, feature = "serialize") - """ - val AttrUnstableDeserialize = """ - all($AwsSdkUnstable, feature = "deserialize") - """ - - // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` - val UnstableDerive = """##[cfg_attr(all($AwsSdkUnstable, feature = "serialize"), derive(serde::Serialize))] -##[cfg_attr(all($AwsSdkUnstable, feature = "deserialize"), derive(serde::Deserialize))]""" -} From 1717d721ba0e6d2bc748dec731a786aa9f88ad4e Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Wed, 11 Jan 2023 09:28:15 +0900 Subject: [PATCH 06/27] Update codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt Co-authored-by: Zelda Hessler --- .../amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index b7ab185f9a..a107e73b8a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -239,7 +239,7 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null) val ConstrainedTrait = RuntimeType("crate::constrained::Constrained", InlineDependency.constrained()) val MaybeConstrained = RuntimeType("crate::constrained::MaybeConstrained", InlineDependency.constrained()) - // serde types. They will be behind feature gates + // serde types. Gated behind `CfgUnstable`. val SerdeSerialize = CargoDependency.Serde.toType().resolve("Serialize") val SerdeDeserialize = CargoDependency.Serde.toType().resolve("Deserialize") From e16ce62421e4142637f843c0e52d37d2c36f9b05 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Wed, 11 Jan 2023 05:17:10 +0000 Subject: [PATCH 07/27] fix dependency thing on cargo --- .../rust/codegen/core/smithy/generators/CargoTomlGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt index 3f2d5e42e8..9681ef3f09 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt @@ -77,7 +77,7 @@ class CargoTomlGenerator( .associate { it.name to it.toMap() }, "dev-dependencies" to dependencies.filter { it.scope == DependencyScope.Dev } .associate { it.name to it.toMap() }, - "target.'cfg(aws_sdk_unstable)'" to dependencies.filter { it.scope == DependencyScope.CfgUnstable } + "target.'cfg(aws_sdk_unstable)'.dependencies" to dependencies.filter { it.scope == DependencyScope.CfgUnstable } .associate { it.name to it.toMap() }, "features" to cargoFeatures.toMap(), ).deepMergeWith(manifestCustomizations) From 14d5e1d6a1ae2d125d817cf97e0f8e37fbba7819 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Wed, 11 Jan 2023 05:26:17 +0000 Subject: [PATCH 08/27] add OutputShape to builder --- .../rust/codegen/core/smithy/UnstableDerive.kt | 17 +++++++++++++++++ .../core/smithy/generators/BuilderGenerator.kt | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt new file mode 100644 index 0000000000..0fd522df48 --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt @@ -0,0 +1,17 @@ +object UnstableDerive { + // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` + val AttrUnstableSerdeAny = """##[cfg(all(aws_sdk_unstable, any(feature = "serde-serialize", feature = "serde-deserialize")))]""" + val AttrUnstableSerdeBoth = """ + all(aws_sdk_unstable, all(feature = "serde-serialize", feature = "serde-deserialize")) + """ + val AttrUnstableSerialize = """ + all(aws_sdk_unstable, feature = "serde-serialize") + """ + val AttrUnstableDeserialize = """ + all(aws_sdk_unstable, feature = "serde-deserialize") + """ + + // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` + val UnstableDerive = """##[cfg_attr(all(aws_sdk_unstable, feature = "serde-serialize"), derive(serde::Serialize))] +##[cfg_attr(all(aws_sdk_unstable, feature = "serde-deserialize"), derive(serde::Deserialize))]""" +} \ No newline at end of file diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 69aca45630..fbe008337f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -48,6 +48,7 @@ import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.redactIfNecessary import software.amazon.smithy.rust.codegen.core.util.toSnakeCase +import UnstableDerive // TODO(https://github.com/awslabs/smithy-rs/issues/1401) This builder generator is only used by the client. // Move this entire file, and its tests, to `codegen-client`. @@ -208,7 +209,11 @@ class BuilderGenerator( private fun renderBuilder(writer: RustWriter) { writer.docs("A builder for #D.", structureSymbol) Attribute(derive(builderDerives)).render(writer) + writer.writeInline("/// This is the datatype that Builder of this module build itself into.\n") + writer.writeInline("pub type OutputShape = #D", structureSymbol) + writer.writeInline(UnstableDerive.UnstableDerive) writer.rustBlock("pub struct $builderName") { + // add serde for (member in members) { val memberName = symbolProvider.toMemberName(member) // All fields in the builder are optional. From cc61ede8084edefd739f5f4a04094aec7cdf39ae Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Wed, 11 Jan 2023 05:30:39 +0000 Subject: [PATCH 09/27] EnumGenerator --- .../rust/codegen/core/smithy/generators/EnumGenerator.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index ec8f3505e9..763d7eceb9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -33,6 +33,7 @@ import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rust.codegen.core.util.shouldRedact +import UnstableDerive /** Model that wraps [EnumDefinition] to calculate and cache values required to generate the Rust enum source. */ class EnumMemberModel(private val definition: EnumDefinition, private val symbolProvider: RustSymbolProvider) { @@ -139,6 +140,7 @@ open class EnumGenerator( private fun renderUnnamedEnum() { writer.documentShape(shape, model) writer.deprecatedShape(shape) + writer.writeInline(UnstableDerive.UnstableDerive) meta.render(writer) writer.write("struct $enumName(String);") writer.rustBlock("impl $enumName") { @@ -178,7 +180,8 @@ open class EnumGenerator( renamedWarning.ifBlank { null }, ) writer.deprecatedShape(shape) - + + writer.writeInline(UnstableDerive.UnstableDerive) meta.render(writer) writer.rustBlock("enum $enumName") { sortedMembers.forEach { member -> member.render(writer) } @@ -225,6 +228,7 @@ open class EnumGenerator( part of the enums that are public interface. """.trimIndent(), ) + writer.writeInline(UnstableDerive.UnstableDerive) meta.render(this) rust("struct $UnknownVariantValue(pub(crate) String);") rustBlock("impl $UnknownVariantValue") { From 22ef698b8f01a85e57a129cd3f3b22eabb7f2590 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Wed, 11 Jan 2023 05:30:46 +0000 Subject: [PATCH 10/27] StructureGenerator --- .../rust/codegen/core/smithy/generators/StructureGenerator.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 7e88d3d1fa..21944b62ca 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -35,6 +35,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.redactIfNecessary +import UnstableDerive fun RustWriter.implBlock(structureShape: Shape, symbolProvider: SymbolProvider, block: Writable) { rustBlock("impl ${symbolProvider.toSymbol(structureShape).name}") { @@ -144,6 +145,7 @@ open class StructureGenerator( val containerMeta = symbol.expectRustMetadata() writer.documentShape(shape, model) writer.deprecatedShape(shape) + writer.writeInline(UnstableDerive.UnstableDerive) containerMeta.render(writer) writer.rustBlock("struct $name ${lifetimeDeclaration()}") { From 7aaa74421f51cce22f30398286ec15a84f5eaf59 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Wed, 11 Jan 2023 05:31:32 +0000 Subject: [PATCH 11/27] UnionGenerator --- .../rust/codegen/core/smithy/generators/UnionGenerator.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt index 69cd25f2ea..70ce166daf 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt @@ -29,6 +29,7 @@ import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.isTargetUnit import software.amazon.smithy.rust.codegen.core.util.shouldRedact import software.amazon.smithy.rust.codegen.core.util.toSnakeCase +import UnstableDerive fun CodegenTarget.renderUnknownVariant() = when (this) { CodegenTarget.SERVER -> false @@ -63,6 +64,7 @@ class UnionGenerator( writer.deprecatedShape(shape) val containerMeta = unionSymbol.expectRustMetadata() + writer.writeInline(UnstableDerive.UnstableDerive) containerMeta.render(writer) renderUnion(unionSymbol) From 8b12529a611cf4c0efbfdc9ca24fb13905fe054e Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Wed, 11 Jan 2023 07:09:28 +0000 Subject: [PATCH 12/27] todo --- .../client/smithy/customize/SerdeDecorator.kt | 27 ++++++++++++++++ .../client/smithy/transformers/SkipSerde.kt | 31 +++++++++++++++++++ .../smithy/generators/StructureGenerator.kt | 5 +++ 3 files changed, 63 insertions(+) create mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt create mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt new file mode 100644 index 0000000000..e99e5b19ba --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -0,0 +1,27 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.smithy.customizations + +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.containerDocs +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization +import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext + +class SerdeDecorator: ClientCodegenDecorator { + override val name: String = "SerdeDecorator" + override val order: Byte = 0 + + override fun configCustomizations( + codegenContext: ClientCodegenContext, + baseCustomizations: List, + ): List { + codegenContext.settings. + } +} \ No newline at end of file diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt new file mode 100644 index 0000000000..44d79610c7 --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt @@ -0,0 +1,31 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.smithy.transformers + +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.model.shapes.StructureShape +import software.amazon.smithy.model.transform.ModelTransformer +import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings +import software.amazon.smithy.rust.codegen.core.util.findStreamingMember +import software.amazon.smithy.rust.codegen.core.util.orNull +import java.util.logging.Logger + +// https://github.com/awslabs/smithy-rs/pull/1944#discussion_r1047800762 +// TODO +object SkipSerde { + private val logger = Logger.getLogger(javaClass.name) + + fun transform(model: Model, settings: ClientRustSettings): Model { + // If Event Stream is allowed in build config, then don't remove the operations + + + return ModelTransformer.create().filterShapes(model) { parentShape -> + // TODO! + } + } +} + \ No newline at end of file diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 21944b62ca..b6512e6fe9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -135,6 +135,11 @@ open class StructureGenerator( open fun renderStructureMember(writer: RustWriter, member: MemberShape, memberName: String, memberSymbol: Symbol) { writer.renderMemberDoc(member, memberSymbol) + + // todo! check if it is sensitive + // if { + //writer.writeInline("This data may contain sensitive information; You must be careful when you serialize this.") + // } writer.deprecatedShape(member) memberSymbol.expectRustMetadata().render(writer) writer.write("$memberName: #T,", memberSymbol) From cd602bf1458e309a3ac2c5929556a54d539776fc Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Thu, 12 Jan 2023 11:56:25 +0000 Subject: [PATCH 13/27] fixed? --- .../client/smithy/customize/SerdeDecorator.kt | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index e99e5b19ba..32ce90481a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -1,27 +1,41 @@ /* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +* SPDX-License-Identifier: Apache-2.0 +*/ -package software.amazon.smithy.rust.codegen.client.smithy.customizations +package software.amazon.smithy.rust.codegen.client.smithy.customize -import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.containerDocs -import software.amazon.smithy.rust.codegen.core.rustlang.writable -import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.customizations.EndpointPrefixGenerator +import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpChecksumRequiredGenerator +import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpVersionListCustomization +import software.amazon.smithy.rust.codegen.client.smithy.customizations.IdempotencyTokenGenerator +import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyConfigCustomization +import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyReExportCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.customizations.AllowLintsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customizations.CrateVersionCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customizations.pubUseSmithyTypes +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -class SerdeDecorator: ClientCodegenDecorator { - override val name: String = "SerdeDecorator" - override val order: Byte = 0 +/** + * This class, + * - Adds serde as a dependency + * + */ +class SerdeDecorator : ClientCodegenDecorator { + override val name: String = "Required" + override val order: Byte = -1 - override fun configCustomizations( - codegenContext: ClientCodegenContext, - baseCustomizations: List, - ): List { - codegenContext.settings. + override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { + rustCrate.mergeFeature(Feature("serde-serialize", false, listOf("aws-sdk-types/serde-serialize"))) + rustCrate.mergeFeature(Feature("serde-deserialize", false, listOf("aws-sdk-types/serde-deserialize"))) } -} \ No newline at end of file + +} From b90a1b22f96c896ca71e8a9b9404d879a22a4387 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Thu, 12 Jan 2023 11:58:23 +0000 Subject: [PATCH 14/27] SerdeDecorator --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 32ce90481a..545ed7316a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -30,7 +30,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext * */ class SerdeDecorator : ClientCodegenDecorator { - override val name: String = "Required" + override val name: String = "SerdeDecorator" override val order: Byte = -1 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { From 1cefde27e57fd55e60f70476e36e79979a17ed11 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Thu, 12 Jan 2023 12:03:02 +0000 Subject: [PATCH 15/27] codegen stuff --- .../client/smithy/RustClientCodegenPlugin.kt | 2 ++ .../client/smithy/transformers/SkipSerde.kt | 31 ------------------- 2 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index 8750fa0c96..740256f260 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCustomizations +import software.amazon.smithy.rust.codegen.client.smithy.customize.SerdeDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator @@ -53,6 +54,7 @@ class RustClientCodegenPlugin : DecoratableBuildPlugin() { val codegenDecorator = CombinedClientCodegenDecorator.fromClasspath( context, + SerdeDecorator(), ClientCustomizations(), RequiredCustomizations(), FluentClientDecorator(), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt deleted file mode 100644 index 44d79610c7..0000000000 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/SkipSerde.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rust.codegen.client.smithy.transformers - -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings -import software.amazon.smithy.rust.codegen.core.util.findStreamingMember -import software.amazon.smithy.rust.codegen.core.util.orNull -import java.util.logging.Logger - -// https://github.com/awslabs/smithy-rs/pull/1944#discussion_r1047800762 -// TODO -object SkipSerde { - private val logger = Logger.getLogger(javaClass.name) - - fun transform(model: Model, settings: ClientRustSettings): Model { - // If Event Stream is allowed in build config, then don't remove the operations - - - return ModelTransformer.create().filterShapes(model) { parentShape -> - // TODO! - } - } -} - \ No newline at end of file From 25ed6ff282f10725db7cdb2016ab5108afbed008 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Thu, 12 Jan 2023 12:27:34 +0000 Subject: [PATCH 16/27] update --- .../codegen/client/smithy/customize/SerdeDecorator.kt | 9 +++++++-- .../codegen/core/smithy/generators/CargoTomlGenerator.kt | 5 +---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 545ed7316a..d3282badd0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -34,8 +34,13 @@ class SerdeDecorator : ClientCodegenDecorator { override val order: Byte = -1 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { - rustCrate.mergeFeature(Feature("serde-serialize", false, listOf("aws-sdk-types/serde-serialize"))) - rustCrate.mergeFeature(Feature("serde-deserialize", false, listOf("aws-sdk-types/serde-deserialize"))) + fun _feature(feature_name: String, crate_name: String): Feature { + return Feature(feature_name, false, listOf(crate_name+"/"+feature_name)) + } + rustCrate.mergeFeature(_feature("serde-serialize", "aws-sdk-types")) + rustCrate.mergeFeature(_feature("serde-deserialize", "aws-sdk-types")) + rustCrate.mergeFeature(_feature("serde-serialize", "aws-sdk-http")) + rustCrate.mergeFeature(_feature("serde-deserialize", "aws-sdk-http")) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt index 9681ef3f09..4b145cffd0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt @@ -54,10 +54,7 @@ class CargoTomlGenerator( if (features.isNotEmpty()) { cargoFeatures.add("default" to features.filter { it.default }.map { it.name }) } - // add serde related features - cargoFeatures.add("serialize" to listOf("aws-smithy-types/serialize")) - cargoFeatures.add("deserialize" to listOf("aws-smithy-types/deserialize")) - + val cargoToml = mapOf( "package" to listOfNotNull( "name" to settings.moduleName, From 6a3757edd8a7283833de380445d0cec63bb3573b Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Thu, 12 Jan 2023 13:11:32 +0000 Subject: [PATCH 17/27] fix --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index d3282badd0..15ebd7670d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -39,8 +39,5 @@ class SerdeDecorator : ClientCodegenDecorator { } rustCrate.mergeFeature(_feature("serde-serialize", "aws-sdk-types")) rustCrate.mergeFeature(_feature("serde-deserialize", "aws-sdk-types")) - rustCrate.mergeFeature(_feature("serde-serialize", "aws-sdk-http")) - rustCrate.mergeFeature(_feature("serde-deserialize", "aws-sdk-http")) } - } From a1dd4303831b9fdeed66f3fa54363c63715db1ee Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Tue, 24 Jan 2023 23:16:33 +0900 Subject: [PATCH 18/27] Apply suggestions from code review Co-authored-by: Zelda Hessler --- .../rust/codegen/core/smithy/generators/BuilderGenerator.kt | 4 ++-- .../rust/codegen/core/smithy/generators/StructureGenerator.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index fbe008337f..72f93cdfdd 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -209,8 +209,8 @@ class BuilderGenerator( private fun renderBuilder(writer: RustWriter) { writer.docs("A builder for #D.", structureSymbol) Attribute(derive(builderDerives)).render(writer) - writer.writeInline("/// This is the datatype that Builder of this module build itself into.\n") - writer.writeInline("pub type OutputShape = #D", structureSymbol) + writer.docs("This is the datatype that Builder of this module build itself into.") + writer.rustInline("pub type OutputShape = #D", structureSymbol) writer.writeInline(UnstableDerive.UnstableDerive) writer.rustBlock("pub struct $builderName") { // add serde diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index b6512e6fe9..6f396b52ec 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -138,7 +138,7 @@ open class StructureGenerator( // todo! check if it is sensitive // if { - //writer.writeInline("This data may contain sensitive information; You must be careful when you serialize this.") + // writer.writeInline("This data contains sensitive information; It will be not be obscured when serialized.") // } writer.deprecatedShape(member) memberSymbol.expectRustMetadata().render(writer) From 8c0843d06f26cac14bd608c73e40e776fe1bc302 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 24 Jan 2023 14:41:02 +0000 Subject: [PATCH 19/27] - refactoring - pre-commit - https://github.com/awslabs/smithy-rs/pull/2183/files#r1080594621 --- .../client/smithy/RustClientCodegenPlugin.kt | 2 +- .../client/smithy/customize/SerdeDecorator.kt | 17 +---------------- .../rust/codegen/core/rustlang/RustType.kt | 10 ++++++++++ .../rust/codegen/core/smithy/UnstableDerive.kt | 17 ----------------- .../core/smithy/generators/BuilderGenerator.kt | 1 - .../smithy/generators/CargoTomlGenerator.kt | 2 +- .../core/smithy/generators/EnumGenerator.kt | 3 +-- .../smithy/generators/StructureGenerator.kt | 5 ++--- .../core/smithy/generators/UnionGenerator.kt | 1 - 9 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index 740256f260..4dfba55846 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -10,11 +10,11 @@ import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.customize.SerdeDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations +import software.amazon.smithy.rust.codegen.client.smithy.customize.SerdeDecorator import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointsDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator import software.amazon.smithy.rust.codegen.client.testutil.DecoratableBuildPlugin diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 15ebd7670d..1fed4e05b3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -5,24 +5,9 @@ package software.amazon.smithy.rust.codegen.client.smithy.customize -import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customizations.EndpointPrefixGenerator -import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpChecksumRequiredGenerator -import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpVersionListCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customizations.IdempotencyTokenGenerator -import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyConfigCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyReExportCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator import software.amazon.smithy.rust.codegen.core.rustlang.Feature import software.amazon.smithy.rust.codegen.core.smithy.RustCrate -import software.amazon.smithy.rust.codegen.core.smithy.customizations.AllowLintsCustomization -import software.amazon.smithy.rust.codegen.core.smithy.customizations.CrateVersionCustomization -import software.amazon.smithy.rust.codegen.core.smithy.customizations.pubUseSmithyTypes -import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext /** * This class, @@ -35,7 +20,7 @@ class SerdeDecorator : ClientCodegenDecorator { override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { fun _feature(feature_name: String, crate_name: String): Feature { - return Feature(feature_name, false, listOf(crate_name+"/"+feature_name)) + return Feature(feature_name, false, listOf(crate_name + "/" + feature_name)) } rustCrate.mergeFeature(_feature("serde-serialize", "aws-sdk-types")) rustCrate.mergeFeature(_feature("serde-deserialize", "aws-sdk-types")) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index c39af9da0c..9306bd1d4f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -447,6 +447,16 @@ class Attribute(val inner: Writable) { } companion object { + fun cfg_attr(vararg attrMacros: Writable): Writable = macroWithArgs("cfg_attr", *attrMacros) + val UnstableSerdeAny = Attribute(cfg(all(writable("aws_sdk_unstable"), any(pair("feature" to "serde-serialize"), pair("feature" to "serde-deserialize"))))) + val UnstableSerdeAll = all(writable("aws_sdk_unstable"), all(pair("feature" to "serde-serialize"), pair("feature" to "serde-deserialize"))) + val UnstableSerialize = all(writable("aws_sdk_unstable"), pair("feature" to "serde-serialize")) + val UnstableDeserialize = all(writable("aws_sdk_unstable"), pair("feature" to "serde-deserialize")) + val UnstableSerdeDerive = writable { + Attribute(cfg_attr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-serialize"), derive(CargoDependency.Serde.resolve("Serialize"))))).render(this) + Attribute(cfg_attr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-deserialize"), derive(CargoDependency.Serde.resolve("Deserialize"))))).render(this) + } + val AllowClippyBoxedLocal = Attribute(allow("clippy::boxed_local")) val AllowClippyLetAndReturn = Attribute(allow("clippy::let_and_return")) val AllowClippyNeedlessBorrow = Attribute(allow("clippy::needless_borrow")) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt deleted file mode 100644 index 0fd522df48..0000000000 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/UnstableDerive.kt +++ /dev/null @@ -1,17 +0,0 @@ -object UnstableDerive { - // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` - val AttrUnstableSerdeAny = """##[cfg(all(aws_sdk_unstable, any(feature = "serde-serialize", feature = "serde-deserialize")))]""" - val AttrUnstableSerdeBoth = """ - all(aws_sdk_unstable, all(feature = "serde-serialize", feature = "serde-deserialize")) - """ - val AttrUnstableSerialize = """ - all(aws_sdk_unstable, feature = "serde-serialize") - """ - val AttrUnstableDeserialize = """ - all(aws_sdk_unstable, feature = "serde-deserialize") - """ - - // double `#` is because this data is passed onto writeInLine, which will interpret it as a variable with single `#` - val UnstableDerive = """##[cfg_attr(all(aws_sdk_unstable, feature = "serde-serialize"), derive(serde::Serialize))] -##[cfg_attr(all(aws_sdk_unstable, feature = "serde-deserialize"), derive(serde::Deserialize))]""" -} \ No newline at end of file diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 72f93cdfdd..94837a863c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -48,7 +48,6 @@ import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.redactIfNecessary import software.amazon.smithy.rust.codegen.core.util.toSnakeCase -import UnstableDerive // TODO(https://github.com/awslabs/smithy-rs/issues/1401) This builder generator is only used by the client. // Move this entire file, and its tests, to `codegen-client`. diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt index 4b145cffd0..fee9e4e0e1 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt @@ -54,7 +54,7 @@ class CargoTomlGenerator( if (features.isNotEmpty()) { cargoFeatures.add("default" to features.filter { it.default }.map { it.name }) } - + val cargoToml = mapOf( "package" to listOfNotNull( "name" to settings.moduleName, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index 763d7eceb9..edd1e5534d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -33,7 +33,6 @@ import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rust.codegen.core.util.shouldRedact -import UnstableDerive /** Model that wraps [EnumDefinition] to calculate and cache values required to generate the Rust enum source. */ class EnumMemberModel(private val definition: EnumDefinition, private val symbolProvider: RustSymbolProvider) { @@ -180,7 +179,7 @@ open class EnumGenerator( renamedWarning.ifBlank { null }, ) writer.deprecatedShape(shape) - + writer.writeInline(UnstableDerive.UnstableDerive) meta.render(writer) writer.rustBlock("enum $enumName") { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 6f396b52ec..807f4ed1c7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -35,7 +35,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.redactIfNecessary -import UnstableDerive fun RustWriter.implBlock(structureShape: Shape, symbolProvider: SymbolProvider, block: Writable) { rustBlock("impl ${symbolProvider.toSymbol(structureShape).name}") { @@ -135,10 +134,10 @@ open class StructureGenerator( open fun renderStructureMember(writer: RustWriter, member: MemberShape, memberName: String, memberSymbol: Symbol) { writer.renderMemberDoc(member, memberSymbol) - + // todo! check if it is sensitive // if { - // writer.writeInline("This data contains sensitive information; It will be not be obscured when serialized.") + // writer.writeInline("This data contains sensitive information; It will be not be obscured when serialized.") // } writer.deprecatedShape(member) memberSymbol.expectRustMetadata().render(writer) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt index 70ce166daf..a84e02f4a9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt @@ -29,7 +29,6 @@ import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.isTargetUnit import software.amazon.smithy.rust.codegen.core.util.shouldRedact import software.amazon.smithy.rust.codegen.core.util.toSnakeCase -import UnstableDerive fun CodegenTarget.renderUnknownVariant() = when (this) { CodegenTarget.SERVER -> false From d64ee3a238e04a886e5c59606689322e0ff9c613 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 24 Jan 2023 17:44:05 +0000 Subject: [PATCH 20/27] adds serde-serialize/deserialize --- CHANGELOG.next.toml | 2 +- .../client/smithy/customize/SerdeDecorator.kt | 4 ++-- .../smithy/rust/codegen/core/rustlang/RustType.kt | 13 +++---------- .../core/smithy/generators/BuilderGenerator.kt | 9 +++++---- .../codegen/core/smithy/generators/EnumGenerator.kt | 10 +++++----- .../core/smithy/generators/StructureGenerator.kt | 7 ++++--- .../core/smithy/generators/UnionGenerator.kt | 4 ++-- rust-runtime/aws-smithy-types/Cargo.toml | 4 ++++ 8 files changed, 26 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fc4c4c2578..0afcaae4a3 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -9,4 +9,4 @@ # message = "Fix typos in module documentation for generated crates" # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} -# author = "rcoh" \ No newline at end of file +# author = "rcoh" diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 1fed4e05b3..56a777b470 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -22,7 +22,7 @@ class SerdeDecorator : ClientCodegenDecorator { fun _feature(feature_name: String, crate_name: String): Feature { return Feature(feature_name, false, listOf(crate_name + "/" + feature_name)) } - rustCrate.mergeFeature(_feature("serde-serialize", "aws-sdk-types")) - rustCrate.mergeFeature(_feature("serde-deserialize", "aws-sdk-types")) + rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types")) + rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types")) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 9306bd1d4f..6f280da072 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -447,16 +447,6 @@ class Attribute(val inner: Writable) { } companion object { - fun cfg_attr(vararg attrMacros: Writable): Writable = macroWithArgs("cfg_attr", *attrMacros) - val UnstableSerdeAny = Attribute(cfg(all(writable("aws_sdk_unstable"), any(pair("feature" to "serde-serialize"), pair("feature" to "serde-deserialize"))))) - val UnstableSerdeAll = all(writable("aws_sdk_unstable"), all(pair("feature" to "serde-serialize"), pair("feature" to "serde-deserialize"))) - val UnstableSerialize = all(writable("aws_sdk_unstable"), pair("feature" to "serde-serialize")) - val UnstableDeserialize = all(writable("aws_sdk_unstable"), pair("feature" to "serde-deserialize")) - val UnstableSerdeDerive = writable { - Attribute(cfg_attr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-serialize"), derive(CargoDependency.Serde.resolve("Serialize"))))).render(this) - Attribute(cfg_attr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-deserialize"), derive(CargoDependency.Serde.resolve("Deserialize"))))).render(this) - } - val AllowClippyBoxedLocal = Attribute(allow("clippy::boxed_local")) val AllowClippyLetAndReturn = Attribute(allow("clippy::let_and_return")) val AllowClippyNeedlessBorrow = Attribute(allow("clippy::needless_borrow")) @@ -478,6 +468,8 @@ class Attribute(val inner: Writable) { val DocInline = Attribute(doc("inline")) val Test = Attribute("test") val TokioTest = Attribute(RuntimeType.Tokio.resolve("test").writable) + val SerdeSerialize = Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "\"serde-serialize\"")), derive(RuntimeType.SerdeSerialize))) + val SerdeDeserialize = Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "\"serde-deserialize\"")), derive(RuntimeType.SerdeDeserialize))) /** * [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute) @@ -506,6 +498,7 @@ class Attribute(val inner: Writable) { } fun all(vararg attrMacros: Writable): Writable = macroWithArgs("all", *attrMacros) + fun cfgAttr(vararg attrMacros: Writable): Writable = macroWithArgs("cfg_attr", *attrMacros) fun allow(lints: Collection): Writable = macroWithArgs("allow", *lints.toTypedArray()) fun allow(vararg lints: String): Writable = macroWithArgs("allow", *lints) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 94837a863c..89e3c930dc 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -4,7 +4,6 @@ */ package software.amazon.smithy.rust.codegen.core.smithy.generators - import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model @@ -27,6 +26,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.documentShape import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustInline import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock @@ -206,11 +206,12 @@ class BuilderGenerator( } private fun renderBuilder(writer: RustWriter) { + writer.docs("This is the datatype that Builder of this module build itself into.") + writer.rustInline("pub type OutputShape = #T;", structureSymbol) writer.docs("A builder for #D.", structureSymbol) Attribute(derive(builderDerives)).render(writer) - writer.docs("This is the datatype that Builder of this module build itself into.") - writer.rustInline("pub type OutputShape = #D", structureSymbol) - writer.writeInline(UnstableDerive.UnstableDerive) + Attribute.SerdeSerialize.render(writer) + Attribute.SerdeDeserialize.render(writer) writer.rustBlock("pub struct $builderName") { // add serde for (member in members) { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index edd1e5534d..77019fba31 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -4,7 +4,6 @@ */ package software.amazon.smithy.rust.codegen.core.smithy.generators - import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StringShape @@ -139,7 +138,8 @@ open class EnumGenerator( private fun renderUnnamedEnum() { writer.documentShape(shape, model) writer.deprecatedShape(shape) - writer.writeInline(UnstableDerive.UnstableDerive) + Attribute.SerdeSerialize.render(writer) + Attribute.SerdeDeserialize.render(writer) meta.render(writer) writer.write("struct $enumName(String);") writer.rustBlock("impl $enumName") { @@ -179,8 +179,8 @@ open class EnumGenerator( renamedWarning.ifBlank { null }, ) writer.deprecatedShape(shape) - - writer.writeInline(UnstableDerive.UnstableDerive) + Attribute.SerdeSerialize.render(writer) + Attribute.SerdeDeserialize.render(writer) meta.render(writer) writer.rustBlock("enum $enumName") { sortedMembers.forEach { member -> member.render(writer) } @@ -227,7 +227,7 @@ open class EnumGenerator( part of the enums that are public interface. """.trimIndent(), ) - writer.writeInline(UnstableDerive.UnstableDerive) + // adding serde features here adds attribute to the end of the file for some reason meta.render(this) rust("struct $UnknownVariantValue(pub(crate) String);") rustBlock("impl $UnknownVariantValue") { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 807f4ed1c7..79daea8ab6 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -4,7 +4,6 @@ */ package software.amazon.smithy.rust.codegen.core.smithy.generators - import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model @@ -13,6 +12,7 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.SensitiveTrait +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -137,7 +137,7 @@ open class StructureGenerator( // todo! check if it is sensitive // if { - // writer.writeInline("This data contains sensitive information; It will be not be obscured when serialized.") + // writer.writeInline("This data contains sensitive information; It will not be obscured when serialized.") // } writer.deprecatedShape(member) memberSymbol.expectRustMetadata().render(writer) @@ -149,7 +149,8 @@ open class StructureGenerator( val containerMeta = symbol.expectRustMetadata() writer.documentShape(shape, model) writer.deprecatedShape(shape) - writer.writeInline(UnstableDerive.UnstableDerive) + Attribute.SerdeSerialize.render(writer) + Attribute.SerdeDeserialize.render(writer) containerMeta.render(writer) writer.rustBlock("struct $name ${lifetimeDeclaration()}") { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt index a84e02f4a9..9c1f4fbb06 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt @@ -4,7 +4,6 @@ */ package software.amazon.smithy.rust.codegen.core.smithy.generators - import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model @@ -62,8 +61,9 @@ class UnionGenerator( writer.documentShape(shape, model) writer.deprecatedShape(shape) + Attribute.SerdeSerialize.render(writer) + Attribute.SerdeDeserialize.render(writer) val containerMeta = unionSymbol.expectRustMetadata() - writer.writeInline(UnstableDerive.UnstableDerive) containerMeta.render(writer) renderUnion(unionSymbol) diff --git a/rust-runtime/aws-smithy-types/Cargo.toml b/rust-runtime/aws-smithy-types/Cargo.toml index 12049c3af8..f49e230428 100644 --- a/rust-runtime/aws-smithy-types/Cargo.toml +++ b/rust-runtime/aws-smithy-types/Cargo.toml @@ -32,3 +32,7 @@ rustdoc-args = ["--cfg", "docsrs"] [[bench]] name = "base64" harness = false + +[features] +serde-serialize = [] +serde-deserialize = [] From e0811b20dca0d5d0610e21c93afb2fba835e1a64 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 27 Jan 2023 16:21:28 +0000 Subject: [PATCH 21/27] this one causes null pointer exception --- .../codegen/core/smithy/generators/BuilderGenerator.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 89e3c930dc..28f47fac16 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -46,6 +46,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait +import software.amazon.smithy.rust.codegen.core.util.isEventStream import software.amazon.smithy.rust.codegen.core.util.redactIfNecessary import software.amazon.smithy.rust.codegen.core.util.toSnakeCase @@ -210,8 +211,10 @@ class BuilderGenerator( writer.rustInline("pub type OutputShape = #T;", structureSymbol) writer.docs("A builder for #D.", structureSymbol) Attribute(derive(builderDerives)).render(writer) - Attribute.SerdeSerialize.render(writer) - Attribute.SerdeDeserialize.render(writer) + if (shape.members().none { it.isEventStream(model) }) { + Attribute.SerdeSerialize.render(writer) + Attribute.SerdeDeserialize.render(writer) + } writer.rustBlock("pub struct $builderName") { // add serde for (member in members) { From a5c2eb86647d90e66732fb27cf0a9c4817e8fef1 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Mon, 30 Jan 2023 22:32:08 +0000 Subject: [PATCH 22/27] interim solution --- .../rust/codegen/core/rustlang/RustType.kt | 6 ++++-- .../smithy/generators/BuilderGenerator.kt | 6 +----- .../core/smithy/generators/EnumGenerator.kt | 6 ++---- .../smithy/generators/RenderSerdeAttribute.kt | 19 +++++++++++++++++++ .../smithy/generators/StructureGenerator.kt | 4 +--- .../core/smithy/generators/UnionGenerator.kt | 4 +--- rust-runtime/aws-smithy-types/Cargo.toml | 2 +- 7 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 9b6b97aa66..83f7543a64 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -470,8 +470,10 @@ class Attribute(val inner: Writable) { val Test = Attribute("test") val TokioTest = Attribute(RuntimeType.Tokio.resolve("test").writable) - val SerdeSerialize = Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "\"serde-serialize\"")), derive(RuntimeType.SerdeSerialize))) - val SerdeDeserialize = Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "\"serde-deserialize\"")), derive(RuntimeType.SerdeDeserialize))) + val UnstableSerdeDerive = fun(writer: RustWriter) = { + Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-serialize"), derive(RuntimeType.SerdeSerialize)))).render(writer) + Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-deserialize"), derive(RuntimeType.SerdeDeserialize)))).render(writer) + } /** * [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 28f47fac16..752b59a376 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -46,7 +46,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait -import software.amazon.smithy.rust.codegen.core.util.isEventStream import software.amazon.smithy.rust.codegen.core.util.redactIfNecessary import software.amazon.smithy.rust.codegen.core.util.toSnakeCase @@ -211,10 +210,7 @@ class BuilderGenerator( writer.rustInline("pub type OutputShape = #T;", structureSymbol) writer.docs("A builder for #D.", structureSymbol) Attribute(derive(builderDerives)).render(writer) - if (shape.members().none { it.isEventStream(model) }) { - Attribute.SerdeSerialize.render(writer) - Attribute.SerdeDeserialize.render(writer) - } + RenderSerdeAttribute.forStructureShape(writer, shape, model) writer.rustBlock("pub struct $builderName") { // add serde for (member in members) { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index 77019fba31..db6a86276d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -138,8 +138,7 @@ open class EnumGenerator( private fun renderUnnamedEnum() { writer.documentShape(shape, model) writer.deprecatedShape(shape) - Attribute.SerdeSerialize.render(writer) - Attribute.SerdeDeserialize.render(writer) + RenderSerdeAttribute.writeAttributes(writer) meta.render(writer) writer.write("struct $enumName(String);") writer.rustBlock("impl $enumName") { @@ -179,8 +178,7 @@ open class EnumGenerator( renamedWarning.ifBlank { null }, ) writer.deprecatedShape(shape) - Attribute.SerdeSerialize.render(writer) - Attribute.SerdeDeserialize.render(writer) + RenderSerdeAttribute.writeAttributes(writer) meta.render(writer) writer.rustBlock("enum $enumName") { sortedMembers.forEach { member -> member.render(writer) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt new file mode 100644 index 0000000000..e49822c7fd --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt @@ -0,0 +1,19 @@ +package software.amazon.smithy.rust.codegen.core.smithy.generators + +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.StructureShape +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.util.isEventStream + +public object RenderSerdeAttribute { + public fun forStructureShape(writer: RustWriter, shape: StructureShape, model: Model) { + if (shape.members().none { it.isEventStream(model) }) { + this.writeAttributes(writer) + } + } + + public fun writeAttributes(writer: RustWriter) { + writer.write("##[cfg_attr(aws_sdk_unstable, feature = \"serde-serialize\", serde::Serialize)]") + writer.write("##[cfg_attr(aws_sdk_unstable, feature = \"serde-deserialize\", serde::Deserialize)]") + } +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 79daea8ab6..173cb4d2f8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -12,7 +12,6 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.SensitiveTrait -import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -149,8 +148,7 @@ open class StructureGenerator( val containerMeta = symbol.expectRustMetadata() writer.documentShape(shape, model) writer.deprecatedShape(shape) - Attribute.SerdeSerialize.render(writer) - Attribute.SerdeDeserialize.render(writer) + RenderSerdeAttribute.forStructureShape(writer, shape, model) containerMeta.render(writer) writer.rustBlock("struct $name ${lifetimeDeclaration()}") { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt index 9c1f4fbb06..b0ba3b09ff 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt @@ -60,9 +60,7 @@ class UnionGenerator( fun render() { writer.documentShape(shape, model) writer.deprecatedShape(shape) - - Attribute.SerdeSerialize.render(writer) - Attribute.SerdeDeserialize.render(writer) + RenderSerdeAttribute.writeAttributes(writer) val containerMeta = unionSymbol.expectRustMetadata() containerMeta.render(writer) diff --git a/rust-runtime/aws-smithy-types/Cargo.toml b/rust-runtime/aws-smithy-types/Cargo.toml index 071957a921..7b17b55722 100644 --- a/rust-runtime/aws-smithy-types/Cargo.toml +++ b/rust-runtime/aws-smithy-types/Cargo.toml @@ -41,4 +41,4 @@ harness = false [features] serde-serialize = [] -serde-deserialize = [] \ No newline at end of file +serde-deserialize = [] From 8ceb679548e71aebf1b18263b75c35aec93846ac Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 31 Jan 2023 07:33:09 +0000 Subject: [PATCH 23/27] new push --- .../amazon/smithy/rust/codegen/core/rustlang/RustType.kt | 4 ++-- .../core/smithy/generators/RenderSerdeAttribute.kt | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 83f7543a64..9132c4e44f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -471,8 +471,8 @@ class Attribute(val inner: Writable) { val Test = Attribute("test") val TokioTest = Attribute(RuntimeType.Tokio.resolve("test").writable) val UnstableSerdeDerive = fun(writer: RustWriter) = { - Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-serialize"), derive(RuntimeType.SerdeSerialize)))).render(writer) - Attribute(cfgAttr(all(writable("aws_sdk_unstable"), pair("feature" to "serde-deserialize"), derive(RuntimeType.SerdeDeserialize)))).render(writer) + Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-serialize"), derive(RuntimeType.SerdeSerialize)))).render(writer) + Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-deserialize"), derive(RuntimeType.SerdeDeserialize)))).render(writer) } /** diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt index e49822c7fd..11b6d34e60 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt @@ -1,7 +1,13 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StructureShape +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.util.isEventStream @@ -13,7 +19,6 @@ public object RenderSerdeAttribute { } public fun writeAttributes(writer: RustWriter) { - writer.write("##[cfg_attr(aws_sdk_unstable, feature = \"serde-serialize\", serde::Serialize)]") - writer.write("##[cfg_attr(aws_sdk_unstable, feature = \"serde-deserialize\", serde::Deserialize)]") + Attribute.UnstableSerdeDerive(writer) } } From b3fa7869ee7b9f38bf4b5ab84ffd9f6dcef0884d Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 3 Feb 2023 18:48:45 +0000 Subject: [PATCH 24/27] fix --- .../smithy/rust/codegen/core/rustlang/RustType.kt | 14 ++++++++++---- .../smithy/rust/codegen/core/smithy/RuntimeType.kt | 5 +++-- .../core/smithy/generators/RenderSerdeAttribute.kt | 5 +++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 9132c4e44f..51fd2683b8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -446,6 +446,16 @@ class Attribute(val inner: Writable) { } } + // These were supposed to be a part of companion object but we decided to move it out to here to avoid NPE + // You can find the discussion here. + // https://github.com/awslabs/smithy-rs/discussions/2248 + public fun SerdeSerialize(): Attribute { + return Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-serialize")), derive(RuntimeType.SerdeSerialize))) + } + public fun SerdeDeserialize(): Attribute { + return Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-deserialize")), derive(RuntimeType.SerdeDeserialize))) + } + companion object { val AllowClippyBoxedLocal = Attribute(allow("clippy::boxed_local")) val AllowClippyLetAndReturn = Attribute(allow("clippy::let_and_return")) @@ -470,10 +480,6 @@ class Attribute(val inner: Writable) { val Test = Attribute("test") val TokioTest = Attribute(RuntimeType.Tokio.resolve("test").writable) - val UnstableSerdeDerive = fun(writer: RustWriter) = { - Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-serialize"), derive(RuntimeType.SerdeSerialize)))).render(writer) - Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-deserialize"), derive(RuntimeType.SerdeDeserialize)))).render(writer) - } /** * [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index b2e1cc11d7..d49ae411b7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -241,8 +241,9 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null) val MaybeConstrained = RuntimeType("crate::constrained::MaybeConstrained", InlineDependency.constrained()) // serde types. Gated behind `CfgUnstable`. - val SerdeSerialize = CargoDependency.Serde.toType().resolve("Serialize") - val SerdeDeserialize = CargoDependency.Serde.toType().resolve("Deserialize") + val Serde = CargoDependency.Serde.toType() + val SerdeSerialize = Serde.resolve("Serialize") + val SerdeDeserialize = Serde.resolve("Deserialize") // smithy runtime types fun smithyAsync(runtimeConfig: RuntimeConfig) = CargoDependency.smithyAsync(runtimeConfig).toType() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt index 11b6d34e60..6d33cf24e7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt @@ -14,11 +14,12 @@ import software.amazon.smithy.rust.codegen.core.util.isEventStream public object RenderSerdeAttribute { public fun forStructureShape(writer: RustWriter, shape: StructureShape, model: Model) { if (shape.members().none { it.isEventStream(model) }) { - this.writeAttributes(writer) + writeAttributes(writer) } } public fun writeAttributes(writer: RustWriter) { - Attribute.UnstableSerdeDerive(writer) + Attribute("").SerdeSerialize().render(writer) + Attribute("").SerdeDeserialize().render(writer) } } From 9f84174716e2ba9dc2fa747d1ff30d9f8543ff54 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 3 Feb 2023 19:41:41 +0000 Subject: [PATCH 25/27] add Sensitive Warning --- .../core/smithy/generators/BuilderGenerator.kt | 3 +++ .../core/smithy/generators/EnumGenerator.kt | 2 ++ .../core/smithy/generators/SensitiveWarning.kt | 15 +++++++++++++++ .../core/smithy/generators/StructureGenerator.kt | 8 +++----- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 752b59a376..08861bcdea 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -43,6 +43,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.locatedIn import software.amazon.smithy.rust.codegen.core.smithy.makeOptional import software.amazon.smithy.rust.codegen.core.smithy.module import software.amazon.smithy.rust.codegen.core.smithy.rustType +import software.amazon.smithy.rust.codegen.core.smithy.shape import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait @@ -211,12 +212,14 @@ class BuilderGenerator( writer.docs("A builder for #D.", structureSymbol) Attribute(derive(builderDerives)).render(writer) RenderSerdeAttribute.forStructureShape(writer, shape, model) + SensitiveWarning.addDoc(writer, shape) writer.rustBlock("pub struct $builderName") { // add serde for (member in members) { val memberName = symbolProvider.toMemberName(member) // All fields in the builder are optional. val memberSymbol = symbolProvider.toSymbol(member).makeOptional() + SensitiveWarning.addDoc(writer, member) renderBuilderMember(this, memberName, memberSymbol) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index db6a86276d..d831ca00b2 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -139,6 +139,7 @@ open class EnumGenerator( writer.documentShape(shape, model) writer.deprecatedShape(shape) RenderSerdeAttribute.writeAttributes(writer) + SensitiveWarning.addDoc(writer, shape) meta.render(writer) writer.write("struct $enumName(String);") writer.rustBlock("impl $enumName") { @@ -179,6 +180,7 @@ open class EnumGenerator( ) writer.deprecatedShape(shape) RenderSerdeAttribute.writeAttributes(writer) + SensitiveWarning.addDoc(writer, shape) meta.render(writer) writer.rustBlock("enum $enumName") { sortedMembers.forEach { member -> member.render(writer) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt new file mode 100644 index 0000000000..91449025d0 --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt @@ -0,0 +1,15 @@ +package software.amazon.smithy.rust.codegen.core.smithy.generators + +import software.amazon.smithy.model.shapes.Shape +import software.amazon.smithy.model.traits.SensitiveTrait +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.util.hasTrait + +object SensitiveWarning { + private const val warningMessage = "/// This data may contain sensitive information; It will not be obscured when serialized.\n" + fun addDoc(writer: RustWriter, shape: T) { + if (shape.hasTrait()) { + writer.writeInline(warningMessage) + } + } +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 173cb4d2f8..b0c72571e3 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -133,11 +133,7 @@ open class StructureGenerator( open fun renderStructureMember(writer: RustWriter, member: MemberShape, memberName: String, memberSymbol: Symbol) { writer.renderMemberDoc(member, memberSymbol) - - // todo! check if it is sensitive - // if { - // writer.writeInline("This data contains sensitive information; It will not be obscured when serialized.") - // } + SensitiveWarning.addDoc(writer, shape) writer.deprecatedShape(member) memberSymbol.expectRustMetadata().render(writer) writer.write("$memberName: #T,", memberSymbol) @@ -149,10 +145,12 @@ open class StructureGenerator( writer.documentShape(shape, model) writer.deprecatedShape(shape) RenderSerdeAttribute.forStructureShape(writer, shape, model) + SensitiveWarning.addDoc(writer, shape) containerMeta.render(writer) writer.rustBlock("struct $name ${lifetimeDeclaration()}") { writer.forEachMember(members) { member, memberName, memberSymbol -> + SensitiveWarning.addDoc(writer, shape) renderStructureMember(writer, member, memberName, memberSymbol) } } From a5970c0a454e8b8214608620f23e161b28757683 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 3 Feb 2023 20:24:30 +0000 Subject: [PATCH 26/27] add test for CargoTomlGeneratorTest pre-commit fix --- .../smithy/generators/SensitiveWarning.kt | 5 ++++ .../generators/CargoTomlGeneratorTest.kt | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt index 91449025d0..59483329b8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/SensitiveWarning.kt @@ -1,3 +1,8 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.model.shapes.Shape diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt index c57ebdc727..f9b1e210ca 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt @@ -42,4 +42,32 @@ class CargoTomlGeneratorTest { } project.compileAndTest() } + + @Test + fun `check serde features`() { + val project = TestWorkspace.testProject() + /* + ["target.'cfg(aws_sdk_unstable)'.dependencies".serde] + version = "1.0" + features = ["derive"] + serde-serialize = ["aws-smithy-types/serde-serialize"] + serde-deserialize = ["aws-smithy-types/serde-deserialize"] + */ + project.lib { + addDependency(CargoMetadata) + unitTest( + "smithy_codegen_serde_features", + """ + let metadata = cargo_metadata::MetadataCommand::new() + .exec() + .expect("could not run `cargo metadata`"); + + let features = &metadata.root_package().expect("missing root package").features; + + assert_eq!(features.get("aws-aws-smithy-types"), Some(vec!["serde-serialize", "serde-deserialize"])); + """, + ) + } + project.compileAndTest() + } } From 4e8a72ced4baa48b6582979de47307d3b2ba4e20 Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Sat, 18 Feb 2023 13:22:01 +0900 Subject: [PATCH 27/27] Update codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt Co-authored-by: Zelda Hessler --- .../rust/codegen/core/smithy/generators/BuilderGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 08861bcdea..ad7fe27b60 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -207,7 +207,7 @@ class BuilderGenerator( } private fun renderBuilder(writer: RustWriter) { - writer.docs("This is the datatype that Builder of this module build itself into.") + writer.docs("This is the datatype returned when calling `Builder::build()`.") writer.rustInline("pub type OutputShape = #T;", structureSymbol) writer.docs("A builder for #D.", structureSymbol) Attribute(derive(builderDerives)).render(writer)