From 487d1fc026405ef5fdba1b789bb26bb19f0caa27 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 26 Sep 2024 17:09:54 -0400 Subject: [PATCH] Add non sparse map test --- .../rendering/PaginatorGeneratorTest.kt | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/PaginatorGeneratorTest.kt b/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/PaginatorGeneratorTest.kt index 0dafcdb9c..7b08a6d86 100644 --- a/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/PaginatorGeneratorTest.kt +++ b/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/PaginatorGeneratorTest.kt @@ -1143,4 +1143,80 @@ class PaginatorGeneratorTest { """.trimIndent() actual.shouldContainOnlyOnceWithDiff(expectedCode) } + + @Test + fun testRenderPaginatorWithStringMap() { + val testModelWithItems = """ + namespace com.test + + use aws.protocols#restJson1 + + service Lambda { + operations: [ListFunctions] + } + + @paginated( + inputToken: "Marker", + outputToken: "NextMarker", + pageSize: "MaxItems", + items: "Functions" + ) + @readonly + @http(method: "GET", uri: "/functions", code: 200) + operation ListFunctions { + input: ListFunctionsRequest, + output: ListFunctionsResponse + } + + structure ListFunctionsRequest { + @httpQuery("FunctionVersion") + FunctionVersion: String, + @httpQuery("Marker") + Marker: String, + @httpQuery("MasterRegion") + MasterRegion: String, + @httpQuery("MaxItems") + MaxItems: Integer + } + + structure ListFunctionsResponse { + Functions: FunctionConfigurationMap, + NextMarker: String + } + + map FunctionConfigurationMap { + key: String + value: FunctionConfiguration + } + + string FunctionConfiguration + """.toSmithyModel() + val testContextWithItems = testModelWithItems.newTestContext("Lambda", "com.test") + + val codegenContextWithItems = object : CodegenContext { + override val model: Model = testContextWithItems.generationCtx.model + override val symbolProvider: SymbolProvider = testContextWithItems.generationCtx.symbolProvider + override val settings: KotlinSettings = testContextWithItems.generationCtx.settings + override val protocolGenerator: ProtocolGenerator = testContextWithItems.generator + override val integrations: List = testContextWithItems.generationCtx.integrations + } + + val unit = PaginatorGenerator() + unit.writeAdditionalFiles(codegenContextWithItems, testContextWithItems.generationCtx.delegator) + + testContextWithItems.generationCtx.delegator.flushWriters() + val testManifest = testContextWithItems.generationCtx.delegator.fileManifest as MockManifest + val actual = testManifest.expectFileString("src/main/kotlin/com/test/paginators/Paginators.kt") + + val expectedCode = """ + @JvmName("listFunctionsResponseFunctionConfigurationMap") + public fun Flow.functions(): Flow> = + transform() { response -> + response.functions?.forEach { + emit(it) + } + } + """.trimIndent() + actual.shouldContainOnlyOnceWithDiff(expectedCode) + } }