-
Notifications
You must be signed in to change notification settings - Fork 31
feat: enum and int enums as event headers #1443
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
Conversation
This comment has been minimized.
This comment has been minimized.
when (target.type) { | ||
ShapeType.ENUM, ShapeType.INT_ENUM -> { | ||
writer.write( | ||
"?.let { #T.fromValue(it) }", | ||
targetSymbol, | ||
) | ||
} | ||
else -> writer.write("") | ||
} |
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.
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
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 don't think we can, since the conversion functions are not code-generated, I'm not sure how it would replace #T.fromValue(it)
.
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.
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
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.
Please add some unit tests to cover this new behavior.
@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.
This comment has been minimized.
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) |
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.
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)) }"""
/** | ||
* A concrete implementation of AwsHttpBindingProtocolGenerator to exercise: | ||
* renderThrowOperationError() | ||
* getProtocolHttpBindingResolver() | ||
*/ | ||
class TestableAwsHttpBindingProtocolGenerator : AwsHttpBindingProtocolGenerator() { |
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.
Comment: Thanks for adding new KDocs to old code!
Affected ArtifactsChanged in size
|
Implemented requested changes and already got required approvals.
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.