Skip to content
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

fix: add IsTruncated pagination customization for S3 ListParts #1245

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.aws.swift.codegen.customization.s3

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.swift.codegen.SwiftSettings
import software.amazon.smithy.swift.codegen.customtraits.PaginationTruncationMember
import software.amazon.smithy.swift.codegen.integration.SwiftIntegration
import software.amazon.smithy.swift.codegen.model.expectShape

private val TRUNCATION_MEMBER_IDS = setOf(
"com.amazonaws.s3#ListPartsOutput\$IsTruncated",
)

/**
* Applies the [PaginationTruncationMember] annotation to a manually-curated list of operations and members to handle
* non-standard pagination termination conditions.
*/
class TruncatablePaginationIntegration : SwiftIntegration {
override fun enabledForService(model: Model, settings: SwiftSettings): Boolean =
model.expectShape<ServiceShape>(settings.service).isS3

override fun preprocessModel(model: Model, settings: SwiftSettings): Model = ModelTransformer
.create()
.mapShapes(model) { shape ->
when {
shape.id.toString() in TRUNCATION_MEMBER_IDS -> {
check(shape is MemberShape) { "Cannot apply PaginationTruncationMember to non-member shape" }
shape.toBuilder().addTrait(PaginationTruncationMember()).build()
}
else -> shape
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
software.amazon.smithy.aws.swift.codegen.AddProtocols
software.amazon.smithy.aws.swift.codegen.customization.s3.S3ErrorIntegration
software.amazon.smithy.aws.swift.codegen.customization.s3.S3Expires
software.amazon.smithy.aws.swift.codegen.customization.s3.TruncatablePaginationIntegration
software.amazon.smithy.aws.swift.codegen.customization.route53.Route53TrimHostedZone
software.amazon.smithy.aws.swift.codegen.customization.route53.Route53InvalidBatchErrorIntegration
software.amazon.smithy.aws.swift.codegen.customization.apigateway.ApiGatewayAddAcceptHeader
Expand Down
Loading