Skip to content

Commit f30828e

Browse files
RFC30 update
1 parent 75269b3 commit f30828e

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegen
1515
import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator
1616
import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator
1717
import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations
18+
import software.amazon.smithy.rust.codegen.client.smithy.customize.SerdeDecorator
1819
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointsDecorator
1920
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator
2021
import software.amazon.smithy.rust.codegen.client.testutil.ClientDecoratableBuildPlugin
@@ -54,6 +55,7 @@ class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() {
5455
val codegenDecorator =
5556
CombinedClientCodegenDecorator.fromClasspath(
5657
context,
58+
SerdeDecorator(),
5759
ClientCustomizations(),
5860
RequiredCustomizations(),
5961
FluentClientDecorator(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.client.smithy.customize
7+
8+
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
9+
import software.amazon.smithy.rust.codegen.core.rustlang.Feature
10+
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
11+
12+
/**
13+
* This class,
14+
* - Adds serde as a dependency
15+
*
16+
*/
17+
class SerdeDecorator : ClientCodegenDecorator {
18+
override val name: String = "SerdeDecorator"
19+
override val order: Byte = -1
20+
21+
override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) {
22+
fun _feature(feature_name: String, crate_name: String): Feature {
23+
return Feature(feature_name, false, listOf(crate_name + "/" + feature_name))
24+
}
25+
rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types"))
26+
rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types"))
27+
}
28+
}

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientEnumGenerator.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator
2121
import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGeneratorContext
2222
import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumMemberModel
2323
import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumType
24+
import software.amazon.smithy.rust.codegen.core.smithy.generators.RenderSerdeAttribute
2425
import software.amazon.smithy.rust.codegen.core.util.dq
2526

2627
/** Infallible enums have an `Unknown` variant and can't fail to parse */
@@ -97,6 +98,8 @@ data class InfallibleEnumType(
9798
part of the enums that are public interface.
9899
""".trimIndent(),
99100
)
101+
102+
RenderSerdeAttribute.writeAttributes(this)
100103
context.enumMeta.render(this)
101104
rust("struct $UnknownVariantValue(pub(crate) String);")
102105
rustBlock("impl $UnknownVariantValue") {

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ class FluentClientGenerator(
262262
) {
263263
val outputType = symbolProvider.toSymbol(operation.outputShape(model))
264264
val errorType = symbolProvider.symbolForOperationError(operation)
265+
val inputBuilderType = symbolProvider.symbolForBuilder(input)
266+
val fnName = clientOperationFnName(operation, symbolProvider)
265267

266268
// Have to use fully-qualified result here or else it could conflict with an op named Result
267269
rustTemplate(
@@ -301,6 +303,7 @@ class FluentClientGenerator(
301303
.map_err(#{SdkError}::construction_failure)?;
302304
self.handle.client.call(op).await
303305
}
306+
304307
""",
305308
"CustomizableOperation" to ClientRustModule.Client.customize.toType()
306309
.resolve("CustomizableOperation"),
@@ -317,6 +320,42 @@ class FluentClientGenerator(
317320
),
318321
)
319322
if (codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
323+
// this fixes this error
324+
// error[E0592]: duplicate definitions with name `set_fields`
325+
// --> sdk/connectcases/src/operation/update_case/builders.rs:115:5
326+
// |
327+
// 78 | / pub fn set_fields(
328+
// 79 | | mut self,
329+
// 80 | | data: crate::operation::update_case::builders::UpdateCaseInputBuilder,
330+
// 81 | | ) -> Self {
331+
// | |_____________- other definition for `set_fields`
332+
// ...
333+
// 115 | / pub fn set_fields(
334+
// 116 | | mut self,
335+
// 117 | | input: std::option::Option<std::vec::Vec<crate::types::FieldValue>>,
336+
// 118 | | ) -> Self {
337+
// | |_____________^ duplicate definitions for `set_fields`
338+
if (inputBuilderType.toString().endsWith("Builder")) {
339+
rustTemplate(
340+
"""
341+
##[#{AwsSdkUnstableAttribute}]
342+
/// This function replaces the parameter with new one.
343+
/// It is useful when you want to replace the existing data with de-serialized data.
344+
/// ```compile_fail
345+
/// let result_future = async {
346+
/// let deserialized_parameters: $inputBuilderType = serde_json::from_str(&json_string).unwrap();
347+
/// client.$fnName().set_fields(&deserialized_parameters).send().await
348+
/// };
349+
/// ```
350+
pub fn set_fields(mut self, data: $inputBuilderType) -> Self {
351+
self.inner = data;
352+
self
353+
}
354+
""",
355+
"AwsSdkUnstableAttribute" to Attribute.AwsSdkUnstableAttribute.inner,
356+
)
357+
}
358+
320359
rustTemplate(
321360
"""
322361
// TODO(enableNewSmithyRuntime): Replace `send` with `send_v2`

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.documentShape
2323
import software.amazon.smithy.rust.codegen.core.rustlang.render
2424
import software.amazon.smithy.rust.codegen.core.rustlang.rust
2525
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
26-
import software.amazon.smithy.rust.codegen.core.rustlang.rustInline
2726
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
2827
import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter
2928
import software.amazon.smithy.rust.codegen.core.rustlang.withBlock

0 commit comments

Comments
 (0)