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 <ahmeddan@amazon.de>
This commit is contained in:
82marbag 2022-05-27 08:34:19 -04:00 committed by GitHub
parent 1f31eae373
commit e577766517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -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<RustType.Option>() is RustType.HashMap) { outputT.rustType() }
val outputSymbol = symbolProvider.toSymbol(binding.member)
check(outputSymbol.rustType().stripOuter<RustType.Option>() 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(