diff --git a/codegen-server-test/model/simple.smithy b/codegen-server-test/model/simple.smithy index 70dee327fae07ef9a2e16a2543c5965b700ea58a..d4420787febe5734440ee64234378cc1d565a6ba 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 output structure") +structure StoreServiceBlobOutput { + +} 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 fc85fb6cad3d8ea2c9513ac37b9435e7f9c67ae2..dfb146f3ac8f80c53826a05fbb1c635886e191cd 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, @@ -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,