From e57776651721775f3d4c6eeb272314793499f686 Mon Sep 17 00:00:00 2001 From: 82marbag <69267416+82marbag@users.noreply.github.com> Date: Fri, 27 May 2022 08:34:19 -0400 Subject: [PATCH] Allow @required with @httpPrefixHeaders (#1410) * Allow `@required` with `@httpPrefixHeaders` The server generates members with `@required` and `@httpPrefixHeaders` as if they were always optional. This commit allows the correct generation with `@required`. Closes: #1394 Signed-off-by: Daniele Ahmed --- .../smithy/generators/http/HttpBindingGenerator.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 20f2b7fce..e61dd8310 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 @@ -25,6 +25,7 @@ import software.amazon.smithy.rust.codegen.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.rustlang.RustModule import software.amazon.smithy.rust.codegen.rustlang.RustType import software.amazon.smithy.rust.codegen.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.rustlang.asOptional import software.amazon.smithy.rust.codegen.rustlang.asType import software.amazon.smithy.rust.codegen.rustlang.autoDeref import software.amazon.smithy.rust.codegen.rustlang.render @@ -40,6 +41,7 @@ import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.smithy.generators.redactIfNecessary import software.amazon.smithy.rust.codegen.smithy.makeOptional +import software.amazon.smithy.rust.codegen.smithy.mapRustType import software.amazon.smithy.rust.codegen.smithy.protocols.HttpBindingDescriptor import software.amazon.smithy.rust.codegen.smithy.protocols.HttpLocation import software.amazon.smithy.rust.codegen.smithy.protocols.Protocol @@ -131,8 +133,8 @@ class HttpBindingGenerator( fun generateDeserializePrefixHeaderFn(binding: HttpBindingDescriptor): RuntimeType { check(binding.location == HttpBinding.Location.PREFIX_HEADERS) - val outputT = symbolProvider.toSymbol(binding.member) - check(outputT.rustType().stripOuter() is RustType.HashMap) { outputT.rustType() } + val outputSymbol = symbolProvider.toSymbol(binding.member) + check(outputSymbol.rustType().stripOuter() is RustType.HashMap) { outputSymbol.rustType() } val target = model.expectShape(binding.member.target) check(target is MapShape) val fnName = "deser_prefix_header_${fnName(operationShape, binding)}" @@ -146,11 +148,12 @@ class HttpBindingGenerator( deserializeFromHeader(model.expectShape(target.value.target), binding.member) } } + val returnTypeSymbol = outputSymbol.mapRustType { it.asOptional() } return RuntimeType.forInlineFun(fnName, httpSerdeModule) { writer -> writer.rustBlock( "pub fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>", RuntimeType.http, - outputT, + returnTypeSymbol, headerUtil ) { rust( -- GitLab