From 2e2f44c633298655439adbe3cc38b0022fb38c03 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Wed, 10 May 2023 18:45:07 -0700 Subject: [PATCH] Enable paginators when code generating with the orchestrator (#2688) ## Motivation and Context The paginators were originally turned off for the orchestrator feature flag since there were issues with them, but those issues seem to have been resolved since. This PR re-enables them. ## Testing - [x] Generated the AWS SDK in `orchestrator` mode and verified the paginator tests pass - [x] Added a unit test that validates the paginators compile for generic clients in `orchestrator` mode ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- .../client/FluentClientGenerator.kt | 31 +++++++++---------- .../generators/PaginatorGeneratorTest.kt | 27 +++++++++++++++- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt index c4714038f0..8460a6aaa3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt @@ -458,23 +458,20 @@ class FluentClientGenerator( ) } - // TODO(enableNewSmithyRuntime): Port paginators to the orchestrator - if (smithyRuntimeMode.generateMiddleware) { - PaginatorGenerator.paginatorType(codegenContext, generics, operation, retryClassifier) - ?.also { paginatorType -> - rustTemplate( - """ - /// Create a paginator for this request - /// - /// Paginators are used by calling [`send().await`](#{Paginator}::send) which returns a `Stream`. - pub fn into_paginator(self) -> #{Paginator}${generics.inst} { - #{Paginator}::new(self.handle, self.inner) - } - """, - "Paginator" to paginatorType, - ) - } - } + PaginatorGenerator.paginatorType(codegenContext, generics, operation, retryClassifier) + ?.also { paginatorType -> + rustTemplate( + """ + /// Create a paginator for this request + /// + /// Paginators are used by calling [`send().await`](#{Paginator}::send) which returns a `Stream`. + pub fn into_paginator(self) -> #{Paginator}${generics.inst} { + #{Paginator}::new(self.handle, self.inner) + } + """, + "Paginator" to paginatorType, + ) + } writeCustomizations( customizations, FluentClientSection.FluentBuilderImpl( diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt index 96eff3ad79..f7dbbdafff 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt @@ -6,9 +6,12 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import org.junit.jupiter.api.Test +import software.amazon.smithy.model.node.ObjectNode +import software.amazon.smithy.model.node.StringNode import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.testutil.IntegrationTestParams import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.integrationTest @@ -67,8 +70,9 @@ internal class PaginatorGeneratorTest { } """.asSmithyModel() + // TODO(enableNewSmithyRuntime): Remove this middleware test when launching @Test - fun `generate paginators that compile`() { + fun `generate paginators that compile with middleware`() { clientIntegrationTest(model) { clientCodegenContext, rustCrate -> rustCrate.integrationTest("paginators_generated") { Attribute.AllowUnusedImports.render(this) @@ -76,4 +80,25 @@ internal class PaginatorGeneratorTest { } } } + + private fun enableNewSmithyRuntime(): ObjectNode = ObjectNode.objectNodeBuilder() + .withMember( + "codegen", + ObjectNode.objectNodeBuilder() + .withMember("enableNewSmithyRuntime", StringNode.from("orchestrator")).build(), + ) + .build() + + @Test + fun `generate paginators that compile`() { + clientIntegrationTest( + model, + params = IntegrationTestParams(additionalSettings = enableNewSmithyRuntime()), + ) { clientCodegenContext, rustCrate -> + rustCrate.integrationTest("paginators_generated") { + Attribute.AllowUnusedImports.render(this) + rust("use ${clientCodegenContext.moduleUseName()}::operation::paginated_list::paginator::PaginatedListPaginator;") + } + } + } }