From aaf75fbceb39d8240b98b7a76bf2589bdcc864b3 Mon Sep 17 00:00:00 2001 From: david-perez Date: Fri, 21 Oct 2022 17:13:35 +0200 Subject: [PATCH] Remove TODO about required `httpHeader`-bound collection shapes (#1397) We do support required `httpHeader`-bound collection shapes, as evidenced by the test operation this commit adds, which is generated by the server, that does not use `Option` for `required` member shapes. This is because even though the deserialization always returns an optional collection, we return `None` if no headers are found (as opposed to an empty collection), so the call that sets the member field on the operation structure does nothing; when `build()` gets called, a `BuildError` is raised because the member is required. --- codegen-core/common-test-models/misc.smithy | 35 ++++++++++++++++--- .../generators/http/HttpBindingGenerator.kt | 1 - 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/codegen-core/common-test-models/misc.smithy b/codegen-core/common-test-models/misc.smithy index c3449feb2..a98c0fa21 100644 --- a/codegen-core/common-test-models/misc.smithy +++ b/codegen-core/common-test-models/misc.smithy @@ -14,7 +14,8 @@ use smithy.test#httpResponseTests service MiscService { operations: [ TypeComplexityOperation, - InnerRequiredShapeOperation, + RequiredInnerShapeOperation, + RequiredHeaderCollectionOperation, ResponseCodeRequiredOperation, ResponseCodeHttpFallbackOperation, ResponseCodeDefaultOperation, @@ -54,12 +55,12 @@ map MapA { /// This operation tests that (de)serializing required values from a nested /// shape works correctly. @http(uri: "/innerRequiredShapeOperation", method: "POST") -operation InnerRequiredShapeOperation { - input: InnerRequiredShapeOperationInputOutput, - output: InnerRequiredShapeOperationInputOutput, +operation RequiredInnerShapeOperation { + input: RequiredInnerShapeOperationInputOutput, + output: RequiredInnerShapeOperationInputOutput, } -structure InnerRequiredShapeOperationInputOutput { +structure RequiredInnerShapeOperationInputOutput { inner: InnerShape } @@ -230,3 +231,27 @@ structure ResponseCodeRequiredOutput { } ]) operation AcceptHeaderStarService {} + +@http(uri: "/required-header-collection-operation", method: "GET") +operation RequiredHeaderCollectionOperation { + input: RequiredHeaderCollectionOperationInputOutput, + output: RequiredHeaderCollectionOperationInputOutput, +} + +structure RequiredHeaderCollectionOperationInputOutput { + @required + @httpHeader("X-Required-List") + requiredHeaderList: HeaderList, + + @required + @httpHeader("X-Required-Set") + requiredHeaderSet: HeaderSet, +} + +list HeaderList { + member: String +} + +set HeaderSet { + member: String +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index 47e1240a0..8d089ef8b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -365,7 +365,6 @@ class HttpBindingGenerator( rust("let $parsedValue = $parsedValue?;") } } - // TODO(https://github.com/awslabs/smithy-rs/issues/837): this doesn't support non-optional vectors when (rustType) { is RustType.Vec -> rust( -- GitLab