diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 71743b31a1..b834b8c2b8 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -33,4 +33,10 @@ author = "jdisanti" message = "Streaming operations now emit the request ID at the `debug` log level like their non-streaming counterparts." references = ["smithy-rs#2495"] meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"} -author = "jdisanti" \ No newline at end of file +author = "jdisanti" + +[[smithy-rs]] +message = "The `enableNewCrateOrganizationScheme` codegen flag has been removed. If you opted out of the new crate organization scheme, it must be adopted now in order to upgrade (see [the upgrade guidance](https://github.com/awslabs/smithy-rs/discussions/2449) from March 23rd's release)." +references = ["smithy-rs#2507"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" } +author = "jdisanti" diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt index 1c3ceed72e..5fbe721e1e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt @@ -9,7 +9,6 @@ import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedCustomizeModule import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDocs import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator @@ -97,12 +96,12 @@ class AwsFluentClientDecorator : ClientCodegenDecorator { reexportSmithyClientBuilder = false, generics = generics, customizations = listOf( - AwsPresignedFluentBuilderMethod(codegenContext, runtimeConfig), + AwsPresignedFluentBuilderMethod(runtimeConfig), AwsFluentClientDocs(codegenContext), ), retryClassifier = AwsRuntimeType.awsHttp(runtimeConfig).resolve("retry::AwsResponseRetryClassifier"), ).render(rustCrate) - rustCrate.withModule(codegenContext.featureGatedCustomizeModule()) { + rustCrate.withModule(ClientRustModule.Client.customize) { renderCustomizableOperationSendMethod(runtimeConfig, generics, this) } rustCrate.withModule(ClientRustModule.client) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt index 7e359f40e3..20d280ddf9 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt @@ -42,6 +42,11 @@ import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware import software.amazon.smithy.rustsdk.traits.PresignableTrait import kotlin.streams.toList +private val presigningTypes: List> = listOf( + "PresignedRequest" to AwsRuntimeType.presigning().resolve("PresignedRequest"), + "PresigningConfig" to AwsRuntimeType.presigning().resolve("PresigningConfig"), +) + internal enum class PayloadSigningType { EMPTY, UNSIGNED_PAYLOAD, @@ -135,8 +140,8 @@ class AwsInputPresignedMethod( private val symbolProvider = codegenContext.symbolProvider private val codegenScope = ( - presigningTypes(codegenContext) + listOf( - "PresignedRequestService" to AwsRuntimeType.presigning(codegenContext) + presigningTypes + listOf( + "PresignedRequestService" to AwsRuntimeType.presigning() .resolve("service::PresignedRequestService"), "SdkError" to RuntimeType.sdkError(runtimeConfig), "aws_sigv4" to AwsRuntimeType.awsSigv4(runtimeConfig), @@ -241,12 +246,11 @@ class AwsInputPresignedMethod( } class AwsPresignedFluentBuilderMethod( - codegenContext: ClientCodegenContext, runtimeConfig: RuntimeConfig, ) : FluentClientCustomization() { private val codegenScope = ( - presigningTypes(codegenContext) + arrayOf( - "Error" to AwsRuntimeType.presigning(codegenContext).resolve("config::Error"), + presigningTypes + arrayOf( + "Error" to AwsRuntimeType.presigning().resolve("config::Error"), "SdkError" to RuntimeType.sdkError(runtimeConfig), ) ).toTypedArray() @@ -365,15 +369,3 @@ private fun RustWriter.documentPresignedMethod(hasConfigArg: Boolean) { """, ) } - -private fun presigningTypes(codegenContext: ClientCodegenContext): List> = - when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> listOf( - "PresignedRequest" to AwsRuntimeType.presigning(codegenContext).resolve("PresignedRequest"), - "PresigningConfig" to AwsRuntimeType.presigning(codegenContext).resolve("PresigningConfig"), - ) - else -> listOf( - "PresignedRequest" to AwsRuntimeType.presigning(codegenContext).resolve("request::PresignedRequest"), - "PresigningConfig" to AwsRuntimeType.presigning(codegenContext).resolve("config::PresigningConfig"), - ) - } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeType.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeType.kt index e07607a722..60bf14f9ea 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeType.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeType.kt @@ -6,7 +6,6 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.codegen.core.CodegenException -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig @@ -42,17 +41,8 @@ fun RuntimeConfig.awsRoot(): RuntimeCrateLocation { } object AwsRuntimeType { - fun presigning(codegenContext: ClientCodegenContext): RuntimeType = - when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("presigning", visibility = Visibility.PUBLIC)) - else -> RuntimeType.forInlineDependency( - InlineAwsDependency.forRustFileAs( - file = "old_presigning", - moduleName = "presigning", - visibility = Visibility.PUBLIC, - ), - ) - } + fun presigning(): RuntimeType = + RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("presigning", visibility = Visibility.PUBLIC)) fun RuntimeConfig.defaultMiddleware() = RuntimeType.forInlineDependency( InlineAwsDependency.forRustFile( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/BaseRequestIdDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/BaseRequestIdDecorator.kt index 80a66b7989..e1f08ebb05 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/BaseRequestIdDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/BaseRequestIdDecorator.kt @@ -66,12 +66,7 @@ abstract class BaseRequestIdDecorator : ClientCodegenDecorator { ): List = baseCustomizations + listOf(RequestIdBuilderCustomization()) override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { - rustCrate.withModule( - when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> ClientRustModule.Operation - else -> ClientRustModule.types - }, - ) { + rustCrate.withModule(ClientRustModule.Operation) { // Re-export RequestId in generated crate rust("pub use #T;", accessorTrait(codegenContext)) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt index 30e15a0ca9..8b2e65a4b3 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt @@ -6,9 +6,9 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.TestUtilFeature -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedConfigModule import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -41,7 +41,7 @@ class CredentialsProviderDecorator : ClientCodegenDecorator { override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { rustCrate.mergeFeature(TestUtilFeature.copy(deps = listOf("aws-credential-types/test-util"))) - rustCrate.withModule(codegenContext.featureGatedConfigModule()) { + rustCrate.withModule(ClientRustModule.Config) { rust( "pub use #T::Credentials;", AwsRuntimeType.awsCredentialTypes(codegenContext.runtimeConfig), diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt index af625e7979..bf116c9269 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt @@ -10,9 +10,9 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rulesengine.language.syntax.parameters.Builtins import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointCustomization -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedConfigModule import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -116,7 +116,7 @@ class RegionDecorator : ClientCodegenDecorator { override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { if (usesRegion(codegenContext)) { - rustCrate.withModule(codegenContext.featureGatedConfigModule()) { + rustCrate.withModule(ClientRustModule.Config) { rust("pub use #T::Region;", region(codegenContext.runtimeConfig)) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt index 0fa2c5f66b..38ff9f1324 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt @@ -8,9 +8,8 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.aws.traits.ServiceTrait import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedConfigModule -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedMetaModule import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -67,18 +66,18 @@ class UserAgentDecorator : ClientCodegenDecorator { val serviceTrait = codegenContext.serviceShape.expectTrait() val serviceId = serviceTrait.sdkId.lowercase().replace(" ", "") - rustCrate.withModule(codegenContext.featureGatedMetaModule()) { + rustCrate.withModule(ClientRustModule.Meta) { rustTemplate( """ pub(crate) static API_METADATA: #{user_agent}::ApiMetadata = #{user_agent}::ApiMetadata::new(${serviceId.dq()}, #{PKG_VERSION}); """, "user_agent" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent"), - "PKG_VERSION" to CrateVersionCustomization.pkgVersion(codegenContext.featureGatedMetaModule()), + "PKG_VERSION" to CrateVersionCustomization.pkgVersion(ClientRustModule.Meta), ) } - rustCrate.withModule(codegenContext.featureGatedConfigModule()) { + rustCrate.withModule(ClientRustModule.Config) { // Re-export the app name so that it can be specified in config programmatically without an explicit dependency rustTemplate( "pub use #{AppName};", @@ -105,7 +104,7 @@ class UserAgentDecorator : ClientCodegenDecorator { } ${section.request}.properties_mut().insert(user_agent); """, - "meta" to codegenContext.featureGatedMetaModule(), + "meta" to ClientRustModule.Meta, "ua_module" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent"), "Env" to AwsRuntimeType.awsTypes(runtimeConfig).resolve("os_shim_internal::Env"), ) diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt index f24dd88408..fc40eec7cd 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt @@ -58,7 +58,6 @@ fun awsSdkIntegrationTest( "codegen", ObjectNode.builder() .withMember("includeFluentClient", false) - .withMember("enableNewCrateOrganizationScheme", true) .build(), ).build(), ), diff --git a/buildSrc/src/main/kotlin/CodegenTestCommon.kt b/buildSrc/src/main/kotlin/CodegenTestCommon.kt index ad02ea63af..2173c237a6 100644 --- a/buildSrc/src/main/kotlin/CodegenTestCommon.kt +++ b/buildSrc/src/main/kotlin/CodegenTestCommon.kt @@ -38,7 +38,6 @@ private fun generateSmithyBuild(projectDir: String, pluginName: String, tests: L "relativePath": "$projectDir/rust-runtime" }, "codegen": { - "enableNewCrateOrganizationScheme": true }, "service": "${it.service}", "module": "${it.module}", diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt index 5a97b1ede5..1a76810066 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt @@ -6,7 +6,6 @@ package software.amazon.smithy.rust.codegen.client.smithy import software.amazon.smithy.build.PluginContext -import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.shapes.OperationShape @@ -41,7 +40,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.contextName import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.core.smithy.module import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer @@ -79,16 +77,8 @@ class ClientCodegenVisitor( runtimeConfig = settings.runtimeConfig, renameExceptions = settings.codegenConfig.renameExceptions, nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, - moduleProvider = when (settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> ClientModuleProvider - else -> OldModuleSchemeClientModuleProvider - }, - nameBuilderFor = { symbol -> - when (settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> "${symbol.name}Builder" - else -> "Builder" - } - }, + moduleProvider = ClientModuleProvider, + nameBuilderFor = { symbol -> "${symbol.name}Builder" }, ) val baseModel = baselineTransform(context.model) val untransformedService = settings.getService(baseModel) @@ -207,19 +197,6 @@ class ClientCodegenVisitor( override fun getDefault(shape: Shape?) { } - // TODO(CrateReorganization): Remove this function when cleaning up `enableNewCrateOrganizationScheme` - private fun RustCrate.maybeInPrivateModuleWithReexport( - privateModule: RustModule.LeafModule, - symbol: Symbol, - writer: Writable, - ) { - if (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - inPrivateModuleWithReexport(privateModule, symbol, writer) - } else { - withModule(symbol.module(), writer) - } - } - private fun privateModule(shape: Shape): RustModule.LeafModule = RustModule.private(privateModuleName(shape), parent = symbolProvider.moduleForShape(shape)) @@ -278,10 +255,10 @@ class ClientCodegenVisitor( } val privateModule = privateModule(shape) - rustCrate.maybeInPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) { + rustCrate.inPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) { renderStruct(this) } - rustCrate.maybeInPrivateModuleWithReexport(privateModule, symbolProvider.symbolForBuilder(shape)) { + rustCrate.inPrivateModuleWithReexport(privateModule, symbolProvider.symbolForBuilder(shape)) { renderBuilder(this) } } @@ -294,7 +271,7 @@ class ClientCodegenVisitor( override fun stringShape(shape: StringShape) { if (shape.hasTrait()) { val privateModule = privateModule(shape) - rustCrate.maybeInPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) { + rustCrate.inPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) { ClientEnumGenerator(codegenContext, shape).render(this) } } @@ -308,7 +285,7 @@ class ClientCodegenVisitor( * Note: this does not generate serializers */ override fun unionShape(shape: UnionShape) { - rustCrate.maybeInPrivateModuleWithReexport(privateModule(shape), symbolProvider.toSymbol(shape)) { + rustCrate.inPrivateModuleWithReexport(privateModule(shape), symbolProvider.toSymbol(shape)) { UnionGenerator(model, symbolProvider, this, shape, renderUnknownVariant = true).render() } if (shape.isEventStream()) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustModule.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustModule.kt index 69b7212236..aa1f547dc4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustModule.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustModule.kt @@ -18,7 +18,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.EscapeFor import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords -import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.docs import software.amazon.smithy.rust.codegen.core.rustlang.docsTemplate @@ -27,7 +26,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.ModuleDocProvider import software.amazon.smithy.rust.codegen.core.smithy.ModuleProvider import software.amazon.smithy.rust.codegen.core.smithy.ModuleProviderContext -import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.contextName import software.amazon.smithy.rust.codegen.core.smithy.module import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait @@ -73,55 +71,28 @@ object ClientRustModule { /** crate::types::error */ val Error = RustModule.public("error", parent = self) } - - // TODO(CrateReorganization): Remove this module when cleaning up `enableNewCrateOrganizationScheme` - val Model = RustModule.public("model") } class ClientModuleDocProvider( private val codegenContext: ClientCodegenContext, private val serviceName: String, ) : ModuleDocProvider { - private val config: ClientCodegenConfig = codegenContext.settings.codegenConfig - override fun docsWriter(module: RustModule.LeafModule): Writable? { val strDoc: (String) -> Writable = { str -> writable { docs(escape(str)) } } - return when (config.enableNewCrateOrganizationScheme) { - true -> when (module) { - ClientRustModule.client -> clientModuleDoc() - ClientRustModule.Client.customize -> customizeModuleDoc() - ClientRustModule.Config -> strDoc("Configuration for $serviceName.") - ClientRustModule.Error -> strDoc("Common errors and error handling utilities.") - ClientRustModule.Endpoint -> strDoc("Endpoint resolution functionality.") - ClientRustModule.Operation -> strDoc("All operations that this crate can perform.") - ClientRustModule.Meta -> strDoc("Information about this crate.") - ClientRustModule.Input -> PANIC("this module shouldn't exist in the new scheme") - ClientRustModule.Output -> PANIC("this module shouldn't exist in the new scheme") - ClientRustModule.Primitives -> strDoc("Primitives such as `Blob` or `DateTime` used by other types.") - ClientRustModule.types -> strDoc("Data structures used by operation inputs/outputs.") - ClientRustModule.Types.Error -> strDoc("Error types that $serviceName can respond with.") - ClientRustModule.Model -> PANIC("this module shouldn't exist in the new scheme") - else -> TODO("Document this module: $module") - } - - else -> strDoc( - when (module) { - ClientRustModule.client -> "Client and fluent builders for calling $serviceName." - ClientRustModule.Client.customize -> "Operation customization and supporting types." - ClientRustModule.Config -> "Configuration for $serviceName." - ClientRustModule.Error -> "All error types that operations can return. Documentation on these types is copied from the model." - ClientRustModule.Endpoint -> "Endpoint resolution functionality." - ClientRustModule.Operation -> "All operations that this crate can perform." - ClientRustModule.Meta -> PANIC("this module shouldn't exist in the old scheme") - ClientRustModule.Input -> "Input structures for operations. Documentation on these types is copied from the model." - ClientRustModule.Output -> "Output structures for operations. Documentation on these types is copied from the model." - ClientRustModule.Primitives -> PANIC("this module shouldn't exist in the old scheme") - ClientRustModule.types -> "Data primitives referenced by other data types." - ClientRustModule.Types.Error -> PANIC("this module shouldn't exist in the old scheme") - ClientRustModule.Model -> "Data structures used by operation inputs/outputs." - else -> TODO("Document this module: $module") - }, - ) + return when (module) { + ClientRustModule.client -> clientModuleDoc() + ClientRustModule.Client.customize -> customizeModuleDoc() + ClientRustModule.Config -> strDoc("Configuration for $serviceName.") + ClientRustModule.Error -> strDoc("Common errors and error handling utilities.") + ClientRustModule.Endpoint -> strDoc("Endpoint resolution functionality.") + ClientRustModule.Operation -> strDoc("All operations that this crate can perform.") + ClientRustModule.Meta -> strDoc("Information about this crate.") + ClientRustModule.Input -> PANIC("this module shouldn't exist in the new scheme") + ClientRustModule.Output -> PANIC("this module shouldn't exist in the new scheme") + ClientRustModule.Primitives -> strDoc("Primitives such as `Blob` or `DateTime` used by other types.") + ClientRustModule.types -> strDoc("Data structures used by operation inputs/outputs.") + ClientRustModule.Types.Error -> strDoc("Error types that $serviceName can respond with.") + else -> TODO("Document this module: $module") } } @@ -226,78 +197,3 @@ object ClientModuleProvider : ModuleProvider { ) } } - -// TODO(CrateReorganization): Remove this provider -object OldModuleSchemeClientModuleProvider : ModuleProvider { - override fun moduleForShape(context: ModuleProviderContext, shape: Shape): RustModule.LeafModule = when (shape) { - is OperationShape -> ClientRustModule.Operation - is StructureShape -> when { - shape.hasTrait() -> ClientRustModule.Error - shape.hasTrait() -> ClientRustModule.Input - shape.hasTrait() -> ClientRustModule.Output - else -> ClientRustModule.Model - } - - else -> ClientRustModule.Model - } - - override fun moduleForOperationError( - context: ModuleProviderContext, - operation: OperationShape, - ): RustModule.LeafModule = ClientRustModule.Error - - override fun moduleForEventStreamError( - context: ModuleProviderContext, - eventStream: UnionShape, - ): RustModule.LeafModule = ClientRustModule.Error - - override fun moduleForBuilder(context: ModuleProviderContext, shape: Shape, symbol: Symbol): RustModule.LeafModule { - val builderNamespace = RustReservedWords.escapeIfNeeded(symbol.name.toSnakeCase()) - return RustModule.new( - builderNamespace, - visibility = Visibility.PUBLIC, - parent = symbol.module(), - inline = true, - documentationOverride = "See [`${symbol.name}`](${symbol.module().fullyQualifiedPath()}::${symbol.name}).", - ) - } -} - -// TODO(CrateReorganization): Remove when cleaning up `enableNewCrateOrganizationScheme` -fun ClientCodegenContext.featureGatedConfigModule() = when (settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> ClientRustModule.Config - else -> ClientRustModule.root -} - -// TODO(CrateReorganization): Remove when cleaning up `enableNewCrateOrganizationScheme` -fun ClientCodegenContext.featureGatedCustomizeModule() = when (settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> ClientRustModule.Client.customize - else -> RustModule.public( - "customize", - parent = ClientRustModule.Operation, - documentationOverride = "Operation customization and supporting types", - ) -} - -// TODO(CrateReorganization): Remove when cleaning up `enableNewCrateOrganizationScheme` -fun ClientCodegenContext.featureGatedMetaModule() = when (settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> ClientRustModule.Meta - else -> ClientRustModule.root -} - -// TODO(CrateReorganization): Remove when cleaning up `enableNewCrateOrganizationScheme` -fun ClientCodegenContext.featureGatedPaginatorModule(symbolProvider: RustSymbolProvider, operation: OperationShape) = - when (settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> RustModule.public( - "paginator", - parent = symbolProvider.moduleForShape(operation), - documentationOverride = "Paginator for this operation", - ) - else -> RustModule.public("paginator", documentationOverride = "Paginators for the service") - } - -// TODO(CrateReorganization): Remove when cleaning up `enableNewCrateOrganizationScheme` -fun ClientCodegenContext.featureGatedPrimitivesModule() = when (settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> ClientRustModule.Primitives - else -> ClientRustModule.types -} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt index dad5bf9d37..e6680d3e0e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt @@ -86,8 +86,6 @@ data class ClientCodegenConfig( val addMessageToErrors: Boolean = defaultAddMessageToErrors, // TODO(EventStream): [CLEANUP] Remove this property when turning on Event Stream for all services val eventStreamAllowList: Set = defaultEventStreamAllowList, - // TODO(CrateReorganization): Remove this once we commit to the breaking change - val enableNewCrateOrganizationScheme: Boolean = defaultEnableNewCrateOrganizationScheme, // TODO(SmithyRuntime): Remove this once we commit to switch to aws-smithy-runtime and aws-smithy-runtime-api val enableNewSmithyRuntime: Boolean = defaultEnableNewSmithyRuntime, ) : CoreCodegenConfig( @@ -98,7 +96,6 @@ data class ClientCodegenConfig( private const val defaultIncludeFluentClient = true private const val defaultAddMessageToErrors = true private val defaultEventStreamAllowList: Set = emptySet() - private const val defaultEnableNewCrateOrganizationScheme = true private const val defaultEnableNewSmithyRuntime = false fun fromCodegenConfigAndNode(coreCodegenConfig: CoreCodegenConfig, node: Optional) = @@ -112,7 +109,6 @@ data class ClientCodegenConfig( renameExceptions = node.get().getBooleanMemberOrDefault("renameErrors", defaultRenameExceptions), includeFluentClient = node.get().getBooleanMemberOrDefault("includeFluentClient", defaultIncludeFluentClient), addMessageToErrors = node.get().getBooleanMemberOrDefault("addMessageToErrors", defaultAddMessageToErrors), - enableNewCrateOrganizationScheme = node.get().getBooleanMemberOrDefault("enableNewCrateOrganizationScheme", defaultEnableNewCrateOrganizationScheme), enableNewSmithyRuntime = node.get().getBooleanMemberOrDefault("enableNewSmithyRuntime", defaultEnableNewSmithyRuntime), ) } else { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt index c5bccd08c3..22dd4e9919 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt @@ -19,10 +19,7 @@ class ClientDocsGenerator(private val codegenContext: ClientCodegenContext) : Li override fun section(section: LibRsSection): Writable { return when (section) { is LibRsSection.ModuleDoc -> if (section.subsection is ModuleDocSection.CrateOrganization) { - when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> crateLayout() - else -> oldCrateLayout() - } + crateLayout() } else { emptySection } @@ -55,24 +52,6 @@ class ClientDocsGenerator(private val codegenContext: ClientCodegenContext) : Li client can return. Any other error type can be converted to this `Error` type via the [`From`](std::convert::From) trait. - The other modules within this crate are not required for normal usage. - """.trimEnd(), - ) - } - - // TODO(CrateReorganization): Delete this function when removing `enableNewCrateOrganizationScheme` - private fun oldCrateLayout(): Writable = - writable { - containerDocs( - """ - The entry point for most customers will be [`Client`]. [`Client`] exposes one method for each API offered - by the service. - - Some APIs require complex or nested arguments. These exist in [`model`](crate::model). - - Lastly, errors that can be returned by the service are contained within [`error`]. [`Error`] defines a meta - error encompassing all possible errors that can be returned by the service. - The other modules within this crate are not required for normal usage. """.trimEnd(), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt index c88af4c2bd..4dad5c716c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt @@ -14,8 +14,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpVers 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.featureGatedMetaModule -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedPrimitivesModule import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.core.rustlang.Feature import software.amazon.smithy.rust.codegen.core.smithy.RustCrate @@ -69,19 +67,14 @@ class RequiredCustomizations : ClientCodegenDecorator { // Re-export resiliency types ResiliencyReExportCustomization(codegenContext.runtimeConfig).extras(rustCrate) - rustCrate.withModule(codegenContext.featureGatedPrimitivesModule()) { + rustCrate.withModule(ClientRustModule.Primitives) { pubUseSmithyPrimitives(codegenContext, codegenContext.model)(this) - if (!codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - pubUseSmithyErrorTypes(codegenContext)(this) - } } - if (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - rustCrate.withModule(ClientRustModule.Error) { - pubUseSmithyErrorTypes(codegenContext)(this) - } + rustCrate.withModule(ClientRustModule.Error) { + pubUseSmithyErrorTypes(codegenContext)(this) } - codegenContext.featureGatedMetaModule().also { metaModule -> + ClientRustModule.Meta.also { metaModule -> rustCrate.withModule(metaModule) { CrateVersionCustomization.extras(rustCrate, metaModule) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientEnumGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientEnumGenerator.kt index a217b0f5f0..d1b87591cb 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientEnumGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientEnumGenerator.kt @@ -7,7 +7,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedPrimitivesModule +import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -172,5 +172,5 @@ class ClientEnumGenerator(codegenContext: ClientCodegenContext, shape: StringSha codegenContext.model, codegenContext.symbolProvider, shape, - InfallibleEnumType(codegenContext.featureGatedPrimitivesModule()), + InfallibleEnumType(ClientRustModule.Primitives), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index b34163b51e..a20a33ecb0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -11,8 +11,8 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.IdempotencyTokenTrait import software.amazon.smithy.model.traits.PaginatedTrait import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedPaginatorModule import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.render @@ -68,7 +68,11 @@ class PaginatorGenerator private constructor( private val idx = PaginatedIndex.of(model) private val paginationInfo = idx.getPaginationInfo(codegenContext.serviceShape, operation).orNull() ?: PANIC("failed to load pagination info") - private val module = codegenContext.featureGatedPaginatorModule(symbolProvider, operation) + private val module = RustModule.public( + "paginator", + parent = symbolProvider.moduleForShape(operation), + documentationOverride = "Paginator for this operation", + ) private val inputType = symbolProvider.toSymbol(operation.inputShape(model)) private val outputShape = operation.outputShape(model) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index 31ca1eae9f..ed24d439b7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -6,7 +6,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.client import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedCustomizeModule +import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics @@ -29,7 +29,7 @@ class CustomizableOperationGenerator( private val smithyTypes = CargoDependency.smithyTypes(runtimeConfig).toType() fun render(crate: RustCrate) { - crate.withModule(codegenContext.featureGatedCustomizeModule()) { + crate.withModule(ClientRustModule.Client.customize) { rustTemplate( """ pub use #{Operation}; @@ -66,7 +66,7 @@ class CustomizableOperationGenerator( "handle_generics_bounds" to handleGenerics.bounds(), "operation_generics_decl" to operationGenerics.declaration(), "combined_generics_decl" to combinedGenerics.declaration(), - "customize_module" to codegenContext.featureGatedCustomizeModule(), + "customize_module" to ClientRustModule.Client.customize, ) writer.rustTemplate( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt index ac2b15dc70..b0950583d5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt @@ -14,7 +14,6 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.DocumentationTrait import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule -import software.amazon.smithy.rust.codegen.client.smithy.featureGatedCustomizeModule import software.amazon.smithy.rust.codegen.client.smithy.generators.PaginatorGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.isPaginated import software.amazon.smithy.rust.codegen.core.rustlang.Attribute @@ -85,7 +84,7 @@ class FluentClientGenerator( renderFluentClient(crate) operations.forEach { operation -> - crate.withModule(operation.fluentBuilderModule(codegenContext, symbolProvider)) { + crate.withModule(symbolProvider.moduleForBuilder(operation)) { renderFluentBuilder(operation) } } @@ -95,7 +94,7 @@ class FluentClientGenerator( private fun renderFluentClient(crate: RustCrate) { crate.withModule(ClientRustModule.client) { - if (!codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme || reexportSmithyClientBuilder) { + if (reexportSmithyClientBuilder) { rustTemplate( """ ##[doc(inline)] @@ -175,7 +174,7 @@ class FluentClientGenerator( "client" to RuntimeType.smithyClient(runtimeConfig), "bounds" to generics.bounds, ) { - val fullPath = operation.fullyQualifiedFluentBuilder(codegenContext, symbolProvider) + val fullPath = operation.fullyQualifiedFluentBuilder(symbolProvider) val maybePaginated = if (operation.isPaginated(model)) { "\n/// This operation supports pagination; See [`into_paginator()`]($fullPath::into_paginator)." } else { @@ -186,13 +185,8 @@ class FluentClientGenerator( val operationOk = symbolProvider.toSymbol(output) val operationErr = symbolProvider.symbolForOperationError(operation) - val inputFieldsBody = generateOperationShapeDocs( - this, - codegenContext, - symbolProvider, - operation, - model, - ).joinToString("\n") { "/// - $it" } + val inputFieldsBody = generateOperationShapeDocs(this, symbolProvider, operation, model) + .joinToString("\n") { "/// - $it" } val inputFieldsHead = if (inputFieldsBody.isNotEmpty()) { "The fluent builder is configurable:\n" @@ -229,7 +223,7 @@ class FluentClientGenerator( #{FluentBuilder}::new(self.handle.clone()) } """, - "FluentBuilder" to operation.fluentBuilderType(codegenContext, symbolProvider), + "FluentBuilder" to operation.fluentBuilderType(symbolProvider), ) } } @@ -244,7 +238,7 @@ class FluentClientGenerator( val derives = baseDerives.filter { it == RuntimeType.Clone } + RuntimeType.Debug docs("Fluent builder constructing a request to `${operationSymbol.name}`.\n") - val builderName = operation.fluentBuilderType(codegenContext, symbolProvider).name + val builderName = operation.fluentBuilderType(symbolProvider).name documentShape(operation, model, autoSuppressMissingDocs = false) deprecatedShape(operation) Attribute(derive(derives.toSet())).render(this) @@ -308,7 +302,7 @@ class FluentClientGenerator( self.handle.client.call(op).await } """, - "CustomizableOperation" to codegenContext.featureGatedCustomizeModule().toType() + "CustomizableOperation" to ClientRustModule.Client.customize.toType() .resolve("CustomizableOperation"), "ClassifyRetry" to RuntimeType.classifyRetry(runtimeConfig), "OperationError" to errorType, @@ -369,13 +363,12 @@ class FluentClientGenerator( */ private fun generateOperationShapeDocs( writer: RustWriter, - codegenContext: ClientCodegenContext, symbolProvider: RustSymbolProvider, operation: OperationShape, model: Model, ): List { val input = operation.inputShape(model) - val fluentBuilderFullyQualifiedName = operation.fullyQualifiedFluentBuilder(codegenContext, symbolProvider) + val fluentBuilderFullyQualifiedName = operation.fullyQualifiedFluentBuilder(symbolProvider) return input.members().map { memberShape -> val builderInputDoc = memberShape.asFluentBuilderInputDoc(symbolProvider) val builderInputLink = docLink("$fluentBuilderFullyQualifiedName::${symbolProvider.toMemberName(memberShape)}") @@ -418,35 +411,9 @@ private fun generateShapeMemberDocs( } } -private fun OperationShape.fluentBuilderModule( - codegenContext: ClientCodegenContext, - symbolProvider: RustSymbolProvider, -) = when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> symbolProvider.moduleForBuilder(this) - else -> RustModule.public( - "fluent_builders", - parent = ClientRustModule.client, - documentationOverride = """ - Utilities to ergonomically construct a request to the service. - - Fluent builders are created through the [`Client`](crate::client::Client) by calling - one if its operation methods. After parameters are set using the builder methods, - the `send` method can be called to initiate the request. - """.trimIndent(), - ) -} - -internal fun OperationShape.fluentBuilderType( - codegenContext: ClientCodegenContext, - symbolProvider: RustSymbolProvider, -): RuntimeType = fluentBuilderModule(codegenContext, symbolProvider).toType() - .resolve( - symbolProvider.toSymbol(this).name + - when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> "FluentBuilder" - else -> "" - }, - ) +internal fun OperationShape.fluentBuilderType(symbolProvider: RustSymbolProvider): RuntimeType = + symbolProvider.moduleForBuilder(this).toType() + .resolve(symbolProvider.toSymbol(this).name + "FluentBuilder") /** * Generate a valid fully-qualified Type for a fluent builder e.g. @@ -455,9 +422,8 @@ internal fun OperationShape.fluentBuilderType( * * _NOTE: This function generates the links that appear under **"The fluent builder is configurable:"**_ */ private fun OperationShape.fullyQualifiedFluentBuilder( - codegenContext: ClientCodegenContext, symbolProvider: RustSymbolProvider, -): String = fluentBuilderType(codegenContext, symbolProvider).fullyQualifiedName() +): String = fluentBuilderType(symbolProvider).fullyQualifiedName() /** * Generate a string that looks like a Rust function pointer for documenting a fluent builder method e.g. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt index 0f53289615..52016f877f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt @@ -6,10 +6,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.protocol import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.client.fluentBuilderType import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBoundProtocolTraitImplGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.derive @@ -17,18 +14,16 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.implBlock 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.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations -import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.util.inputShape open class ClientProtocolGenerator( - private val codegenContext: ClientCodegenContext, + codegenContext: ClientCodegenContext, private val protocol: Protocol, /** * Operations generate a `make_operation(&config)` method to build a `aws_smithy_http::Operation` that can be dispatched @@ -62,10 +57,7 @@ open class ClientProtocolGenerator( makeOperationGenerator.generateMakeOperation(this, operationShape, customizations) } - when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { - true -> renderOperationStruct(operationWriter, operationShape, customizations) - else -> oldRenderOperationStruct(operationWriter, operationShape, inputShape, customizations) - } + renderOperationStruct(operationWriter, operationShape, customizations) } private fun renderOperationStruct( @@ -95,43 +87,4 @@ open class ClientProtocolGenerator( } traitGenerator.generateTraitImpls(operationWriter, operationShape, customizations) } - - // TODO(CrateReorganization): Remove this function when removing `enableNewCrateOrganizationScheme` - private fun oldRenderOperationStruct( - operationWriter: RustWriter, - operationShape: OperationShape, - inputShape: StructureShape, - customizations: List, - ) { - val operationName = symbolProvider.toSymbol(operationShape).name - - // pub struct Operation { ... } - val fluentBuilderName = FluentClientGenerator.clientOperationFnName(operationShape, symbolProvider) - operationWriter.rustTemplate( - """ - /// Operation shape for `$operationName`. - /// - /// This is usually constructed for you using the the fluent builder returned by - /// [`$fluentBuilderName`](#{fluentBuilder}). - /// - /// `ParseStrictResponse` impl for `$operationName`. - """, - "fluentBuilder" to operationShape.fluentBuilderType(codegenContext, symbolProvider), - ) - Attribute(derive(RuntimeType.Clone, RuntimeType.Default, RuntimeType.Debug)).render(operationWriter) - operationWriter.rustBlock("pub struct $operationName") { - write("_private: ()") - } - operationWriter.implBlock(symbolProvider.toSymbol(operationShape)) { - BuilderGenerator.renderConvenienceMethod(this, symbolProvider, inputShape) - - rust("/// Creates a new `$operationName` operation.") - rustBlock("pub fn new() -> Self") { - rust("Self { _private: () }") - } - - writeCustomizations(customizations, OperationSection.OperationImplBlock(customizations)) - } - traitGenerator.generateTraitImpls(operationWriter, operationShape, customizations) - } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt index 8cc56a8350..1d2384b4a0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt @@ -12,8 +12,8 @@ import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.ClientModuleProvider import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.OldModuleSchemeClientModuleProvider import software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator @@ -54,7 +54,7 @@ val TestClientRustSymbolProviderConfig = RustSymbolProviderConfig( runtimeConfig = TestRuntimeConfig, renameExceptions = true, nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, - moduleProvider = OldModuleSchemeClientModuleProvider, + moduleProvider = ClientModuleProvider, ) private class ClientTestCodegenDecorator : ClientCodegenDecorator { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt index 42663f2756..703ea2a7af 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt @@ -60,8 +60,8 @@ class EventStreamSymbolProviderTest { val inputType = provider.toSymbol(inputStream).rustType() val outputType = provider.toSymbol(outputStream).rustType() - inputType shouldBe RustType.Opaque("EventStreamSender", "aws_smithy_http::event_stream") - outputType shouldBe RustType.Opaque("Receiver", "aws_smithy_http::event_stream") + inputType shouldBe RustType.Opaque("EventStreamSender", "aws_smithy_http::event_stream") + outputType shouldBe RustType.Opaque("Receiver", "aws_smithy_http::event_stream") } @Test @@ -100,7 +100,7 @@ class EventStreamSymbolProviderTest { val inputType = provider.toSymbol(inputStream).rustType() val outputType = provider.toSymbol(outputStream).rustType() - inputType shouldBe RustType.Option(RustType.Opaque("NotStreaming", "crate::model")) - outputType shouldBe RustType.Option(RustType.Opaque("NotStreaming", "crate::model")) + inputType shouldBe RustType.Option(RustType.Opaque("NotStreaming", "crate::types")) + outputType shouldBe RustType.Option(RustType.Opaque("NotStreaming", "crate::types")) } } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RequestBindingGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RequestBindingGeneratorTest.kt index be42a9647c..a769504f13 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RequestBindingGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RequestBindingGeneratorTest.kt @@ -11,7 +11,6 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.client.testutil.testClientCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -126,10 +125,11 @@ class RequestBindingGeneratorTest { private val symbolProvider = testSymbolProvider(model) private val operationShape = model.expectShape(ShapeId.from("smithy.example#PutObject"), OperationShape::class.java) private val inputShape = model.expectShape(operationShape.input.get(), StructureShape::class.java) + private val operationModule = symbolProvider.moduleForShape(inputShape) private fun renderOperation(rustCrate: RustCrate) { inputShape.renderWithModelBuilder(model, symbolProvider, rustCrate) - rustCrate.withModule(ClientRustModule.Input) { + rustCrate.withModule(operationModule) { val codegenContext = testClientCodegenContext(model) val bindingGen = RequestBindingGenerator( codegenContext, @@ -182,7 +182,7 @@ class RequestBindingGeneratorTest { fun `generates valid request bindings`() { val project = TestWorkspace.testProject(symbolProvider) renderOperation(project) - project.withModule(ClientRustModule.Input) { // Currently rendering the operation renders the protocols—I want to separate that at some point. + project.withModule(operationModule) { // Currently rendering the operation renders the protocols—I want to separate that at some point. unitTest( name = "generate_uris", test = """ diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/ResponseBindingGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/ResponseBindingGeneratorTest.kt index 5264b4ea6f..a4b9f6e8b7 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/ResponseBindingGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/ResponseBindingGeneratorTest.kt @@ -7,8 +7,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.http import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule +import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.client.testutil.testClientCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -23,6 +22,7 @@ import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.core.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape class ResponseBindingGeneratorTest { @@ -65,13 +65,14 @@ class ResponseBindingGeneratorTest { } """.asSmithyModel() private val model = OperationNormalizer.transform(baseModel) - private val operationShape = model.expectShape(ShapeId.from("smithy.example#PutObject"), OperationShape::class.java) + private val operationShape: OperationShape = model.lookup("smithy.example#PutObject") + private val outputShape: StructureShape = operationShape.outputShape(model) private val codegenContext = testClientCodegenContext(model) private val symbolProvider = codegenContext.symbolProvider private fun RustCrate.renderOperation() { operationShape.outputShape(model).renderWithModelBuilder(model, symbolProvider, this) - withModule(ClientRustModule.Output) { + withModule(symbolProvider.moduleForShape(outputShape)) { rustBlock("impl PutObjectOutput") { val bindings = HttpTraitHttpBindingResolver(model, ProtocolContentTypes.consistent("dont-care")) .responseBindings(operationShape) @@ -93,7 +94,7 @@ class ResponseBindingGeneratorTest { fun deserializeHeadersIntoOutputShape() { val testProject = TestWorkspace.testProject(symbolProvider) testProject.renderOperation() - testProject.withModule(ClientRustModule.Output) { + testProject.withModule(symbolProvider.moduleForShape(outputShape)) { unitTest( "http_header_deser", """