Loading codegen-test/dynamo-it/src/main.rs +1 −6 Original line number Diff line number Diff line Loading @@ -64,9 +64,6 @@ async fn main() -> Result<(), Box<dyn Error>> { ) .build(&config); let body = String::from_utf8(create_table.build_http_request().body().clone()).unwrap(); println!("{}", body); let response = io_v0::dispatch!(client, create_table); match response.parsed { Some(Ok(output)) => { Loading @@ -83,9 +80,7 @@ async fn main() -> Result<(), Box<dyn Error>> { let tables = io_v0::dispatch!( client, dynamo::operation::ListTables::builder().build(&config) ) .parsed .unwrap(); ).parsed.unwrap(); println!( "current tables: {:?}", &tables.as_ref().unwrap().table_names Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt +1 −0 Original line number Diff line number Diff line Loading @@ -173,5 +173,6 @@ data class CargoDependency( val SerdeJson: CargoDependency = CargoDependency("serde_json", CratesIo("1"), features = listOf("float_roundtrip")) val Serde = CargoDependency("serde", CratesIo("1"), features = listOf("derive")) val Bytes: RustDependency = CargoDependency("bytes", CratesIo("1")) } } codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt +6 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,12 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n val Config = RuntimeType("config", null, "crate") fun operation(runtimeConfig: RuntimeConfig) = RuntimeType("Operation", dependency = CargoDependency.SmithyHttp(runtimeConfig), namespace = "smithy_http::operation") fun operationModule(runtimeConfig: RuntimeConfig) = RuntimeType(null, dependency = CargoDependency.SmithyHttp(runtimeConfig), namespace = "smithy_http::operation") fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = RuntimeType("SdkBody", dependency = CargoDependency.SmithyHttp(runtimeConfig), "smithy_http::body") fun parseStrict(runtimeConfig: RuntimeConfig) = RuntimeType("ParseStrictResponse", dependency = CargoDependency.SmithyHttp(runtimeConfig), namespace = "smithy_http::response") val Bytes = RuntimeType("Bytes", dependency = CargoDependency.Bytes, namespace = "bytes") fun BlobSerde(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.blobSerde(runtimeConfig)) private fun forInlineDependency(inlineDependency: InlineDependency) = Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/BuilderGenerator.kt +27 −9 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import software.amazon.smithy.rust.codegen.rustlang.conditionalBlock import software.amazon.smithy.rust.codegen.rustlang.docs import software.amazon.smithy.rust.codegen.rustlang.documentShape import software.amazon.smithy.rust.codegen.rustlang.render import software.amazon.smithy.rust.codegen.rustlang.rust import software.amazon.smithy.rust.codegen.rustlang.rustBlock import software.amazon.smithy.rust.codegen.rustlang.stripOuter import software.amazon.smithy.rust.codegen.rustlang.withBlock Loading @@ -23,6 +24,7 @@ import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.smithy.defaultValue import software.amazon.smithy.rust.codegen.smithy.isOptional import software.amazon.smithy.rust.codegen.smithy.letIf import software.amazon.smithy.rust.codegen.smithy.makeOptional import software.amazon.smithy.rust.codegen.smithy.rustType import software.amazon.smithy.rust.codegen.util.dq Loading Loading @@ -64,19 +66,35 @@ class OperationInputBuilderGenerator( ) : BuilderGenerator(model, symbolProvider, shape.inputShape(model)) { override fun buildFn(implBlockWriter: RustWriter) { val fallibleBuilder = StructureGenerator.fallibleBuilder(shape.inputShape(model), symbolProvider) val returnType = when (fallibleBuilder) { true -> "Result<#T, String>" false -> "#T" } val retryType = "()" val returnType = "#T<#{T}, $retryType>".letIf(fallibleBuilder) { "Result<$it, String>" } val outputSymbol = symbolProvider.toSymbol(shape) val operationT = RuntimeType.operation(symbolProvider.config().runtimeConfig) val operationModule = RuntimeType.operationModule(symbolProvider.config().runtimeConfig) val sdkBody = RuntimeType.sdkBody(symbolProvider.config().runtimeConfig) implBlockWriter.docs("Consumes the builder and constructs a #D", outputSymbol) implBlockWriter.rustBlock("pub fn build(self, _config: &#T::Config) -> $returnType", RuntimeType.Config, outputSymbol) { conditionalBlock("Ok(", ")", conditional = fallibleBuilder) { // If a wrapper is specified, use the `::new` associated function to construct the wrapper withBlock("#T::new(", ")", outputSymbol) { implBlockWriter.docs("Consumes the builder and constructs an Operation<#D>", outputSymbol) implBlockWriter.rustBlock("pub fn build(self, _config: &#T::Config) -> $returnType", RuntimeType.Config, operationT, outputSymbol) { conditionalBlock("Ok({", "})", conditional = fallibleBuilder) { withBlock("let op = #T::new(", ");", outputSymbol) { coreBuilder(this) } rust( """ ##[allow(unused_mut)] let mut request = #T::Request::new(op.build_http_request().map(#T::from)); """, operationModule, sdkBody ) rust( """ #T::new( request, op ) """, operationT ) } } } Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolGenerator.kt +3 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ abstract class HttpProtocolGenerator( write("Self { input }") } } traitImplementations(operationWriter, operationShape) } protected fun httpBuilderFun(implBlockWriter: RustWriter, f: RustWriter.() -> Unit) { Loading Loading @@ -131,6 +132,8 @@ abstract class HttpProtocolGenerator( } } abstract fun traitImplementations(operationWriter: RustWriter, operationShape: OperationShape) abstract fun fromResponseImpl(implBlockWriter: RustWriter, operationShape: OperationShape) /** Loading Loading
codegen-test/dynamo-it/src/main.rs +1 −6 Original line number Diff line number Diff line Loading @@ -64,9 +64,6 @@ async fn main() -> Result<(), Box<dyn Error>> { ) .build(&config); let body = String::from_utf8(create_table.build_http_request().body().clone()).unwrap(); println!("{}", body); let response = io_v0::dispatch!(client, create_table); match response.parsed { Some(Ok(output)) => { Loading @@ -83,9 +80,7 @@ async fn main() -> Result<(), Box<dyn Error>> { let tables = io_v0::dispatch!( client, dynamo::operation::ListTables::builder().build(&config) ) .parsed .unwrap(); ).parsed.unwrap(); println!( "current tables: {:?}", &tables.as_ref().unwrap().table_names Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt +1 −0 Original line number Diff line number Diff line Loading @@ -173,5 +173,6 @@ data class CargoDependency( val SerdeJson: CargoDependency = CargoDependency("serde_json", CratesIo("1"), features = listOf("float_roundtrip")) val Serde = CargoDependency("serde", CratesIo("1"), features = listOf("derive")) val Bytes: RustDependency = CargoDependency("bytes", CratesIo("1")) } }
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt +6 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,12 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n val Config = RuntimeType("config", null, "crate") fun operation(runtimeConfig: RuntimeConfig) = RuntimeType("Operation", dependency = CargoDependency.SmithyHttp(runtimeConfig), namespace = "smithy_http::operation") fun operationModule(runtimeConfig: RuntimeConfig) = RuntimeType(null, dependency = CargoDependency.SmithyHttp(runtimeConfig), namespace = "smithy_http::operation") fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = RuntimeType("SdkBody", dependency = CargoDependency.SmithyHttp(runtimeConfig), "smithy_http::body") fun parseStrict(runtimeConfig: RuntimeConfig) = RuntimeType("ParseStrictResponse", dependency = CargoDependency.SmithyHttp(runtimeConfig), namespace = "smithy_http::response") val Bytes = RuntimeType("Bytes", dependency = CargoDependency.Bytes, namespace = "bytes") fun BlobSerde(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.blobSerde(runtimeConfig)) private fun forInlineDependency(inlineDependency: InlineDependency) = Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/BuilderGenerator.kt +27 −9 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import software.amazon.smithy.rust.codegen.rustlang.conditionalBlock import software.amazon.smithy.rust.codegen.rustlang.docs import software.amazon.smithy.rust.codegen.rustlang.documentShape import software.amazon.smithy.rust.codegen.rustlang.render import software.amazon.smithy.rust.codegen.rustlang.rust import software.amazon.smithy.rust.codegen.rustlang.rustBlock import software.amazon.smithy.rust.codegen.rustlang.stripOuter import software.amazon.smithy.rust.codegen.rustlang.withBlock Loading @@ -23,6 +24,7 @@ import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.smithy.defaultValue import software.amazon.smithy.rust.codegen.smithy.isOptional import software.amazon.smithy.rust.codegen.smithy.letIf import software.amazon.smithy.rust.codegen.smithy.makeOptional import software.amazon.smithy.rust.codegen.smithy.rustType import software.amazon.smithy.rust.codegen.util.dq Loading Loading @@ -64,19 +66,35 @@ class OperationInputBuilderGenerator( ) : BuilderGenerator(model, symbolProvider, shape.inputShape(model)) { override fun buildFn(implBlockWriter: RustWriter) { val fallibleBuilder = StructureGenerator.fallibleBuilder(shape.inputShape(model), symbolProvider) val returnType = when (fallibleBuilder) { true -> "Result<#T, String>" false -> "#T" } val retryType = "()" val returnType = "#T<#{T}, $retryType>".letIf(fallibleBuilder) { "Result<$it, String>" } val outputSymbol = symbolProvider.toSymbol(shape) val operationT = RuntimeType.operation(symbolProvider.config().runtimeConfig) val operationModule = RuntimeType.operationModule(symbolProvider.config().runtimeConfig) val sdkBody = RuntimeType.sdkBody(symbolProvider.config().runtimeConfig) implBlockWriter.docs("Consumes the builder and constructs a #D", outputSymbol) implBlockWriter.rustBlock("pub fn build(self, _config: &#T::Config) -> $returnType", RuntimeType.Config, outputSymbol) { conditionalBlock("Ok(", ")", conditional = fallibleBuilder) { // If a wrapper is specified, use the `::new` associated function to construct the wrapper withBlock("#T::new(", ")", outputSymbol) { implBlockWriter.docs("Consumes the builder and constructs an Operation<#D>", outputSymbol) implBlockWriter.rustBlock("pub fn build(self, _config: &#T::Config) -> $returnType", RuntimeType.Config, operationT, outputSymbol) { conditionalBlock("Ok({", "})", conditional = fallibleBuilder) { withBlock("let op = #T::new(", ");", outputSymbol) { coreBuilder(this) } rust( """ ##[allow(unused_mut)] let mut request = #T::Request::new(op.build_http_request().map(#T::from)); """, operationModule, sdkBody ) rust( """ #T::new( request, op ) """, operationT ) } } } Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolGenerator.kt +3 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ abstract class HttpProtocolGenerator( write("Self { input }") } } traitImplementations(operationWriter, operationShape) } protected fun httpBuilderFun(implBlockWriter: RustWriter, f: RustWriter.() -> Unit) { Loading Loading @@ -131,6 +132,8 @@ abstract class HttpProtocolGenerator( } } abstract fun traitImplementations(operationWriter: RustWriter, operationShape: OperationShape) abstract fun fromResponseImpl(implBlockWriter: RustWriter, operationShape: OperationShape) /** Loading