generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 221
Bump smithy version to 1.52 #3887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
19d76ca
Bump smithy version to 1.52
landonxjames 200335b
Merge branch 'main' into landonxjames/smithy152
landonxjames e98d3ed
Fix null document in protocol test
landonxjames 894cf94
Revert ddb update, it broke something
landonxjames 14ae7dd
Update header serialization to include empty headers
landonxjames d43e580
Add accept header to RpcV2Cbor
landonxjames 7657f1b
Remove unnecessary reference in header serializer
landonxjames f0bc029
Update comment
landonxjames 7dcedeb
Add broken tests for smithy 1.52
landonxjames 29413cc
Update header codegen to not user unnecessary ref
landonxjames 037972f
Separate empty header logic for client/server
landonxjames 47247ac
Merge branch 'main' into landonxjames/smithy152
landonxjames f96ff63
Merge branch 'main' into landonxjames/smithy152
landonxjames c2ecd75
Update header serializiation with conditionalBlock
landonxjames File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustType | |
| import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.Writable | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.asOptional | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.qualifiedName | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.render | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.rust | ||
|
|
@@ -491,6 +492,7 @@ class HttpBindingGenerator( | |
| fun generateAddHeadersFn( | ||
| shape: Shape, | ||
| httpMessageType: HttpMessageType = HttpMessageType.REQUEST, | ||
| serializeEmptyHeaders: Boolean = false, | ||
| ): RuntimeType? { | ||
| val (headerBindings, prefixHeaderBinding) = | ||
| when (httpMessageType) { | ||
|
|
@@ -538,7 +540,7 @@ class HttpBindingGenerator( | |
| """, | ||
| *codegenScope, | ||
| ) { | ||
| headerBindings.forEach { httpBinding -> renderHeaders(httpBinding) } | ||
| headerBindings.forEach { httpBinding -> renderHeaders(httpBinding, serializeEmptyHeaders) } | ||
| if (prefixHeaderBinding != null) { | ||
| renderPrefixHeader(prefixHeaderBinding) | ||
| } | ||
|
|
@@ -547,7 +549,10 @@ class HttpBindingGenerator( | |
| } | ||
| } | ||
|
|
||
| private fun RustWriter.renderHeaders(httpBinding: HttpBinding) { | ||
| private fun RustWriter.renderHeaders( | ||
| httpBinding: HttpBinding, | ||
| serializeEmptyHeaders: Boolean, | ||
| ) { | ||
| check(httpBinding.location == HttpLocation.HEADER) | ||
| val memberShape = httpBinding.member | ||
| val targetShape = model.expectShape(memberShape.target) | ||
|
|
@@ -585,6 +590,7 @@ class HttpBindingGenerator( | |
| targetShape, | ||
| timestampFormat, | ||
| renderErrorMessage, | ||
| serializeEmptyHeaders, | ||
| ) | ||
| } else { | ||
| renderHeaderValue( | ||
|
|
@@ -596,6 +602,7 @@ class HttpBindingGenerator( | |
| renderErrorMessage, | ||
| serializeIfDefault = memberSymbol.isOptional(), | ||
| memberShape, | ||
| serializeEmptyHeaders, | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -608,6 +615,7 @@ class HttpBindingGenerator( | |
| shape: CollectionShape, | ||
| timestampFormat: TimestampFormatTrait.Format, | ||
| renderErrorMessage: (String) -> Writable, | ||
| serializeEmptyHeaders: Boolean, | ||
| ) { | ||
| val loopVariable = ValueExpression.Reference(safeName("inner")) | ||
| val context = HeaderValueSerializationContext(value, shape) | ||
|
|
@@ -617,17 +625,29 @@ class HttpBindingGenerator( | |
| )(this) | ||
| } | ||
|
|
||
| rustBlock("for ${loopVariable.name} in ${context.valueExpression.asRef()}") { | ||
| this.renderHeaderValue( | ||
| headerName, | ||
| loopVariable, | ||
| model.expectShape(shape.member.target), | ||
| isMultiValuedHeader = true, | ||
| timestampFormat, | ||
| renderErrorMessage, | ||
| serializeIfDefault = true, | ||
| shape.member, | ||
| ) | ||
| // Conditionally wrap the header generation in a block that handles empty header values if | ||
| // `serializeEmptyHeaders` is true | ||
| conditionalBlock( | ||
| """ | ||
| // Empty vec in header is serialized as an empty string | ||
| if ${context.valueExpression.name}.is_empty() { | ||
| builder = builder.header("$headerName", ""); | ||
| } else {""", | ||
| "}", conditional = serializeEmptyHeaders, | ||
|
Comment on lines
+632
to
+636
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
| ) { | ||
| rustBlock("for ${loopVariable.name} in ${context.valueExpression.asRef()}") { | ||
| this.renderHeaderValue( | ||
| headerName, | ||
| loopVariable, | ||
| model.expectShape(shape.member.target), | ||
| isMultiValuedHeader = true, | ||
| timestampFormat, | ||
| renderErrorMessage, | ||
| serializeIfDefault = true, | ||
| shape.member, | ||
| serializeEmptyHeaders, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -647,6 +667,7 @@ class HttpBindingGenerator( | |
| renderErrorMessage: (String) -> Writable, | ||
| serializeIfDefault: Boolean, | ||
| memberShape: MemberShape, | ||
| serializeEmptyHeaders: Boolean, | ||
| ) { | ||
| val context = HeaderValueSerializationContext(value, shape) | ||
| for (customization in customizations) { | ||
|
|
@@ -669,20 +690,24 @@ class HttpBindingGenerator( | |
| isMultiValuedHeader = isMultiValuedHeader, | ||
| ) | ||
| val safeName = safeName("formatted") | ||
| rustTemplate( | ||
| """ | ||
| let $safeName = $formatted; | ||
| if !$safeName.is_empty() { | ||
|
|
||
| // If `serializeEmptyHeaders` is false we wrap header serialization in a `!foo.is_empty()` check and skip | ||
| // serialization if the header value is empty | ||
| rust("let $safeName = $formatted;") | ||
| conditionalBlock("if !$safeName.is_empty() {", "}", conditional = !serializeEmptyHeaders) { | ||
| rustTemplate( | ||
| """ | ||
| let header_value = $safeName; | ||
| let header_value: #{HeaderValue} = header_value.parse().map_err(|err| { | ||
| #{invalid_field_error:W} | ||
| })?; | ||
| builder = builder.header("$headerName", header_value); | ||
| } | ||
| """, | ||
| "HeaderValue" to RuntimeType.Http.resolve("HeaderValue"), | ||
| "invalid_field_error" to renderErrorMessage("header_value"), | ||
| ) | ||
|
|
||
| """, | ||
| "HeaderValue" to RuntimeType.Http.resolve("HeaderValue"), | ||
| "invalid_field_error" to renderErrorMessage("header_value"), | ||
| ) | ||
| } | ||
| } | ||
| if (serializeIfDefault) { | ||
| block(context.valueExpression) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this only affect clients?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated tests for this only apply to clients: https://github.com/smithy-lang/smithy/pull/2403/files
There are similar tests for the server, but they still indicate that empty headers should not be serialized by the server: https://github.com/smithy-lang/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-headers.smithy#L455
I asked internally about this discrepancy and there didn't seem to be much of a reason for it, so it might be updated in the future to align the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a PR to smithy to update the server tests to align: smithy-lang/smithy#2433