-
Notifications
You must be signed in to change notification settings - Fork 633
fix(codegen): preprocessModel -> map waiter errorType to shapeId if awsQueryError.code #6483
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
aa57647
fix(sdk-codegen): update errorType in waitable traits to use correct …
8e776a9
chore(core): change description to force version update (#6467)
trivikr 361a96d
chore(middleware-flexible-checksums): add config resolver (#6470)
trivikr 92e34cc
chore(clients): populate and resolve flexible checksums client config…
trivikr 82f429d
fix(credential-provider-ini): fix recursive assume role and optional …
kuhe d5f220c
chore(cloudfront-signer): add support for WebSockets (#5827)
mkdynamic 0eb8efe
docs(client-amplify): Doc only update to Amplify to explain platform …
0570d56
docs(client-ivs): Updates to all tags descriptions.
fa578b9
docs(client-ivschat): Updates to all tags descriptions.
dd10581
feat(clients): update client endpoints as of 2024-09-13
ae1b990
Publish v3.651.1
18d0952
chore(deps-dev): bump turbo to v2.1.2 (#6473)
trivikr 3aedc77
chore: disable turborepo telemetry (#6474)
trivikr 656ddb8
docs(client-pca-connector-scep): This is a general availability (GA) …
fe9c0ea
feat(client-rds): Launching Global Cluster tagging.
5c1f071
docs(client-organizations): Doc only update for AWS Organizations tha…
035bd5b
feat(client-medialive): Removing the ON_PREMISE enum from the input s…
b603569
feat(client-iot): This release adds additional enhancements to AWS Io…
b0ff23a
feat(client-bedrock): This feature adds cross account s3 bucket and V…
39d00e7
feat(clients): update client endpoints as of 2024-09-16
35d334d
Publish v3.652.0
54d979c
chore: pass turbo remote cache options in environment variables (#6479)
trivikr e975ad7
chore: show only turbo-computed task hashes in output (#6478)
trivikr b48d955
chore: use yarn for running turbo commands (#6480)
trivikr 3ee6fc7
chore: allow turbo remote cache write only on AWS Codebuild (#6481)
trivikr 5266c94
feat(client-ssm): Support for additional levels of cross-account, cro…
5f7243a
docs(client-ecs): This is a documentation only release to address var…
8dd22e5
feat(client-codebuild): GitLab Enhancements - Add support for Self-Ho…
7cf1ab2
docs(client-rds): Updates Amazon RDS documentation with configuration…
decb970
feat(client-lambda): Support for JSON resource-based policies and blo…
c1da5f6
feat(client-ecr): The `DescribeImageScanning` API now includes `fixAv…
7068ea1
Publish v3.653.0
fc11f25
chore(clients): codegen sync for IDE type navigation (#6490)
kuhe 1d4ebff
fix(middleware-flexible-checksums): use union for new config types (#…
trivikr d34c61f
fix(codegen): fix setting of default signing name (#6487)
kuhe 346b310
feat(client-cost-explorer): This release extends the GetReservationPu…
e641ad8
feat(client-guardduty): Add `launchType` and `sourceIPs` fields to Gu…
6feb5a5
docs(client-rds): Updates Amazon RDS documentation with information u…
33c1376
feat(client-directory-service): Added new APIs for enabling, disablin…
66eca97
feat(client-directory-service-data): Added new AWS Directory Service …
930276a
feat(client-mailmanager): Introduce a new RuleSet condition evaluatio…
5b89838
feat(client-s3): Added SSE-KMS support for directory buckets.
00ad6a3
Publish v3.654.0
87f29e5
feat(client-sagemaker): Introduced support for G6e instance types on …
bacb064
feat(client-quicksight): QuickSight: 1. Add new API - ListFoldersForR…
c920c2d
feat(client-lambda): Tagging support for Lambda event source mapping,…
ff44caa
feat(client-glue): This change is for releasing TestConnection api SD…
1b45166
feat(client-mediaconvert): This release provides support for addition…
ab83f05
feat(client-medialive): Adds Bandwidth Reduction Filtering for HD AVC…
7f2e49b
feat(client-codeconnections): This release adds the PullRequestCommen…
9887384
feat(client-workspaces-web): WorkSpaces Secure Browser now enables Ad…
80a6eae
Publish v3.655.0
afb9535
fix(sdk-codegen): corrected model parsing and awsQuery error code wit…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
...n/src/main/java/software/amazon/smithy/aws/typescript/codegen/ProcessAwsQueryWaiters.java
This file contains hidden or 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,144 @@ | ||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.node.ArrayNode; | ||
import software.amazon.smithy.model.node.Node; | ||
import software.amazon.smithy.model.node.ObjectNode; | ||
import software.amazon.smithy.model.node.StringNode; | ||
import software.amazon.smithy.model.shapes.AbstractShapeBuilder; | ||
import software.amazon.smithy.model.shapes.OperationShape; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
import software.amazon.smithy.model.traits.DynamicTrait; | ||
import software.amazon.smithy.model.traits.Trait; | ||
import software.amazon.smithy.model.transform.ModelTransformer; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; | ||
import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
||
import java.util.*; | ||
|
||
@SmithyInternalApi | ||
public final class ProcessAwsQueryWaiters implements TypeScriptIntegration { | ||
|
||
@Override | ||
public Model preprocessModel(Model model, TypeScriptSettings settings) { | ||
// create mapping of exception shape IDs and awsQuery error code | ||
Map<String, ShapeId> errorCodeToShapeId = new HashMap<>(); | ||
for (Shape shape : model.toSet()) { | ||
RanVaknin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (shape.hasTrait("smithy.api#error") && shape.hasTrait("aws.protocols#awsQueryError")) { | ||
kuhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Optional<Trait> awsQueryTraitOpt = shape.findTrait("aws.protocols#awsQueryError"); | ||
if (awsQueryTraitOpt.isPresent()) { | ||
RanVaknin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Trait awsQueryTrait = awsQueryTraitOpt.get(); | ||
ObjectNode traitValue = awsQueryTrait.toNode().expectObjectNode(); | ||
Optional<Node> memberNodeOpt = traitValue.getMember("code"); | ||
if (memberNodeOpt.isPresent()){ | ||
Optional<StringNode> codeNodeOpt = memberNodeOpt.get().asStringNode(); | ||
if (codeNodeOpt.isPresent()){ | ||
String code = codeNodeOpt.get().getValue(); | ||
kuhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
errorCodeToShapeId.put(code, shape.getId()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
List<Shape> modifiedShapes = new ArrayList<>(); | ||
|
||
for (Shape shape : model.toSet()) { | ||
kuhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Optional<Trait> waitableTraitOpt = shape.findTrait("smithy.waiters#waitable"); | ||
if (waitableTraitOpt.isPresent()) { | ||
kuhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Trait waitableTrait = waitableTraitOpt.get(); | ||
ObjectNode traitValue = waitableTrait.toNode().expectObjectNode(); | ||
ObjectNode.Builder traitValueBuilder = traitValue.toBuilder(); | ||
boolean modified = false; | ||
|
||
for (Map.Entry<StringNode, Node> waiterEntry : traitValue.getMembers().entrySet()) { | ||
StringNode waiterNameNode = waiterEntry.getKey(); | ||
Node waiterNode = waiterEntry.getValue(); | ||
|
||
if (waiterNode.isObjectNode()) { | ||
ObjectNode waiterObject = waiterNode.expectObjectNode(); | ||
ObjectNode.Builder waiterObjectBuilder = waiterObject.toBuilder(); | ||
boolean waiterModified = false; | ||
|
||
Optional<ArrayNode> acceptorsArrayOpt = waiterObject.getArrayMember("acceptors"); | ||
if (acceptorsArrayOpt.isPresent()) { | ||
ArrayNode acceptorsArray = acceptorsArrayOpt.get(); | ||
ArrayNode.Builder acceptorsArrayBuilder = ArrayNode.builder(); | ||
boolean acceptorsModified = false; | ||
|
||
for (Node acceptorNode : acceptorsArray.getElements()) { | ||
if (acceptorNode.isObjectNode()) { | ||
ObjectNode acceptorObject = acceptorNode.expectObjectNode(); | ||
Optional<ObjectNode> matcherObjectOpt = acceptorObject.getObjectMember("matcher"); | ||
if (matcherObjectOpt.isPresent()) { | ||
ObjectNode matcherObject = matcherObjectOpt.get(); | ||
Optional<StringNode> errorTypeNodeOpt = matcherObject.getStringMember("errorType"); | ||
if (errorTypeNodeOpt.isPresent()) { | ||
String errorType = errorTypeNodeOpt.get().getValue(); | ||
ShapeId errorShapeId = errorCodeToShapeId.get(errorType); | ||
if (errorShapeId != null) { | ||
// Replace the errorType value with the shape ID | ||
ObjectNode modifiedMatcherObject = matcherObject.withMember("errorType", Node.from(errorShapeId.toString())); | ||
ObjectNode modifiedAcceptorObject = acceptorObject.withMember("matcher", modifiedMatcherObject); | ||
acceptorsArrayBuilder.withValue(modifiedAcceptorObject); | ||
acceptorsModified = true; | ||
continue; | ||
} | ||
} | ||
} | ||
// If not modified, add the original acceptor | ||
acceptorsArrayBuilder.withValue(acceptorObject); | ||
} else { | ||
acceptorsArrayBuilder.withValue(acceptorNode); | ||
} | ||
} | ||
if (acceptorsModified) { | ||
waiterObjectBuilder.withMember("acceptors", acceptorsArrayBuilder.build()); | ||
waiterModified = true; | ||
} | ||
} | ||
if (waiterModified) { | ||
traitValueBuilder.withMember(waiterNameNode, waiterObjectBuilder.build()); | ||
modified = true; | ||
} | ||
} | ||
} | ||
|
||
if (modified) { | ||
Trait modifiedWaitableTrait = new DynamicTrait(waitableTrait.toShapeId(), traitValueBuilder.build()); | ||
AbstractShapeBuilder<?, ?> shapeBuilder = Shape.shapeToBuilder(shape); | ||
|
||
shapeBuilder.removeTrait(waitableTrait.toShapeId()); | ||
shapeBuilder.addTrait(modifiedWaitableTrait); | ||
Shape modifiedShape = shapeBuilder.build(); | ||
|
||
modifiedShapes.add(modifiedShape); | ||
} | ||
} | ||
} | ||
|
||
// replace the modified shapes in the model | ||
if (!modifiedShapes.isEmpty()) { | ||
ModelTransformer transformer = ModelTransformer.create(); | ||
model = transformer.replaceShapes(model, modifiedShapes); | ||
} | ||
|
||
// print the transformation | ||
for (Shape updatedShape : model.toSet()) { | ||
Optional<Trait> waitableTraitOpt = updatedShape.findTrait("smithy.waiters#waitable"); | ||
if (waitableTraitOpt.isPresent()) { | ||
Trait waitableTrait = waitableTraitOpt.get(); | ||
ObjectNode traitValue = waitableTrait.toNode().expectObjectNode(); | ||
|
||
System.out.println("Waitable trait for shape: " + updatedShape.getId()); | ||
String json = Node.prettyPrintJson(traitValue); | ||
System.out.println(json); | ||
} | ||
} | ||
|
||
return model; | ||
} | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.