-
Notifications
You must be signed in to change notification settings - Fork 49
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' of github.com:awslabs/aws-sdk-kotlin into feat-gp…
…-anno
- Loading branch information
Showing
68 changed files
with
13,233 additions
and
2,498 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
55 changes: 55 additions & 0 deletions
55
.../src/main/kotlin/aws/sdk/kotlin/codegen/customization/PaginationEndBehaviorIntegration.kt
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,55 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.codegen.customization | ||
|
||
import software.amazon.smithy.kotlin.codegen.KotlinSettings | ||
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration | ||
import software.amazon.smithy.kotlin.codegen.model.traits.PaginationEndBehavior | ||
import software.amazon.smithy.kotlin.codegen.model.traits.PaginationEndBehaviorTrait | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.BooleanShape | ||
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.model.shapes.StructureShape | ||
import software.amazon.smithy.model.transform.ModelTransformer | ||
|
||
private val TRUNCATION_MEMBER_IDS = mapOf( | ||
"com.amazonaws.s3#ListParts" to "IsTruncated", | ||
) | ||
|
||
private val IDENTICAL_TOKEN_OPERATION_IDS = setOf( | ||
"com.amazonaws.cloudwatchlogs#GetLogEvents", // https://github.com/awslabs/aws-sdk-kotlin/issues/1326 | ||
) | ||
|
||
/** | ||
* Applies [PaginationEndBehaviorTrait] to a manually-curated list of operations/members for which pagination terminates | ||
* in a non-standard manner | ||
*/ | ||
class PaginationEndBehaviorIntegration : KotlinIntegration { | ||
override fun preprocessModel(model: Model, settings: KotlinSettings): Model = ModelTransformer | ||
.create() | ||
.mapShapes(model) { shape -> | ||
val shapeId = shape.id.toString() | ||
when { | ||
shape !is OperationShape -> shape // Pagination behavior trait only applied to operations | ||
|
||
shapeId in TRUNCATION_MEMBER_IDS -> { | ||
val output = model.expectShape(shape.outputShape) | ||
require(output is StructureShape) { "Operation output must be a structure shape" } | ||
val memberName = TRUNCATION_MEMBER_IDS.getValue(shapeId) | ||
val member = output.allMembers[memberName] ?: error("Cannot find $memberName in ${output.id}") | ||
val target = model.expectShape(member.target) | ||
check(target is BooleanShape) { "Truncation member must be a boolean shape" } | ||
|
||
val behavior = PaginationEndBehavior.TruncationMember(memberName) | ||
shape.toBuilder().addTrait(PaginationEndBehaviorTrait(behavior)).build() | ||
} | ||
|
||
shapeId in IDENTICAL_TOKEN_OPERATION_IDS -> | ||
shape.toBuilder().addTrait(PaginationEndBehaviorTrait(PaginationEndBehavior.IdenticalToken)).build() | ||
|
||
else -> shape | ||
} | ||
} | ||
} |
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.