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(codegen): preprocessModel -> map waiter errorType to shapeId if awsQueryError.code #6483

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 …
Sep 17, 2024
8e776a9
chore(core): change description to force version update (#6467)
trivikr Sep 12, 2024
361a96d
chore(middleware-flexible-checksums): add config resolver (#6470)
trivikr Sep 13, 2024
92e34cc
chore(clients): populate and resolve flexible checksums client config…
trivikr Sep 13, 2024
82f429d
fix(credential-provider-ini): fix recursive assume role and optional …
kuhe Sep 13, 2024
d5f220c
chore(cloudfront-signer): add support for WebSockets (#5827)
mkdynamic Sep 13, 2024
0eb8efe
docs(client-amplify): Doc only update to Amplify to explain platform …
Sep 13, 2024
0570d56
docs(client-ivs): Updates to all tags descriptions.
Sep 13, 2024
fa578b9
docs(client-ivschat): Updates to all tags descriptions.
Sep 13, 2024
dd10581
feat(clients): update client endpoints as of 2024-09-13
Sep 13, 2024
ae1b990
Publish v3.651.1
Sep 13, 2024
18d0952
chore(deps-dev): bump turbo to v2.1.2 (#6473)
trivikr Sep 16, 2024
3aedc77
chore: disable turborepo telemetry (#6474)
trivikr Sep 16, 2024
656ddb8
docs(client-pca-connector-scep): This is a general availability (GA) …
Sep 16, 2024
fe9c0ea
feat(client-rds): Launching Global Cluster tagging.
Sep 16, 2024
5c1f071
docs(client-organizations): Doc only update for AWS Organizations tha…
Sep 16, 2024
035bd5b
feat(client-medialive): Removing the ON_PREMISE enum from the input s…
Sep 16, 2024
b603569
feat(client-iot): This release adds additional enhancements to AWS Io…
Sep 16, 2024
b0ff23a
feat(client-bedrock): This feature adds cross account s3 bucket and V…
Sep 16, 2024
39d00e7
feat(clients): update client endpoints as of 2024-09-16
Sep 16, 2024
35d334d
Publish v3.652.0
Sep 16, 2024
54d979c
chore: pass turbo remote cache options in environment variables (#6479)
trivikr Sep 16, 2024
e975ad7
chore: show only turbo-computed task hashes in output (#6478)
trivikr Sep 16, 2024
b48d955
chore: use yarn for running turbo commands (#6480)
trivikr Sep 16, 2024
3ee6fc7
chore: allow turbo remote cache write only on AWS Codebuild (#6481)
trivikr Sep 16, 2024
5266c94
feat(client-ssm): Support for additional levels of cross-account, cro…
Sep 17, 2024
5f7243a
docs(client-ecs): This is a documentation only release to address var…
Sep 17, 2024
8dd22e5
feat(client-codebuild): GitLab Enhancements - Add support for Self-Ho…
Sep 17, 2024
7cf1ab2
docs(client-rds): Updates Amazon RDS documentation with configuration…
Sep 17, 2024
decb970
feat(client-lambda): Support for JSON resource-based policies and blo…
Sep 17, 2024
c1da5f6
feat(client-ecr): The `DescribeImageScanning` API now includes `fixAv…
Sep 17, 2024
7068ea1
Publish v3.653.0
Sep 17, 2024
fc11f25
chore(clients): codegen sync for IDE type navigation (#6490)
kuhe Sep 17, 2024
1d4ebff
fix(middleware-flexible-checksums): use union for new config types (#…
trivikr Sep 17, 2024
d34c61f
fix(codegen): fix setting of default signing name (#6487)
kuhe Sep 18, 2024
346b310
feat(client-cost-explorer): This release extends the GetReservationPu…
Sep 18, 2024
e641ad8
feat(client-guardduty): Add `launchType` and `sourceIPs` fields to Gu…
Sep 18, 2024
6feb5a5
docs(client-rds): Updates Amazon RDS documentation with information u…
Sep 18, 2024
33c1376
feat(client-directory-service): Added new APIs for enabling, disablin…
Sep 18, 2024
66eca97
feat(client-directory-service-data): Added new AWS Directory Service …
Sep 18, 2024
930276a
feat(client-mailmanager): Introduce a new RuleSet condition evaluatio…
Sep 18, 2024
5b89838
feat(client-s3): Added SSE-KMS support for directory buckets.
Sep 18, 2024
00ad6a3
Publish v3.654.0
Sep 18, 2024
87f29e5
feat(client-sagemaker): Introduced support for G6e instance types on …
Sep 19, 2024
bacb064
feat(client-quicksight): QuickSight: 1. Add new API - ListFoldersForR…
Sep 19, 2024
c920c2d
feat(client-lambda): Tagging support for Lambda event source mapping,…
Sep 19, 2024
ff44caa
feat(client-glue): This change is for releasing TestConnection api SD…
Sep 19, 2024
1b45166
feat(client-mediaconvert): This release provides support for addition…
Sep 19, 2024
ab83f05
feat(client-medialive): Adds Bandwidth Reduction Filtering for HD AVC…
Sep 19, 2024
7f2e49b
feat(client-codeconnections): This release adds the PullRequestCommen…
Sep 19, 2024
9887384
feat(client-workspaces-web): WorkSpaces Secure Browser now enables Ad…
Sep 19, 2024
80a6eae
Publish v3.655.0
Sep 19, 2024
afb9535
fix(sdk-codegen): corrected model parsing and awsQuery error code wit…
Sep 20, 2024
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,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.*;
RanVaknin marked this conversation as resolved.
Show resolved Hide resolved

@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.
Show resolved Hide resolved
if (shape.hasTrait("smithy.api#error") && shape.hasTrait("aws.protocols#awsQueryError")) {
kuhe marked this conversation as resolved.
Show resolved Hide resolved
Optional<Trait> awsQueryTraitOpt = shape.findTrait("aws.protocols#awsQueryError");
if (awsQueryTraitOpt.isPresent()) {
RanVaknin marked this conversation as resolved.
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.
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.
Show resolved Hide resolved
Optional<Trait> waitableTraitOpt = shape.findTrait("smithy.waiters#waitable");
if (waitableTraitOpt.isPresent()) {
kuhe marked this conversation as resolved.
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsSdkCustom
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AddAwsDefaultSigningName
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AddSTSAuthCustomizations
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsSdkCustomizeEndpointRuleSetHttpAuthSchemeProvider
software.amazon.smithy.aws.typescript.codegen.ProcessAwsQueryWaiters
Loading