Skip to content

Commit

Permalink
Enable paginators when code generating with the orchestrator (#2688)
Browse files Browse the repository at this point in the history
## 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._
  • Loading branch information
jdisanti authored and david-perez committed May 22, 2023
1 parent 9495ef9 commit 2e2f44c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -67,13 +70,35 @@ 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)
rust("use ${clientCodegenContext.moduleUseName()}::operation::paginated_list::paginator::PaginatedListPaginator;")
}
}
}

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;")
}
}
}
}

0 comments on commit 2e2f44c

Please sign in to comment.