Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more client re-exports #2437

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,15 @@ match client.some_operation().send().await {
references = ["smithy-rs#2398"]
meta = { "breaking" = false, "tada" = true, "bug" = false }
author = "ysaito1001"

[[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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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<RuntimeType> {
internal fun pubUseTypes(codegenContext: CodegenContext, model: Model): List<RuntimeType> =
pubUseTypesThatShouldBeExported(codegenContext, model).map { it.type }

private fun pubUseTypesThatShouldBeExported(codegenContext: CodegenContext, model: Model): List<PubUseType> {
val runtimeConfig = codegenContext.runtimeConfig
return (
listOf(
Expand All @@ -58,16 +62,25 @@ internal fun pubUseTypes(codegenContext: CodegenContext, model: Model): List<Run
listOf(
PubUseType(http.resolve("byte_stream::ByteStream"), ::hasStreamingOperations),
PubUseType(http.resolve("byte_stream::AggregatedBytes"), ::hasStreamingOperations),
PubUseType(http.resolve("byte_stream::error::Error"), ::hasStreamingOperations, "ByteStreamError"),
PubUseType(http.resolve("body::SdkBody"), ::hasStreamingOperations),
)
}
).filter { pubUseType -> 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)
}
}
}

Expand All @@ -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()
Expand Down