Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions codegen-server-test/model/simple.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ service SimpleService {
],
operations: [
Healthcheck,
StoreServiceBlob,
],
}

Expand Down Expand Up @@ -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 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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,
Expand Down