Skip to content

Commit

Permalink
fix(sdk-codegen): update errorType in waitable traits to correct shap…
Browse files Browse the repository at this point in the history
…e Id
  • Loading branch information
Ran Vaknin committed Sep 23, 2024
1 parent aa72922 commit 5dc0e7d
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.*;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.smithy.model.transform.ModelTransformer;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
Expand Down Expand Up @@ -48,19 +51,19 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) {
operationBuilder.removeTrait(WaitableTrait.ID);
WaitableTrait waiterTrait = operationShape.expectTrait(WaitableTrait.class);
WaitableTrait.Builder waitableTraitBuilder = (WaitableTrait.Builder) waiterTrait.toBuilder();
for (Map.Entry<String, Waiter> entry : waiterTrait.getWaiters().entrySet()){
for (Map.Entry<String, Waiter> entry : waiterTrait.getWaiters().entrySet()) {
String name = entry.getKey();
Waiter waiter = entry.getValue();
Waiter.Builder waiterBuilder = (Waiter.Builder) waiter.toBuilder();
waiterBuilder.clearAcceptors();
for (Acceptor acceptor : waiter.getAcceptors()){
for (Acceptor acceptor : waiter.getAcceptors()) {
ObjectNode acceptorNode = acceptor.toNode().expectObjectNode();
Matcher matcher = acceptor.getMatcher();
if (matcher instanceof Matcher.ErrorTypeMember){
if (matcher instanceof Matcher.ErrorTypeMember) {
ObjectNode matcherNode = matcher.toNode().expectObjectNode();

String errorCode = matcherNode.expectStringMember("errorType").getValue();
if (errorCodeToShapeId.containsKey(errorCode)){
if (errorCodeToShapeId.containsKey(errorCode)) {
matcherNode = matcherNode.toBuilder()
.withMember("errorType", errorCodeToShapeId.get(errorCode))
.build();
Expand All @@ -72,7 +75,7 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) {
}
waiterBuilder.addAcceptor(Acceptor.fromNode(acceptorNode));
}
waitableTraitBuilder.put(name,waiterBuilder.build());
waitableTraitBuilder.put(name, waiterBuilder.build());
}
operationBuilder.addTrait(waitableTraitBuilder.build());
}
Expand All @@ -86,4 +89,4 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) {

return model;
}
}
}

0 comments on commit 5dc0e7d

Please sign in to comment.