-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into filter-deprecated
- Loading branch information
Showing
20 changed files
with
322 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
52 changes: 52 additions & 0 deletions
52
smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenPaginationInfo.java
This file contains 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,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.model.transform; | ||
|
||
import java.util.HashSet; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.knowledge.PaginatedIndex; | ||
import software.amazon.smithy.model.knowledge.PaginationInfo; | ||
import software.amazon.smithy.model.shapes.OperationShape; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
import software.amazon.smithy.model.traits.PaginatedTrait; | ||
|
||
/** | ||
* Flattens pagination info from service shapes into operation-level pagination traits. | ||
*/ | ||
final class FlattenPaginationInfo { | ||
|
||
private final ServiceShape service; | ||
|
||
FlattenPaginationInfo(ServiceShape service) { | ||
this.service = service; | ||
} | ||
|
||
public Model transform(ModelTransformer transformer, Model model) { | ||
Optional<PaginatedTrait> serviceLevelPagination = service.getTrait(PaginatedTrait.class); | ||
if (!serviceLevelPagination.isPresent()) { | ||
return model; | ||
} | ||
PaginatedIndex paginatedIndex = PaginatedIndex.of(model); | ||
|
||
// Merge service-level information into each operation's pagination trait. | ||
Set<Shape> updatedShapes = new HashSet<>(); | ||
for (OperationShape operationShape : model.getOperationShapesWithTrait(PaginatedTrait.class)) { | ||
PaginationInfo paginationInfo = paginatedIndex.getPaginationInfo(service, operationShape).get(); | ||
OperationShape updatedShape = operationShape.toBuilder() | ||
.addTrait(paginationInfo.getPaginatedTrait()) | ||
.build(); | ||
updatedShapes.add(updatedShape); | ||
} | ||
|
||
// Remove the paginated trait from the service as it's info has been flattened into the operations | ||
updatedShapes.add(service.toBuilder().removeTrait(PaginatedTrait.ID).build()); | ||
|
||
return transformer.replaceShapes(model, updatedShapes); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.