From b714a8ffcb39c1dc249581b2bbe043bda1c15988 Mon Sep 17 00:00:00 2001 From: Bigo <1781140+crisidev@users.noreply.github.com> Date: Mon, 7 Feb 2022 17:01:13 +0000 Subject: [PATCH 1/4] Fix payload serialization where we need to return an Optional type when the member is streaming --- .../codegen/smithy/generators/http/HttpBindingGenerator.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt index fc85fb6cad3..48300cf26c3 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt @@ -181,10 +181,10 @@ class HttpBindingGenerator( httpMessageType: HttpMessageType = HttpMessageType.RESPONSE ): RuntimeType { check(binding.location == HttpBinding.Location.PAYLOAD) - val outputT = symbolProvider.toSymbol(binding.member) val fnName = "deser_payload_${fnName(operationShape, binding)}" return RuntimeType.forInlineFun(fnName, httpSerdeModule) { rustWriter -> if (binding.member.isStreaming(model)) { + val outputT = symbolProvider.toSymbol(binding.member) rustWriter.rustBlock( "pub fn $fnName(body: &mut #T) -> std::result::Result<#T, #T>", RuntimeType.sdkBody(runtimeConfig), @@ -200,6 +200,9 @@ class HttpBindingGenerator( } } } else { + // The output needs to be Optional when deserializing the payload body or the caller signature + // will not match. + val outputT = symbolProvider.toSymbol(binding.member).makeOptional() rustWriter.rustBlock("pub fn $fnName(body: &[u8]) -> std::result::Result<#T, #T>", outputT, errorT) { deserializePayloadBody( binding, From 076ec4e377e9b21dfa49efbdd6830323f160b4de Mon Sep 17 00:00:00 2001 From: Bigo <1781140+crisidev@users.noreply.github.com> Date: Tue, 8 Feb 2022 12:06:54 +0000 Subject: [PATCH 2/4] Add little example to simple.smithy covering a required httpPayload in input structure --- codegen-server-test/model/simple.smithy | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/codegen-server-test/model/simple.smithy b/codegen-server-test/model/simple.smithy index 70dee327fae..4e74999996d 100644 --- a/codegen-server-test/model/simple.smithy +++ b/codegen-server-test/model/simple.smithy @@ -16,6 +16,7 @@ service SimpleService { ], operations: [ Healthcheck, + StoreServiceBlob, ], } @@ -105,3 +106,26 @@ structure HealthcheckInputRequest { structure HealthcheckOutputResponse { } + +@readonly +@http(method: "GET", uri: "/service/{id}/blob") +@documentation("Stores a blob for a service id") +operation StoreServiceBlob { + input: StoreServiceBlobInput, + output: StoreServiceBlobOutput +} + +@documentation("Store a blob for a service id input structure") +structure StoreServiceBlobInput { + @required + @httpLabel + id: ServiceId, + @required + @httpPayload + content: Blob, +} + +@documentation("Store a blob for a service id input structure") +structure StoreServiceBlobOutput { + +} From b27fd90162e8a7a5868474ff3a61d7e9efdbd51e Mon Sep 17 00:00:00 2001 From: Bigo <1781140+crisidev@users.noreply.github.com> Date: Tue, 8 Feb 2022 12:07:28 +0000 Subject: [PATCH 3/4] Fix typo --- codegen-server-test/model/simple.smithy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-server-test/model/simple.smithy b/codegen-server-test/model/simple.smithy index 4e74999996d..d4420787feb 100644 --- a/codegen-server-test/model/simple.smithy +++ b/codegen-server-test/model/simple.smithy @@ -125,7 +125,7 @@ structure StoreServiceBlobInput { content: Blob, } -@documentation("Store a blob for a service id input structure") +@documentation("Store a blob for a service id output structure") structure StoreServiceBlobOutput { } From 3ac2b85d7a23aae68a9be287edb9adb9b46ffbff Mon Sep 17 00:00:00 2001 From: Bigo <1781140+crisidev@users.noreply.github.com> Date: Tue, 8 Feb 2022 14:01:08 +0000 Subject: [PATCH 4/4] Fix docstring --- .../rust/codegen/smithy/generators/http/HttpBindingGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt index 48300cf26c3..dfb146f3ac8 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/http/HttpBindingGenerator.kt @@ -170,7 +170,7 @@ class HttpBindingGenerator( } /** - * Generate a function to deserialize `[binding]` from the response payload. + * Generate a function to deserialize `[binding]` from the request / response payload. */ fun generateDeserializePayloadFn( operationShape: OperationShape,