Repository navigation
Translate paginators on the Smithy path - #7463
Conversation
The Smithy builder passed an empty paginator map and never set isPaginated, so no paginator classes or xxxPaginator() client methods were generated from a Smithy model. AddSmithyPaginators builds the map from each operation's @paginated trait, with the service's @paginated filling the members the operation leaves out, as Smithy's PaginatedIndex does. A new codegen trait, paginatorOverride, replaces that translation for paginators @paginated cannot express (several tokens, moreResults, several result keys), or with skip, drops the paginator. The builder sets isPaginated with the rule C2J's AddOperations uses, so the client methods and paginator classes agree, and removes paginators of deprecatedOperations as the C2J builder does.
| if (!skip && (isNullOrEmpty(inputToken) || isNullOrEmpty(outputToken))) { | ||
| throw new ExpectationNotMetException( | ||
| ID + " needs inputToken and outputToken unless skip is true. Remove the trait to use @paginated.", node); | ||
| } |
There was a problem hiding this comment.
Should this validation also require inputToken and outputToken to have the same size? The paginator generator pairs them by index, so mismatched lists could cause generation failures or unused tokens ?
| inputToken: PaginatorMemberPaths | ||
| outputToken: PaginatorMemberPaths | ||
| resultKey: PaginatorMemberPaths | ||
| moreResults: String |
There was a problem hiding this comment.
Should moreResults be validated to reference a Boolean member? Generated paginator code calls booleanValue() on its getter, while current validation only checks that the member exists
There was a problem hiding this comment.
Nice catch! Though this and the above behavior are all c2j behavior today. And no model in our current repo violates that. if we are going to add it, we probably will add this for both smithy path and c2j path. I can take a note on that.
6c5d151
into
feature/master/smithy-migration
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
Motivation and Context
For now on the Smithy path, the step that builds the intermediate model passed an empty paginator map and never marked an operation as paginated. So a client generated from a Smithy model had no paginator classes (such as
ListThingsIterableandListThingsPublisher) and nolistThingsPaginator(...)client methods.This PR fills that gap. Smithy describes pagination with the
@paginatedtrait on an operation, for example:@paginatedcovers most paginators, but not everythingpaginators-1.jsoncan say. Inpaginators-1.json:ListObjectVersionsusesKeyMarkerandVersionIdMarker.more_results, such as IAM'sIsTruncated) rather than on a missing token.DescribeAlarmsreturnsMetricAlarms,CompositeAlarms, andLogAlarms.@paginatedallows one token each way, no stop field, and oneitemspath. For those paginators, this PR adds a codegen trait,software.amazon.awssdk.codegen#paginatorOverride. It carries thepaginators-1.jsonfields on the operation, so the generated paginator stays the same as on the C2J path. It sits alongside the existing Java-only codegen traits and is applied throughsmithy-build.json, so the service'smodel.jsonis not edited. Withskip: true, the trait generates no paginator, for an operation that has@paginatedbut no paginator on the C2J path. We can modify this in the future.Modifications
paginatorOverridetrait: the definition inaws-sdk-java-codegen-traits.smithyand the classPaginatorOverrideTrait, registered as aTraitService.skip: truealone, or non-emptyinputTokenandoutputTokenlists, plus optionalresultKey,moreResults, andlimitKey.AddSmithyPaginators: builds the paginator map, keyed by operation name as inpaginators-1.json.paginatorOverridewins.@paginatedis translated:inputTokenandoutputTokenbecome single-element lists,itemsbecomesresultKey, andpageSizebecomeslimitKey.@paginatedfills in members the operation leaves out, as Smithy'sPaginatedIndexdoes.SmithyIntermediateModelBuilder:deprecatedOperations, as the C2J path does.Not in this PR:
paginatorOverrideentries from a service'spaginators-1.jsonintosmithy-build.jsonbelongs with the tool that generatessmithy-build.jsonfromcustomization.config. Until then, asmithy-build.jsonwithout the overrides falls back to translating@paginated.Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License