Skip to content
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

fix: differentiate between string enum and int enum in client correction #1069

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/56a90e2f-014b-4abd-8baa-5ce12dc60320.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "56a90e2f-014b-4abd-8baa-5ce12dc60320",
"type": "bugfix",
"description": "Correctly handle error correction of int enums"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.kotlin.codegen.core.CodegenContext
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
import software.amazon.smithy.kotlin.codegen.model.isEnum
import software.amazon.smithy.kotlin.codegen.model.isStringEnumShape
import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.ShapeType

Expand All @@ -33,8 +33,10 @@ object ClientErrorCorrection {

// In IDL v1 all enums were `ShapeType.STRING` and you had to explicitly check for the @enum trait, this handles
// the differences in IDL versions
if (target.isEnum) {
if (target.isStringEnumShape) {
return writer.format("#T.SdkUnknown(#S)", targetSymbol, "no value provided")
} else if (target.isIntEnumShape) {
return writer.format("#T.SdkUnknown(0)", targetSymbol)
}

return when (target.type) {
Expand Down
9 changes: 9 additions & 0 deletions tests/codegen/nullability-tests/model/nullability.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ structure TestStruct {
@required
enum: Enum

@required
intEnum: IntEnum

@required
union: U

Expand All @@ -77,6 +80,12 @@ enum Enum {
C
}

intEnum IntEnum {
ONE = 1,
TWO = 2,
THREE = 3
}

union U {
A: Integer,
B: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ class ErrorCorrectionTest {

// enums become unknown variant
assertEquals(smithy.kotlin.nullability.clientcareful.model.Enum.SdkUnknown("no value provided"), actual.enum)
assertEquals(smithy.kotlin.nullability.clientcareful.model.IntEnum.SdkUnknown(0), actual.intEnum)
}
}
Loading