-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-emptively update the S3 model with transform (#3213)
## Motivation and Context S3 models is being updated but this creates issues with examples-compilation. This fixes that issue by pre-emptively updating the model so we can synchronize codegen and examples updates ## Testing - [x] generated S3, verified the same compilation errors ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
- Loading branch information
Showing
5 changed files
with
49 additions
and
2 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
38 changes: 38 additions & 0 deletions
38
.../main/kotlin/software/amazon/smithy/rustsdk/customize/s3/MakeS3BoolsAndNumbersOptional.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,38 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rustsdk.customize.s3 | ||
|
||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.AbstractShapeBuilder | ||
import software.amazon.smithy.model.shapes.BooleanShape | ||
import software.amazon.smithy.model.shapes.NumberShape | ||
import software.amazon.smithy.model.shapes.Shape | ||
import software.amazon.smithy.model.traits.DefaultTrait | ||
import software.amazon.smithy.model.transform.ModelTransformer | ||
|
||
/** | ||
* The s3 model is being updated but if we consume that model update, then we'll run into an issue with examples compilation | ||
* | ||
* This "pre-updates" the model so we can fix examples without requiring complex coordination | ||
*/ | ||
class MakeS3BoolsAndNumbersOptional { | ||
fun processModel(model: Model): Model { | ||
val updates = arrayListOf<Shape>() | ||
for (struct in model.structureShapes) { | ||
for (member in struct.allMembers.values) { | ||
val target = model.expectShape(member.target) | ||
val boolTarget = target as? BooleanShape | ||
val numberTarget = target as? NumberShape | ||
if (boolTarget != null || numberTarget != null) { | ||
updates.add(member.toBuilder().removeTrait(DefaultTrait.ID).build()) | ||
val builder: AbstractShapeBuilder<*, *> = Shape.shapeToBuilder(target) | ||
updates.add(builder.removeTrait(DefaultTrait.ID).build()) | ||
} | ||
} | ||
} | ||
return ModelTransformer.create().replaceShapes(model, updates) | ||
} | ||
} |
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