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 send_with method to fluent builders #2652

Merged
merged 60 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
88b3c43
- Add feature gates
thomas-k-cameron Apr 27, 2023
82d296c
Add CfgUnstable feature gate
thomas-k-cameron Apr 27, 2023
5cc6ac9
add serde to runtime type
thomas-k-cameron Apr 27, 2023
900cf67
Merge commit '82d296c38fa6794e7a986639d82456f1587b185f' into RFC30/ru…
thomas-k-cameron Apr 27, 2023
72ed5b7
Merge commit '900cf67356e3d697cf2e330708e00810aa8665da' into RFC30/fe…
thomas-k-cameron Apr 27, 2023
f701ae1
add set field
thomas-k-cameron Apr 27, 2023
78d2e0b
Merge commit '72ed5b78f1018e64095cfded1f5a9e756edff9ac' into RFC30/ad…
thomas-k-cameron Apr 27, 2023
356bde7
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Apr 29, 2023
c9a4ae0
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron May 31, 2023
893692a
Update FluentClientGenerator.kt
thomas-k-cameron May 31, 2023
c2cce08
update
thomas-k-cameron May 31, 2023
48c04f8
update
thomas-k-cameron Jun 1, 2023
bbd94ba
update
thomas-k-cameron Jun 1, 2023
75e84e7
Update FluentClientGenerator.kt
thomas-k-cameron Jun 1, 2023
7115727
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 1, 2023
ad8f413
update fluent client
thomas-k-cameron Jun 2, 2023
d1069dc
fix
thomas-k-cameron Jun 2, 2023
2cb1e9b
update
thomas-k-cameron Jun 2, 2023
663dff3
update
thomas-k-cameron Jun 2, 2023
8b38afc
update
thomas-k-cameron Jun 2, 2023
525f572
update
thomas-k-cameron Jun 2, 2023
e3367dd
update
thomas-k-cameron Jun 2, 2023
dc21f19
update
thomas-k-cameron Jun 2, 2023
5972800
update
thomas-k-cameron Jun 2, 2023
54a187b
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 2, 2023
e850ea2
update
thomas-k-cameron Jun 2, 2023
8b2877e
update
thomas-k-cameron Jun 2, 2023
ca47afe
change input path
thomas-k-cameron Jun 2, 2023
3bd1a7b
update
thomas-k-cameron Jun 2, 2023
a0a4651
update
thomas-k-cameron Jun 2, 2023
299e5ec
FIX
thomas-k-cameron Jun 3, 2023
605689e
updater
thomas-k-cameron Jun 3, 2023
ef38bbd
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 3, 2023
857f3d4
FIX
thomas-k-cameron Jun 3, 2023
7bd1365
asdf
thomas-k-cameron Jun 3, 2023
e5cd52f
update
thomas-k-cameron Jun 3, 2023
7908333
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 7, 2023
2e83422
update
thomas-k-cameron Jun 7, 2023
212506c
update
thomas-k-cameron Jun 7, 2023
54517f1
asdf
thomas-k-cameron Jun 7, 2023
140c040
precommit
thomas-k-cameron Jun 7, 2023
338ae8f
update
thomas-k-cameron Jun 7, 2023
edc62e8
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 7, 2023
3d29cf9
asdf
thomas-k-cameron Jun 7, 2023
7f44d06
Merge branch 'RFC30/add-set-fields' of https://github.com/thomas-k-ca…
thomas-k-cameron Jun 7, 2023
6cd4b6b
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 8, 2023
11af526
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 11, 2023
8fc4751
Update codegen-client/src/main/kotlin/software/amazon/smithy/rust/cod…
thomas-k-cameron Jun 13, 2023
20ea34b
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 13, 2023
ddc8c71
update
thomas-k-cameron Jun 13, 2023
3531f10
update
thomas-k-cameron Jun 13, 2023
08440b8
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 13, 2023
c76dada
Merge branch 'main' into RFC30/add-set-fields
jdisanti Jun 13, 2023
79662af
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 14, 2023
4251f97
update changelog
thomas-k-cameron Jun 14, 2023
0e478b2
FIX
thomas-k-cameron Jun 14, 2023
fa6e681
update
thomas-k-cameron Jun 14, 2023
ef451bb
update
thomas-k-cameron Jun 14, 2023
d8c5135
Update CHANGELOG.next.toml
jdisanti Jun 14, 2023
073d873
Merge branch 'main' into RFC30/add-set-fields
thomas-k-cameron Jun 14, 2023
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
40 changes: 37 additions & 3 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
message = "Fix bug in AWS JSON 1.x routers where, if a service had more than 14 operations, the router was created without the route for the 15th operation."
author = "thor-bjorgvinsson"
references = ["smithy-rs#2733"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" ="server" }
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "server" }

[[aws-sdk-rust]]
message = "Remove native-tls and add a migration guide."
Expand Down Expand Up @@ -66,7 +66,7 @@ author = "jdisanti"
[[smithy-rs]]
message = "For event stream operations, the `EventStreamSender` in inputs/outputs now requires the passed in `Stream` impl to implement `Sync`."
references = ["smithy-rs#2673"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"}
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" }
author = "jdisanti"

[[aws-sdk-rust]]
Expand Down Expand Up @@ -143,7 +143,7 @@ author = "jdisanti"
[[smithy-rs]]
message = "Update MSRV to Rust 1.68.2"
references = ["smithy-rs#2745"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"}
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" }
author = "jdisanti"

[[smithy-rs]]
Expand Down Expand Up @@ -408,3 +408,37 @@ let scoped_plugin = Scoped::new::<SomeScope>(plugin);
references = ["smithy-rs#2740", "smithy-rs#2759"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "hlbarber"

[[smithy-rs]]
message = "Implement unstable serde support for the `Number`, `Blob`, `Document`, `DateTime` primitives"
author = "thomas-k-cameron"
meta = { "breaking" = false, "tada" = true, "bug" = false, target = "all" }
references = [
"smithy-rs#2647",
"smithy-rs#2645",
"smithy-rs#2646",
"smithy-rs#2616",
]

[[aws-sdk-rust]]
message = "Implement unstable serde support for the `Number`, `Blob`, `Document`, `DateTime` primitives"
author = "thomas-k-cameron"
meta = { "breaking" = false, "tada" = true, "bug" = false }
references = [
"smithy-rs#2647",
"smithy-rs#2645",
"smithy-rs#2646",
"smithy-rs#2616",
]

[[smithy-rs]]
message = "Add a `send_with` function on `-Input` types for sending requests without fluent builders"
author = "thomas-k-cameron"
references = ["smithy-rs#2652"]
meta = { "breaking" = false, "tada" = true, "bug" = false, target = "client" }

[[aws-sdk-rust]]
message = "Add a `send_with` function on `-Input` types for sending requests without fluent builders"
author = "thomas-k-cameron"
references = ["smithy-rs#2652"]
meta = { "breaking" = false, "tada" = true, "bug" = false }
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.docLink
import software.amazon.smithy.rust.codegen.core.rustlang.docs
import software.amazon.smithy.rust.codegen.core.rustlang.documentShape
import software.amazon.smithy.rust.codegen.core.rustlang.escape
import software.amazon.smithy.rust.codegen.core.rustlang.implBlock
import software.amazon.smithy.rust.codegen.core.rustlang.normalizeHtml
import software.amazon.smithy.rust.codegen.core.rustlang.qualifiedName
import software.amazon.smithy.rust.codegen.core.rustlang.render
Expand Down Expand Up @@ -315,10 +316,44 @@ class FluentClientGenerator(
}

private fun RustWriter.renderFluentBuilder(operation: OperationShape) {
val outputType = symbolProvider.toSymbol(operation.outputShape(model))
val errorType = symbolProvider.symbolForOperationError(operation)
val operationSymbol = symbolProvider.toSymbol(operation)

val input = operation.inputShape(model)
val baseDerives = symbolProvider.toSymbol(input).expectRustMetadata().derives
// Filter out any derive that isn't Clone. Then add a Debug derive
// input name
val fnName = clientOperationFnName(operation, symbolProvider)
implBlock(symbolProvider.symbolForBuilder(input)) {
rustTemplate(
"""
/// Sends a request with this input using the given client.
pub async fn send_with${generics.inst}(self, client: &crate::Client${generics.inst}) -> #{Result}<#{OperationOutput}, #{SdkError}<#{OperationError}, #{RawResponseType}>>
#{send_bounds:W}
#{boundsWithoutWhereClause:W}
{
let mut fluent_builder = client.$fnName();
fluent_builder.inner = self;
fluent_builder.send().await
}
""",
*preludeScope,
"RawResponseType" to if (codegenContext.smithyRuntimeMode.defaultToMiddleware) {
RuntimeType.smithyHttp(runtimeConfig).resolve("operation::Response")
} else {
RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::orchestrator::HttpResponse")
},
"Operation" to operationSymbol,
"OperationError" to errorType,
"OperationOutput" to outputType,
"SdkError" to RuntimeType.sdkError(runtimeConfig),
"SdkSuccess" to RuntimeType.sdkSuccess(runtimeConfig),
"boundsWithoutWhereClause" to generics.boundsWithoutWhereClause,
"send_bounds" to generics.sendBounds(operationSymbol, outputType, errorType, retryClassifier),
)
}

val derives = baseDerives.filter { it == RuntimeType.Clone } + RuntimeType.Debug
docs("Fluent builder constructing a request to `${operationSymbol.name}`.\n")

Expand Down Expand Up @@ -350,9 +385,6 @@ class FluentClientGenerator(
"client" to RuntimeType.smithyClient(runtimeConfig),
"bounds" to generics.bounds,
) {
val outputType = symbolProvider.toSymbol(operation.outputShape(model))
val errorType = symbolProvider.symbolForOperationError(operation)

rust("/// Creates a new `${operationSymbol.name}`.")
withBlockTemplate(
"pub(crate) fn new(handle: #{Arc}<crate::client::Handle${generics.inst}>) -> Self {",
Expand All @@ -370,6 +402,7 @@ class FluentClientGenerator(
}
}
}

if (smithyRuntimeMode.generateMiddleware) {
val middlewareScope = arrayOf(
*preludeScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ interface FluentClientGenerics {

/** Convert this `FluentClientGenerics` into the more general `RustGenerics` */
fun toRustGenerics(): RustGenerics

/** bounds without where clause. If bounds does is not prefixed with `where\n`, then it gets the same value. **/
val boundsWithoutWhereClause: Writable
}

class NoClientGenerics(private val runtimeConfig: RuntimeConfig) : FluentClientGenerics {
Expand All @@ -55,6 +58,8 @@ class NoClientGenerics(private val runtimeConfig: RuntimeConfig) : FluentClientG
/** Trait bounds */
override val bounds = writable { }

override val boundsWithoutWhereClause = writable {}

/** Bounds for generated `send()` functions */
override fun sendBounds(
operation: Symbol,
Expand Down Expand Up @@ -94,9 +99,18 @@ data class FlexibleClientGenerics(
rustTemplate(
"""
where
C: #{client}::bounds::SmithyConnector,
M: #{client}::bounds::SmithyMiddleware<C>,
R: #{client}::retry::NewRequestPolicy,
#{bounds}
""",
"bounds" to boundsWithoutWhereClause,
)
}

override val boundsWithoutWhereClause = writable {
rustTemplate(
"""
C: #{client}::bounds::SmithyConnector,
thomas-k-cameron marked this conversation as resolved.
Show resolved Hide resolved
M: #{client}::bounds::SmithyMiddleware<C>,
R: #{client}::retry::NewRequestPolicy,
""",
"client" to client,
)
Expand All @@ -112,7 +126,7 @@ data class FlexibleClientGenerics(
#{OperationOutput},
#{OperationError},
#{RetryClassifier}
>
>,
""",
"client" to client,
"Operation" to operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import java.nio.file.Path
sealed class DependencyScope {
object Dev : DependencyScope()
object Compile : DependencyScope()
object CfgUnstable : DependencyScope()
object Build : DependencyScope()
}

Expand Down Expand Up @@ -283,5 +284,8 @@ data class CargoDependency(
fun smithyRuntimeApi(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-runtime-api")
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,23 @@ class Attribute(val inner: Writable, val isDeriveHelper: Boolean = false) {
}
}

// 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)))
}
public fun SerdeSkip(): Attribute {
return Attribute(cfgAttr(all(writable("aws_sdk_unstable"), any(feature("serde-serialize"), feature("serde-deserialize"))), serde("skip")))
}

public fun SerdeSerializeOrDeserialize(): Attribute {
return Attribute(cfg(all(writable("aws_sdk_unstable"), any(feature("serde-serialize"), feature("serde-deserialize")))))
}

companion object {
val AllowClippyBoxedLocal = Attribute(allow("clippy::boxed_local"))
val AllowClippyLetAndReturn = Attribute(allow("clippy::let_and_return"))
Expand Down Expand Up @@ -504,6 +521,7 @@ class Attribute(val inner: Writable, val isDeriveHelper: Boolean = false) {

val Test = Attribute("test")
val TokioTest = Attribute(RuntimeType.Tokio.resolve("test").writable)
val AwsSdkUnstableAttribute = Attribute(cfg("aws_sdk_unstable"))

/**
* [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute)
Expand Down Expand Up @@ -532,10 +550,12 @@ class Attribute(val inner: Writable, val isDeriveHelper: Boolean = false) {
}

fun all(vararg attrMacros: Writable): Writable = macroWithArgs("all", *attrMacros)
fun cfgAttr(vararg attrMacros: Writable): Writable = macroWithArgs("cfg_attr", *attrMacros)

fun allow(lints: Collection<String>): Writable = macroWithArgs("allow", *lints.toTypedArray())
fun allow(vararg lints: String): Writable = macroWithArgs("allow", *lints)
fun deny(vararg lints: String): Writable = macroWithArgs("deny", *lints)
fun serde(vararg lints: String): Writable = macroWithArgs("serde", *lints)
fun any(vararg attrMacros: Writable): Writable = macroWithArgs("any", *attrMacros)
fun cfg(vararg attrMacros: Writable): Writable = macroWithArgs("cfg", *attrMacros)
fun cfg(vararg attrMacros: String): Writable = macroWithArgs("cfg", *attrMacros)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ 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. Gated behind `CfgUnstable`.
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()
fun smithyChecksums(runtimeConfig: RuntimeConfig) = CargoDependency.smithyChecksums(runtimeConfig).toType()
Expand Down