-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Smithy generator for paginator #3690
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
Open
kai-ion
wants to merge
16
commits into
main
Choose a base branch
from
paginatorModel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bd04a63
Smithy code gen for pagination
kai-ion 153df50
Smithy code gen for pagination
kai-ion 1461605
updated parser to use c2j mapping names
kai-ion 262eae8
updated writer to use c2j mapping names and deleted space in map.json
kai-ion b647665
fix file location
kai-ion 03c06ef
added a compilation test
kai-ion d58423e
updated cppwriter to use smithy library
kai-ion 7c55bf5
changed parsers to be more generic
kai-ion 6b29534
added service name util
kai-ion 6084c35
filter out deprecated service
kai-ion 6ef01e7
edgecases for backwards compatibility
kai-ion 1eb974f
edgecases for backwards compatibility
kai-ion aabd2e6
temporary fix for AccessAnalyzer which uses service-level pagination …
kai-ion 0ebc50f
temporary fix for amp
kai-ion 14d1c8b
temporary fix for B2BI
kai-ion 619c29a
harded for missing abbreviation trait
kai-ion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
generated/src/aws-cpp-sdk-s3/include/aws/s3/S3ClientPagination.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include <aws/core/utils/pagination/Paginator.h> | ||
| #include <aws/s3/S3Client.h> | ||
| #include <aws/s3/model/pagination/ListBucketsPaginationTraits.h> | ||
| #include <aws/s3/model/pagination/ListDirectoryBucketsPaginationTraits.h> | ||
| #include <aws/s3/model/pagination/ListObjectsV2PaginationTraits.h> | ||
| #include <aws/s3/model/pagination/ListPartsPaginationTraits.h> | ||
|
|
||
| namespace Aws { | ||
| namespace S3 { | ||
|
|
||
| using ListBucketsPaginator = | ||
| Aws::Utils::Pagination::PagePaginator<S3Client, Model::ListBucketsRequest, Pagination::ListBucketsPaginationTraits>; | ||
| using ListDirectoryBucketsPaginator = | ||
| Aws::Utils::Pagination::PagePaginator<S3Client, Model::ListDirectoryBucketsRequest, Pagination::ListDirectoryBucketsPaginationTraits>; | ||
| using ListObjectsV2Paginator = | ||
| Aws::Utils::Pagination::PagePaginator<S3Client, Model::ListObjectsV2Request, Pagination::ListObjectsV2PaginationTraits>; | ||
| using ListPartsPaginator = Aws::Utils::Pagination::PagePaginator<S3Client, Model::ListPartsRequest, Pagination::ListPartsPaginationTraits>; | ||
|
|
||
| } // namespace S3 | ||
| } // namespace Aws |
33 changes: 33 additions & 0 deletions
33
generated/src/aws-cpp-sdk-s3/include/aws/s3/model/pagination/ListBucketsPaginationTraits.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include <aws/s3/S3Client.h> | ||
| #include <aws/s3/S3_EXPORTS.h> | ||
| #include <aws/s3/model/ListBucketsRequest.h> | ||
| #include <aws/s3/model/ListBucketsResult.h> | ||
|
|
||
| namespace Aws { | ||
| namespace S3 { | ||
| namespace Pagination { | ||
|
|
||
| struct ListBucketsPaginationTraits { | ||
| using RequestType = Model::ListBucketsRequest; | ||
| using ResultType = Model::ListBucketsResult; | ||
| using OutcomeType = Model::ListBucketsOutcome; | ||
| using ClientType = S3Client; | ||
|
|
||
| static OutcomeType Invoke(ClientType& client, const RequestType& request) { return client.ListBuckets(request); } | ||
|
|
||
| static bool HasMoreResults(const ResultType& result) { return !result.GetContinuationToken().empty(); } | ||
|
|
||
| static void SetNextRequest(const ResultType& result, RequestType& request) { | ||
| request.SetContinuationToken(result.GetContinuationToken()); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace Pagination | ||
| } // namespace S3 | ||
| } // namespace Aws |
33 changes: 33 additions & 0 deletions
33
...src/aws-cpp-sdk-s3/include/aws/s3/model/pagination/ListDirectoryBucketsPaginationTraits.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include <aws/s3/S3Client.h> | ||
| #include <aws/s3/S3_EXPORTS.h> | ||
| #include <aws/s3/model/ListDirectoryBucketsRequest.h> | ||
| #include <aws/s3/model/ListDirectoryBucketsResult.h> | ||
|
|
||
| namespace Aws { | ||
| namespace S3 { | ||
| namespace Pagination { | ||
|
|
||
| struct ListDirectoryBucketsPaginationTraits { | ||
| using RequestType = Model::ListDirectoryBucketsRequest; | ||
| using ResultType = Model::ListDirectoryBucketsResult; | ||
| using OutcomeType = Model::ListDirectoryBucketsOutcome; | ||
| using ClientType = S3Client; | ||
|
|
||
| static OutcomeType Invoke(ClientType& client, const RequestType& request) { return client.ListDirectoryBuckets(request); } | ||
|
|
||
| static bool HasMoreResults(const ResultType& result) { return !result.GetContinuationToken().empty(); } | ||
|
|
||
| static void SetNextRequest(const ResultType& result, RequestType& request) { | ||
| request.SetContinuationToken(result.GetContinuationToken()); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace Pagination | ||
| } // namespace S3 | ||
| } // namespace Aws |
33 changes: 33 additions & 0 deletions
33
generated/src/aws-cpp-sdk-s3/include/aws/s3/model/pagination/ListObjectsV2PaginationTraits.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include <aws/s3/S3Client.h> | ||
| #include <aws/s3/S3_EXPORTS.h> | ||
| #include <aws/s3/model/ListObjectsV2Request.h> | ||
| #include <aws/s3/model/ListObjectsV2Result.h> | ||
|
|
||
| namespace Aws { | ||
| namespace S3 { | ||
| namespace Pagination { | ||
|
|
||
| struct ListObjectsV2PaginationTraits { | ||
| using RequestType = Model::ListObjectsV2Request; | ||
| using ResultType = Model::ListObjectsV2Result; | ||
| using OutcomeType = Model::ListObjectsV2Outcome; | ||
| using ClientType = S3Client; | ||
|
|
||
| static OutcomeType Invoke(ClientType& client, const RequestType& request) { return client.ListObjectsV2(request); } | ||
|
|
||
| static bool HasMoreResults(const ResultType& result) { return !result.GetNextContinuationToken().empty(); } | ||
|
|
||
| static void SetNextRequest(const ResultType& result, RequestType& request) { | ||
| request.SetContinuationToken(result.GetNextContinuationToken()); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace Pagination | ||
| } // namespace S3 | ||
| } // namespace Aws |
33 changes: 33 additions & 0 deletions
33
generated/src/aws-cpp-sdk-s3/include/aws/s3/model/pagination/ListPartsPaginationTraits.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include <aws/s3/S3Client.h> | ||
| #include <aws/s3/S3_EXPORTS.h> | ||
| #include <aws/s3/model/ListPartsRequest.h> | ||
| #include <aws/s3/model/ListPartsResult.h> | ||
|
|
||
| namespace Aws { | ||
| namespace S3 { | ||
| namespace Pagination { | ||
|
|
||
| struct ListPartsPaginationTraits { | ||
| using RequestType = Model::ListPartsRequest; | ||
| using ResultType = Model::ListPartsResult; | ||
| using OutcomeType = Model::ListPartsOutcome; | ||
| using ClientType = S3Client; | ||
|
|
||
| static OutcomeType Invoke(ClientType& client, const RequestType& request) { return client.ListParts(request); } | ||
|
|
||
| static bool HasMoreResults(const ResultType& result) { return result.GetNextPartNumberMarker() != 0; } | ||
|
|
||
| static void SetNextRequest(const ResultType& result, RequestType& request) { | ||
| request.SetPartNumberMarker(result.GetNextPartNumberMarker()); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace Pagination | ||
| } // namespace S3 | ||
| } // namespace Aws |
25 changes: 25 additions & 0 deletions
25
generated/tests/s3-gen-tests/S3PaginationCompilationTests.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| // Header compilation test for S3 pagination headers | ||
| // This test ensures all generated pagination headers compile successfully | ||
|
|
||
| #include <aws/s3/S3ClientPagination.h> | ||
| #include <aws/s3/model/pagination/ListBucketsPaginationTraits.h> | ||
| #include <aws/s3/model/pagination/ListDirectoryBucketsPaginationTraits.h> | ||
| #include <aws/s3/model/pagination/ListPartsPaginationTraits.h> | ||
| #include <aws/s3/model/pagination/ListObjectsV2PaginationTraits.h> | ||
|
|
||
| #include <aws/testing/AwsCppSdkGTestSuite.h> | ||
|
|
||
| class S3PaginationCompilationTest : public Aws::Testing::AwsCppSdkGTestSuite | ||
| { | ||
| }; | ||
|
|
||
| TEST_F(S3PaginationCompilationTest, S3PaginationHeadersCompile) | ||
| { | ||
| // Test passes if compilation succeeds | ||
| SUCCEED(); | ||
| } |
18 changes: 18 additions & 0 deletions
18
tools/code-generation/smithy/codegen/cpp-pagination-codegen/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| plugins { | ||
| `java-library` | ||
| } | ||
|
|
||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation("software.amazon.smithy:smithy-model:1.51.0") | ||
| implementation("software.amazon.smithy:smithy-codegen-core:1.51.0") | ||
| implementation("software.amazon.smithy:smithy-aws-traits:1.51.0") | ||
| implementation("software.amazon.smithy:smithy-waiters:1.51.0") | ||
| implementation("software.amazon.smithy:smithy-rules-engine:1.51.0") | ||
| implementation("software.amazon.smithy:smithy-aws-endpoints:1.51.0") | ||
| implementation("software.amazon.smithy:smithy-aws-iam-traits:1.51.0") | ||
| } |
20 changes: 20 additions & 0 deletions
20
...in/java/com/amazonaws/util/awsclientsmithygenerator/generators/ClientCodegenSettings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
| package com.amazonaws.util.awsclientsmithygenerator.generators; | ||
|
|
||
| import software.amazon.smithy.model.node.ObjectNode; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
|
|
||
| public class ClientCodegenSettings { | ||
| private final ShapeId service; | ||
|
|
||
| public ClientCodegenSettings(ObjectNode settings) { | ||
| this.service = ShapeId.from(settings.expectStringMember("service").getValue()); | ||
| } | ||
|
|
||
| public ShapeId getService() { | ||
| return service; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
...in/java/com/amazonaws/util/awsclientsmithygenerator/generators/CompilationTestParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
| package com.amazonaws.util.awsclientsmithygenerator.generators; | ||
|
|
||
| import software.amazon.smithy.build.PluginContext; | ||
| import software.amazon.smithy.model.shapes.*; | ||
| import software.amazon.smithy.aws.traits.ServiceTrait; | ||
| import com.amazonaws.util.awsclientsmithygenerator.generators.CppWriter; | ||
| import com.amazonaws.util.awsclientsmithygenerator.generators.ServiceNameUtil; | ||
| import java.util.*; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public class CompilationTestParser<T> { | ||
| private final ServiceShape service; | ||
| private final CppWriterDelegator writerDelegator; | ||
| private final String testType; | ||
| private final Consumer<CppWriter> renderFunction; | ||
| private final Map<String, String> c2jMap; | ||
|
|
||
| public CompilationTestParser(PluginContext context, ServiceShape service, List<T> operations, | ||
| String testType, Consumer<CppWriter> renderFunction, Map<String, String> c2jMap) { | ||
| this.service = service; | ||
| this.writerDelegator = new CppWriterDelegator(context.getFileManifest()); | ||
| this.testType = testType; | ||
| this.renderFunction = renderFunction; | ||
| this.c2jMap = c2jMap; | ||
| } | ||
|
|
||
| public void run() { | ||
| generateCompilationTest(); | ||
| writerDelegator.flushWriters(); | ||
| } | ||
|
|
||
| private void generateCompilationTest() { | ||
| String serviceName = ServiceNameUtil.getServiceName(service); | ||
| String c2jServiceName = ServiceNameUtil.getC2jServiceName(service, c2jMap); | ||
|
|
||
| writerDelegator.useFileWriter( | ||
| "generated/tests/" + c2jServiceName + "-gen-tests/" + serviceName + testType + "CompilationTests.cpp", | ||
| renderFunction | ||
| ); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
.../main/java/com/amazonaws/util/awsclientsmithygenerator/generators/CppImportContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
| package com.amazonaws.util.awsclientsmithygenerator.generators; | ||
|
|
||
| import software.amazon.smithy.codegen.core.ImportContainer; | ||
| import software.amazon.smithy.codegen.core.Symbol; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * CppImportContainer tracks symbols used in code generation. | ||
| * For C++, we handle includes manually via writeInclude method. | ||
| */ | ||
| public class CppImportContainer implements ImportContainer { | ||
| private final Set<String> imports = new HashSet<>(); | ||
|
|
||
| @Override | ||
| public void importSymbol(Symbol symbol, String alias) { | ||
| // Track the symbol's namespace for potential future use | ||
| if (symbol.getNamespace() != null && !symbol.getNamespace().isEmpty()) { | ||
| imports.add(symbol.getNamespace()); | ||
| } | ||
| } | ||
|
|
||
| public Set<String> getImports() { | ||
| return imports; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| // Return empty string since we handle includes manually | ||
| return ""; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
...degen/src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/CppWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
| package com.amazonaws.util.awsclientsmithygenerator.generators; | ||
|
|
||
| import software.amazon.smithy.codegen.core.SymbolWriter; | ||
|
|
||
| public class CppWriter extends SymbolWriter<CppWriter, CppImportContainer> { | ||
|
|
||
| public CppWriter() { | ||
| super(new CppImportContainer()); | ||
|
|
||
| // Add custom formatter for symbols | ||
| putFormatter('T', (arg, indent) -> { | ||
| if (!(arg instanceof software.amazon.smithy.codegen.core.Symbol symbol)) { | ||
| throw new software.amazon.smithy.codegen.core.CodegenException("Expected a symbol but got " + arg); | ||
| } | ||
|
|
||
| // Record our symbol so we can generate appropriate includes later if needed | ||
| getImportContainer().importSymbol(symbol, null); | ||
|
|
||
| // For C++, use namespace::name syntax (e.g. Aws::S3::Model::ListBucketsRequest) | ||
| if (symbol.getNamespace() != null && !symbol.getNamespace().isEmpty()) { | ||
| return symbol.getNamespace() + "::" + symbol.getName(); | ||
| } | ||
| return symbol.getName(); | ||
| }); | ||
| } | ||
|
|
||
| public CppWriter writeInclude(String header) { | ||
| write("#include <$L>", header); | ||
| return this; | ||
| } | ||
|
|
||
| public CppWriter writeNamespaceOpen(String namespace) { | ||
| openBlock("namespace $L\n{", namespace); | ||
| return this; | ||
| } | ||
|
|
||
| public CppWriter writeNamespaceClose(String namespace) { | ||
| closeBlock("} // namespace $L", namespace); | ||
| return this; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being a bit nitpicky but Instead of manually opening and closing namespace blocks, why don't we do something like this:
and the same for
writeNamespaceClose, but withwriter.closeBlock. Its functionally the exact same (block functions indent/dedent which doesn't matter since we clang format anyway) , but we should try to use these functions when opening/closing blocks