diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index c60bd839ff..b785b2e4c0 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -251,3 +251,15 @@ message = "Fix `FilterByOperationName` plugin. This previous caused services wit references = ["smithy-rs#2441"] meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "server" } author = "hlbarber" + +[[aws-sdk-rust]] +message = "Add more client re-exports. Specifically, it re-exports `aws_smithy_http::body::SdkBody`, `aws_smithy_http::byte_stream::error::Error`, and `aws_smithy_http::operation::{Request, Response}`." +references = ["smithy-rs#2437", "aws-sdk-rust#600"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "ysaito1001" + +[[smithy-rs]] +message = "Add more client re-exports. Specifically, it re-exports `aws_smithy_http::body::SdkBody`, `aws_smithy_http::byte_stream::error::Error`, and `aws_smithy_http::operation::{Request, Response}`." +references = ["smithy-rs#2437", "aws-sdk-rust#600"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" } +author = "ysaito1001" 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 31f2ee8f58..ba17a3e4a1 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 @@ -33,10 +33,14 @@ class CustomizableOperationGenerator( rustTemplate( """ pub use #{Operation}; + pub use #{Request}; + pub use #{Response}; pub use #{ClassifyRetry}; pub use #{RetryKind}; """, "Operation" to smithyHttp.resolve("operation::Operation"), + "Request" to smithyHttp.resolve("operation::Request"), + "Response" to smithyHttp.resolve("operation::Response"), "ClassifyRetry" to smithyHttp.resolve("retry::ClassifyRetry"), "RetryKind" to smithyTypes.resolve("retry::RetryKind"), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customizations/SmithyTypesPubUseExtra.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customizations/SmithyTypesPubUseExtra.kt index 48b68bfa6d..ec49a97613 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customizations/SmithyTypesPubUseExtra.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customizations/SmithyTypesPubUseExtra.kt @@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.util.letIf private data class PubUseType( val type: RuntimeType, val shouldExport: (Model) -> Boolean, + val alias: String? = null, ) /** Returns true if the model has normal streaming operations (excluding event streams) */ @@ -48,7 +49,10 @@ private fun hasBlobs(model: Model): Boolean = structUnionMembersMatchPredicate(m private fun hasDateTimes(model: Model): Boolean = structUnionMembersMatchPredicate(model, Shape::isTimestampShape) /** Returns a list of types that should be re-exported for the given model */ -internal fun pubUseTypes(codegenContext: CodegenContext, model: Model): List { +internal fun pubUseTypes(codegenContext: CodegenContext, model: Model): List = + pubUseTypesThatShouldBeExported(codegenContext, model).map { it.type } + +private fun pubUseTypesThatShouldBeExported(codegenContext: CodegenContext, model: Model): List { val runtimeConfig = codegenContext.runtimeConfig return ( listOf( @@ -58,16 +62,25 @@ internal fun pubUseTypes(codegenContext: CodegenContext, model: Model): List pubUseType.shouldExport(model) }.map { it.type } + ).filter { pubUseType -> pubUseType.shouldExport(model) } } /** Adds re-export statements for Smithy primitives */ fun pubUseSmithyPrimitives(codegenContext: CodegenContext, model: Model): Writable = writable { - val types = pubUseTypes(codegenContext, model) + val types = pubUseTypesThatShouldBeExported(codegenContext, model) if (types.isNotEmpty()) { - types.forEach { type -> rust("pub use #T;", type) } + types.forEach { + val useStatement = if (it.alias == null) { + "pub use #T;" + } else { + "pub use #T as ${it.alias};" + } + rust(useStatement, it.type) + } } } @@ -77,14 +90,15 @@ fun pubUseSmithyErrorTypes(codegenContext: CodegenContext): Writable = writable val reexports = listOf( listOf( RuntimeType.smithyHttp(runtimeConfig).let { http -> - PubUseType(http.resolve("result::SdkError")) { true } + PubUseType(http.resolve("result::SdkError"), { _ -> true }) }, ), RuntimeType.smithyTypes(runtimeConfig).let { types -> - listOf(PubUseType(types.resolve("error::display::DisplayErrorContext")) { true }) + listOf(PubUseType(types.resolve("error::display::DisplayErrorContext"), { _ -> true })) // Only re-export `ProvideErrorMetadata` for clients .letIf(codegenContext.target == CodegenTarget.CLIENT) { list -> - list + listOf(PubUseType(types.resolve("error::metadata::ProvideErrorMetadata")) { true }) + list + + listOf(PubUseType(types.resolve("error::metadata::ProvideErrorMetadata"), { _ -> true })) } }, ).flatten()