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 c40eac9631c..0aff8d6bd3a 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,6 +6,8 @@ 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.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.derive @@ -14,7 +16,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.docLink 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.smithy.CodegenContext 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 @@ -26,7 +27,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.util.inputShape open class ClientProtocolGenerator( - codegenContext: CodegenContext, + private val codegenContext: ClientCodegenContext, private val protocol: Protocol, /** * Operations generate a `make_operation(&config)` method to build a `aws_smithy_http::Operation` that can be dispatched @@ -52,7 +53,6 @@ open class ClientProtocolGenerator( val inputShape = operationShape.inputShape(model) // impl OperationInputShape { ... } - val operationName = symbolProvider.toSymbol(operationShape).name inputWriter.implBlock(symbolProvider.toSymbol(inputShape)) { writeCustomizations( customizations, @@ -61,6 +61,48 @@ open class ClientProtocolGenerator( makeOperationGenerator.generateMakeOperation(this, operationShape, customizations) } + when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) { + true -> renderOperationStruct(operationWriter, operationShape, customizations) + else -> oldRenderOperationStruct(operationWriter, operationShape, inputShape, customizations) + } + } + + private fun renderOperationStruct( + operationWriter: RustWriter, + operationShape: OperationShape, + customizations: List, + ) { + val operationName = symbolProvider.toSymbol(operationShape).name + + // pub struct Operation { ... } + operationWriter.rust( + """ + /// `ParseStrictResponse` impl for `$operationName`. + """, + ) + Attribute(derive(RuntimeType.Clone, RuntimeType.Default, RuntimeType.Debug)).render(operationWriter) + Attribute.NonExhaustive.render(operationWriter) + Attribute.DocHidden.render(operationWriter) + operationWriter.rust("pub struct $operationName;") + operationWriter.implBlock(symbolProvider.toSymbol(operationShape)) { + rustBlock("pub(crate) fn new() -> Self") { + rust("Self") + } + + writeCustomizations(customizations, OperationSection.OperationImplBlock(customizations)) + } + 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.rust( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index 60de7f8a322..fbd5a700c6b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -9,6 +9,7 @@ import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.generators.http.ResponseBindingGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.MakeOperationGenerator @@ -47,7 +48,7 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toSnakeCase class HttpBoundProtocolGenerator( - codegenContext: CodegenContext, + codegenContext: ClientCodegenContext, protocol: Protocol, ) : ClientProtocolGenerator( codegenContext, diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index 36341b4cdde..c6f427d318e 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -92,7 +92,7 @@ private class TestProtocolMakeOperationGenerator( // A stubbed test protocol to do enable testing intentionally broken protocols private class TestProtocolGenerator( - codegenContext: CodegenContext, + codegenContext: ClientCodegenContext, protocol: Protocol, httpRequestBuilder: String, body: String,