From 30002d0c9daa02371a3f2f5d8994ff75f85fa627 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 13 Feb 2025 14:57:32 -0500 Subject: [PATCH 1/3] misc: test union with member that has the same name --- .../amazon/smithy/kotlin/codegen/SmithySdkTest.kt | 11 +++++++++++ .../src/test/resources/kitchen-sink-model.smithy | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt b/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt index 8cad9fc623..2bbd656515 100644 --- a/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt +++ b/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt @@ -224,6 +224,17 @@ class SmithySdkTest { assertEquals(KotlinCompilation.ExitCode.OK, compilationResult.exitCode, compileOutputStream.toString()) } + + @Test + fun `it compiles models with unions with members that have the same name as the union`() { + val model = javaClass.getResource("/kitchen-sink-model.smithy")!!.asSmithy() + + val compileOutputStream = ByteArrayOutputStream() + val compilationResult = compileSdkAndTest(model = model, outputSink = compileOutputStream, emitSourcesToTmp = Debug.emitSourcesToTemp) + compileOutputStream.flush() + + assertEquals(KotlinCompilation.ExitCode.OK, compilationResult.exitCode, compileOutputStream.toString()) + } } /** diff --git a/tests/compile/src/test/resources/kitchen-sink-model.smithy b/tests/compile/src/test/resources/kitchen-sink-model.smithy index b5643d3fe7..4a4d563463 100644 --- a/tests/compile/src/test/resources/kitchen-sink-model.smithy +++ b/tests/compile/src/test/resources/kitchen-sink-model.smithy @@ -59,7 +59,13 @@ structure SmokeTestRequest { payload1: String, payload2: Integer, - payload3: Nested + payload3: Nested, + + nestedUnion: NestedUnion +} + +union NestedUnion { + nestedUnion: Boolean } structure Nested { From bd9ceb4e4c54261470fd0b78145292015a4fac47 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 13 Feb 2025 15:03:31 -0500 Subject: [PATCH 2/3] misc: move model to unit test --- .../smithy/kotlin/codegen/SmithySdkTest.kt | 29 ++++++++++++++++++- .../test/resources/kitchen-sink-model.smithy | 8 +---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt b/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt index 2bbd656515..d5ad59599d 100644 --- a/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt +++ b/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt @@ -227,7 +227,34 @@ class SmithySdkTest { @Test fun `it compiles models with unions with members that have the same name as the union`() { - val model = javaClass.getResource("/kitchen-sink-model.smithy")!!.asSmithy() + val model = """ + namespace aws.sdk.kotlin.test + + use aws.protocols#awsJson1_0 + use smithy.rules#operationContextParams + use smithy.rules#endpointRuleSet + use aws.api#service + + @awsJson1_0 + @service(sdkId: "UnionOperationTest") + service TestService { + operations: [UnionOperation], + version: "1" + } + + operation UnionOperation { + input: UnionOperationRequest + } + + structure UnionOperationRequest { + Union: Foo + } + + union Foo { + foo: Boolean + } + + """.asSmithy() val compileOutputStream = ByteArrayOutputStream() val compilationResult = compileSdkAndTest(model = model, outputSink = compileOutputStream, emitSourcesToTmp = Debug.emitSourcesToTemp) diff --git a/tests/compile/src/test/resources/kitchen-sink-model.smithy b/tests/compile/src/test/resources/kitchen-sink-model.smithy index 4a4d563463..b5643d3fe7 100644 --- a/tests/compile/src/test/resources/kitchen-sink-model.smithy +++ b/tests/compile/src/test/resources/kitchen-sink-model.smithy @@ -59,13 +59,7 @@ structure SmokeTestRequest { payload1: String, payload2: Integer, - payload3: Nested, - - nestedUnion: NestedUnion -} - -union NestedUnion { - nestedUnion: Boolean + payload3: Nested } structure Nested { From 6da3219a168ccd74312a35af108fab7da8516b68 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 13 Feb 2025 15:52:58 -0500 Subject: [PATCH 3/3] misc: add GH PR link --- .../software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt b/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt index d5ad59599d..8adeb29cbf 100644 --- a/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt +++ b/tests/compile/src/test/kotlin/software/amazon/smithy/kotlin/codegen/SmithySdkTest.kt @@ -225,6 +225,7 @@ class SmithySdkTest { assertEquals(KotlinCompilation.ExitCode.OK, compilationResult.exitCode, compileOutputStream.toString()) } + // https://github.com/smithy-lang/smithy-kotlin/issues/1129 @Test fun `it compiles models with unions with members that have the same name as the union`() { val model = """