Skip to content

Conversation

0marperez
Copy link
Contributor

Issue #

N/A

Description of changes

Supports smithy enums and int enums as event headers

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This comment has been minimized.

Comment on lines 171 to 179
when (target.type) {
ShapeType.ENUM, ShapeType.INT_ENUM -> {
writer.write(
"?.let { #T.fromValue(it) }",
targetSymbol,
)
}
else -> writer.write("")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplification: Can this ?.let { #T.fromValue(it) } be made part of the conversionFn for enum and int enum? It feels wrong to have extra logic doing type conversion when we already have conversionFn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can, since the conversion functions are not code-generated, I'm not sure how it would replace #T.fromValue(it).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like this should be possible:

@InternalApi
fun <T> HeaderValue.expectEnumValue(fromValue: (String) -> T): T {
    val stringValue = expectString()
    return fromValue(stringValue)
}

it's not a strong opinion but I think this could be done cleaner

Copy link
Contributor

@ianbotsf ianbotsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some unit tests to cover this new behavior.

@0marperez
Copy link
Contributor Author

@ianbotsf I added some codegen tests downstream: aws/aws-sdk-kotlin#1710. I'm not sure if you saw them.

@ianbotsf
Copy link
Contributor

@ianbotsf I added some codegen tests downstream: aws/aws-sdk-kotlin#1710. I'm not sure if you saw them.

Those are great but smithy-kotlin will soon have other use cases besides the SDK. We should ensure this repo is capable of testing all of its features, whether the SDK uses them or not.

This comment has been minimized.

Comment on lines 142 to 152
val expectedEnumSerializer = "input.value.enum?.let { addHeader(\"enum\", HeaderValue.String(it.value)) }"
val expectedIntEnumSerializer = "input.value.intEnum?.let { addHeader(\"intEnum\", HeaderValue.Int32(it.value)) }"
val actualSerializer = testCtx.manifest.expectFileString("src/main/kotlin/com/test/serde/TestStreamOpOperationSerializer.kt")
actualSerializer.shouldContainOnlyOnceWithDiff(expectedEnumSerializer)
actualSerializer.shouldContainOnlyOnceWithDiff(expectedIntEnumSerializer)

val expectedEnumDeserializer = "eb.enum = message.headers.find { it.name == \"enum\" }?.value?.expectEnumValue(Enum::fromValue)"
val expectedIntEnumDeserializer = "eb.intEnum = message.headers.find { it.name == \"intEnum\" }?.value?.expectIntEnumValue(IntEnum::fromValue)"
val actualDeserializer = testCtx.manifest.expectFileString("src/main/kotlin/com/test/serde/TestStreamOpOperationDeserializer.kt")
actualDeserializer.shouldContainOnlyOnceWithDiff(expectedEnumDeserializer)
actualDeserializer.shouldContainOnlyOnceWithDiff(expectedIntEnumDeserializer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Strings with double-quotes inside are generally more readable with triple quotes, which don't require escaping. For example:

// harder to read
val expectedEnumSerializer = "input.value.enum?.let { addHeader(\"enum\", HeaderValue.String(it.value)) }"

// easier to read
val expectedEnumSerializer = """input.value.enum?.let { addHeader("enum", HeaderValue.String(it.value)) }"""

Comment on lines +155 to 160
/**
* A concrete implementation of AwsHttpBindingProtocolGenerator to exercise:
* renderThrowOperationError()
* getProtocolHttpBindingResolver()
*/
class TestableAwsHttpBindingProtocolGenerator : AwsHttpBindingProtocolGenerator() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: Thanks for adding new KDocs to old code!

Copy link

Affected Artifacts

Changed in size
Artifact Pull Request (bytes) Latest Release (bytes) Delta (bytes) Delta (percentage)
aws-event-stream-jvm.jar 85,140 84,814 326 0.38%

@0marperez 0marperez dismissed lauzadis’s stale review October 17, 2025 22:36

Implemented requested changes and already got required approvals.

@0marperez 0marperez merged commit f169b9f into main Oct 17, 2025
36 of 37 checks passed
@0marperez 0marperez deleted the enums-event-header branch October 17, 2025 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants