Unverified Commit 0228d5ed authored by Matteo Bigoi's avatar Matteo Bigoi Committed by GitHub
Browse files

Fix payload deserialization where we need to return an Optional type when the...

Fix payload deserialization where we need to return an Optional type when the member is non-streaming (#1166)
parent 4312e3ee
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -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 {

}
+5 −2
Original line number Diff line number Diff line
@@ -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,