Skip to content

Commit 325d6b4

Browse files
authored
chore(codegen): pass ServiceShape service to ShapeId.getName() (#2198)
1 parent 94aefce commit 325d6b4

15 files changed

+55
-35
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAwsAuthPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static boolean operationUsesAwsAuth(Model model, ServiceShape service, O
125125
if (testServiceId(service, "STS")) {
126126
Boolean isUnsignedCommand = SetUtils
127127
.of("AssumeRoleWithWebIdentity", "AssumeRoleWithSAML")
128-
.contains(operation.getId().getName());
128+
.contains(operation.getId().getName(service));
129129
return !isUnsignedCommand;
130130
}
131131

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ public List<RuntimeClientPlugin> getClientPlugins() {
6868
RuntimeClientPlugin.builder()
6969
.withConventions(AwsDependency.EC2_MIDDLEWARE.dependency,
7070
"CopySnapshotPresignedUrl", HAS_MIDDLEWARE)
71-
.operationPredicate((m, s, o) -> o.getId().getName().equals("CopySnapshot")
71+
.operationPredicate((m, s, o) -> o.getId().getName(s).equals("CopySnapshot")
7272
&& testServiceId(s, "EC2"))
7373
.build(),
7474
RuntimeClientPlugin.builder()
7575
.withConventions(AwsDependency.MACHINELEARNING_MIDDLEWARE.dependency, "PredictEndpoint",
7676
HAS_MIDDLEWARE)
77-
.operationPredicate((m, s, o) -> o.getId().getName().equals("Predict")
77+
.operationPredicate((m, s, o) -> o.getId().getName(s).equals("Predict")
7878
&& testServiceId(s, "Machine Learning"))
7979
.build(),
8080
RuntimeClientPlugin.builder()
8181
.withConventions(AwsDependency.ROUTE53_MIDDLEWARE.dependency,
8282
"ChangeResourceRecordSets", HAS_MIDDLEWARE)
83-
.operationPredicate((m, s, o) -> o.getId().getName().equals("ChangeResourceRecordSets")
83+
.operationPredicate((m, s, o) -> o.getId().getName(s).equals("ChangeResourceRecordSets")
8484
&& testServiceId(s, "Route 53"))
8585
.build(),
8686
RuntimeClientPlugin.builder()
@@ -92,19 +92,19 @@ && testServiceId(s, "Route 53"))
9292
RuntimeClientPlugin.builder()
9393
.withConventions(AwsDependency.SQS_MIDDLEWARE.dependency, "SendMessage",
9494
HAS_MIDDLEWARE)
95-
.operationPredicate((m, s, o) -> o.getId().getName().equals("SendMessage")
95+
.operationPredicate((m, s, o) -> o.getId().getName(s).equals("SendMessage")
9696
&& testServiceId(s, "SQS"))
9797
.build(),
9898
RuntimeClientPlugin.builder()
9999
.withConventions(AwsDependency.SQS_MIDDLEWARE.dependency, "SendMessageBatch",
100100
HAS_MIDDLEWARE)
101-
.operationPredicate((m, s, o) -> o.getId().getName().equals("SendMessageBatch")
101+
.operationPredicate((m, s, o) -> o.getId().getName(s).equals("SendMessageBatch")
102102
&& testServiceId(s, "SQS"))
103103
.build(),
104104
RuntimeClientPlugin.builder()
105105
.withConventions(AwsDependency.SQS_MIDDLEWARE.dependency, "ReceiveMessage",
106106
HAS_MIDDLEWARE)
107-
.operationPredicate((m, s, o) -> o.getId().getName().equals("ReceiveMessage")
107+
.operationPredicate((m, s, o) -> o.getId().getName(s).equals("ReceiveMessage")
108108
&& testServiceId(s, "SQS"))
109109
.build(),
110110
RuntimeClientPlugin.builder()

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddCrossRegionCopyingPlugin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public List<RuntimeClientPlugin> getClientPlugins() {
4343
RuntimeClientPlugin.builder()
4444
.withConventions(AwsDependency.RDS_MIDDLEWARE.dependency, "CrossRegionPresignedUrl",
4545
HAS_MIDDLEWARE)
46-
.operationPredicate((m, s, o) -> RDS_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName())
46+
.operationPredicate((m, s, o) -> RDS_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName(s))
4747
&& testServiceId(s, "RDS"))
4848
.build(),
4949
RuntimeClientPlugin.builder()
5050
.withConventions(AwsDependency.RDS_MIDDLEWARE.dependency, "CrossRegionPresignedUrl",
5151
HAS_MIDDLEWARE)
52-
.operationPredicate((m, s, o) -> SHARED_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName())
52+
.operationPredicate((m, s, o) -> SHARED_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName(s))
5353
&& (testServiceId(s, "RDS") || testServiceId(s, "DocDB") || testServiceId(s, "Neptune")))
5454
.build()
5555
);

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public List<RuntimeClientPlugin> getClientPlugins() {
127127
.withConventions(AwsDependency.S3_MIDDLEWARE.dependency, "throw200Exceptions",
128128
HAS_MIDDLEWARE)
129129
.operationPredicate(
130-
(m, s, o) -> EXCEPTIONS_OF_200_OPERATIONS.contains(o.getId().getName())
130+
(m, s, o) -> EXCEPTIONS_OF_200_OPERATIONS.contains(o.getId().getName(s))
131131
&& testServiceId(s))
132132
.build(),
133133
RuntimeClientPlugin.builder()
@@ -143,7 +143,7 @@ && testServiceId(s))
143143
RuntimeClientPlugin.builder()
144144
.withConventions(AwsDependency.LOCATION_CONSTRAINT.dependency, "LocationConstraint",
145145
HAS_MIDDLEWARE)
146-
.operationPredicate((m, s, o) -> o.getId().getName().equals("CreateBucket")
146+
.operationPredicate((m, s, o) -> o.getId().getName(s).equals("CreateBucket")
147147
&& testServiceId(s))
148148
.build(),
149149
/**
@@ -158,13 +158,13 @@ && testServiceId(s))
158158
RuntimeClientPlugin.builder()
159159
.withConventions(AwsDependency.BUCKET_ENDPOINT_MIDDLEWARE.dependency, "BucketEndpoint",
160160
HAS_MIDDLEWARE)
161-
.operationPredicate((m, s, o) -> !NON_BUCKET_ENDPOINT_OPERATIONS.contains(o.getId().getName())
161+
.operationPredicate((m, s, o) -> !NON_BUCKET_ENDPOINT_OPERATIONS.contains(o.getId().getName(s))
162162
&& testServiceId(s))
163163
.build(),
164164
RuntimeClientPlugin.builder()
165165
.withConventions(AwsDependency.BODY_CHECKSUM.dependency, "ApplyMd5BodyChecksum",
166166
HAS_MIDDLEWARE)
167-
.operationPredicate((m, s, o) -> S3_MD5_OPERATIONS.contains(o.getId().getName())
167+
.operationPredicate((m, s, o) -> S3_MD5_OPERATIONS.contains(o.getId().getName(s))
168168
&& testServiceId(s))
169169
.build()
170170
);

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3ControlDependency.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public List<RuntimeClientPlugin> getClientPlugins() {
5252
"ProcessArnables",
5353
HAS_MIDDLEWARE
5454
)
55-
.operationPredicate((m, s, o) -> isS3Control(s) && isArnableOperation(o))
55+
.operationPredicate((m, s, o) -> isS3Control(s) && isArnableOperation(o, s))
5656
.build(),
5757
RuntimeClientPlugin.builder()
5858
.withConventions(
5959
AwsDependency.S3_CONTROL_MIDDLEWARE.dependency,
6060
"RedirectFromPostId",
6161
HAS_MIDDLEWARE
6262
)
63-
.operationPredicate((m, s, o) -> isS3Control(s) && !isArnableOperation(o))
63+
.operationPredicate((m, s, o) -> isS3Control(s) && !isArnableOperation(o, s))
6464
.build());
6565
}
6666

@@ -70,9 +70,10 @@ public Model preprocessModel(PluginContext context, TypeScriptSettings settings)
7070
if (!isS3Control(settings.getService(model))) {
7171
return model;
7272
}
73+
ServiceShape serviceShape = model.expectShape(settings.getService(), ServiceShape.class);
7374
return ModelTransformer.create().mapShapes(model, shape -> {
7475
Optional<MemberShape> modified = shape.asMemberShape()
75-
.filter(memberShape -> memberShape.getTarget().getName().equals("AccountId"))
76+
.filter(memberShape -> memberShape.getTarget().getName(serviceShape).equals("AccountId"))
7677
.filter(memberShape -> model.expectShape(memberShape.getTarget()).isStringShape())
7778
.filter(memberShape -> memberShape.isRequired())
7879
.map(memberShape -> Shape.shapeToBuilder(memberShape).removeTrait(RequiredTrait.ID).build());
@@ -85,8 +86,8 @@ private static boolean isS3Control(ServiceShape service) {
8586
return serviceId.equals("S3 Control");
8687
}
8788

88-
private static boolean isArnableOperation(OperationShape operation) {
89-
String operationName = operation.getId().getName();
89+
private static boolean isArnableOperation(OperationShape operation, ServiceShape serviceShape) {
90+
String operationName = operation.getId().getName(serviceShape);
9091
return !operationName.equals("CreateBucket") && !operationName.equals("ListRegionalBuckets");
9192
}
9293
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsEc2.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait;
2020
import software.amazon.smithy.codegen.core.SymbolReference;
2121
import software.amazon.smithy.model.shapes.OperationShape;
22+
import software.amazon.smithy.model.shapes.ServiceShape;
2223
import software.amazon.smithy.model.shapes.Shape;
2324
import software.amazon.smithy.model.shapes.ShapeId;
2425
import software.amazon.smithy.model.shapes.StructureShape;
@@ -134,8 +135,9 @@ protected void serializeInputDocument(
134135
writer.write("...$L,",
135136
inputStructure.accept(new QueryMemberSerVisitor(context, "input", Format.DATE_TIME)));
136137
// Set the protocol required values.
137-
writer.write("Action: $S,", operation.getId().getName());
138-
writer.write("Version: $S,", context.getService().getVersion());
138+
ServiceShape serviceShape = context.getService();
139+
writer.write("Action: $S,", operation.getId().getName(serviceShape));
140+
writer.write("Version: $S,", serviceShape.getVersion());
139141
});
140142
}
141143

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void writeAdditionalFiles(
7676

7777
TopDownIndex topDownIndex = TopDownIndex.of(model);
7878
OperationShape firstOperation = topDownIndex.getContainedOperations(service).iterator().next();
79-
String operationName = firstOperation.getId().getName();
79+
String operationName = firstOperation.getId().getName(service);
8080
resource = resource.replaceAll(Pattern.quote("${commandName}"), operationName);
8181
resource = resource.replaceAll(Pattern.quote("${operationName}"),
8282
operationName.substring(0, 1).toLowerCase() + operationName.substring(1));

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import software.amazon.smithy.model.neighbor.Walker;
2727
import software.amazon.smithy.model.shapes.MemberShape;
2828
import software.amazon.smithy.model.shapes.OperationShape;
29+
import software.amazon.smithy.model.shapes.ServiceShape;
2930
import software.amazon.smithy.model.shapes.Shape;
3031
import software.amazon.smithy.model.shapes.ShapeVisitor;
3132
import software.amazon.smithy.model.traits.IdempotencyTokenTrait;
@@ -178,8 +179,9 @@ static boolean generateUndefinedQueryInputBody(GenerationContext context, Operat
178179
// Set the form encoded string.
179180
writer.openBlock("const body = buildFormUrlencodedString({", "});", () -> {
180181
// Set the protocol required values.
181-
writer.write("Action: $S,", operation.getId().getName());
182-
writer.write("Version: $S,", context.getService().getVersion());
182+
ServiceShape serviceShape = context.getService();
183+
writer.write("Action: $S,", operation.getId().getName(serviceShape));
184+
writer.write("Version: $S,", serviceShape.getVersion());
183185
});
184186

185187
return true;

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsQuery.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait;
2020
import software.amazon.smithy.codegen.core.SymbolReference;
2121
import software.amazon.smithy.model.shapes.OperationShape;
22+
import software.amazon.smithy.model.shapes.ServiceShape;
2223
import software.amazon.smithy.model.shapes.Shape;
2324
import software.amazon.smithy.model.shapes.ShapeId;
2425
import software.amazon.smithy.model.shapes.StructureShape;
@@ -134,8 +135,9 @@ protected void serializeInputDocument(
134135
writer.write("...$L,",
135136
inputStructure.accept(new QueryMemberSerVisitor(context, "input", Format.DATE_TIME)));
136137
// Set the protocol required values.
137-
writer.write("Action: $S,", operation.getId().getName());
138-
writer.write("Version: $S,", context.getService().getVersion());
138+
ServiceShape serviceShape = context.getService();
139+
writer.write("Action: $S,", operation.getId().getName(serviceShape));
140+
writer.write("Version: $S,", serviceShape.getVersion());
139141
});
140142
}
141143

@@ -160,7 +162,7 @@ protected void deserializeOutputDocument(
160162
) {
161163
TypeScriptWriter writer = context.getWriter();
162164

163-
String dataSource = "data." + operation.getId().getName() + "Result";
165+
String dataSource = "data." + operation.getId().getName(context.getService()) + "Result";
164166
writer.write("contents = $L;",
165167
outputStructure.accept(new XmlMemberDeserVisitor(context, dataSource, Format.DATE_TIME)));
166168
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import software.amazon.smithy.model.knowledge.HttpBinding.Location;
2525
import software.amazon.smithy.model.shapes.MemberShape;
2626
import software.amazon.smithy.model.shapes.OperationShape;
27+
import software.amazon.smithy.model.shapes.ServiceShape;
2728
import software.amazon.smithy.model.shapes.Shape;
2829
import software.amazon.smithy.model.shapes.ShapeId;
2930
import software.amazon.smithy.model.shapes.StructureShape;
@@ -153,18 +154,19 @@ protected void serializeInputDocument(
153154
return;
154155
}
155156

157+
ServiceShape serviceShape = context.getService();
156158
SymbolProvider symbolProvider = context.getSymbolProvider();
157159
ShapeId inputShapeId = documentBindings.get(0).getMember().getContainer();
158160

159161
// Start with the XML declaration.
160162
writer.write("body = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\";");
161163

162164
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");
163-
writer.write("const bodyNode = new __XmlNode($S);", inputShapeId.getName());
165+
writer.write("const bodyNode = new __XmlNode($S);", inputShapeId.getName(serviceShape));
164166

165167
// Add @xmlNamespace value of the service to the root node,
166168
// fall back to one from the input shape.
167-
boolean serviceXmlns = AwsProtocolUtils.writeXmlNamespace(context, context.getService(), "bodyNode");
169+
boolean serviceXmlns = AwsProtocolUtils.writeXmlNamespace(context, serviceShape, "bodyNode");
168170
if (!serviceXmlns) {
169171
StructureShape inputShape = context.getModel().expectShape(inputShapeId, StructureShape.class);
170172
AwsProtocolUtils.writeXmlNamespace(context, inputShape, "bodyNode");

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Set;
1919
import software.amazon.smithy.model.shapes.OperationShape;
20+
import software.amazon.smithy.model.shapes.ServiceShape;
2021
import software.amazon.smithy.model.shapes.Shape;
2122
import software.amazon.smithy.model.shapes.StructureShape;
2223
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
@@ -88,7 +89,8 @@ protected void writeDefaultHeaders(GenerationContext context, OperationShape ope
8889
// AWS JSON RPC protocols use a combination of the service and operation shape names,
8990
// separated by a '.' character, for the target header.
9091
TypeScriptWriter writer = context.getWriter();
91-
String target = context.getService().getId().getName() + "." + operation.getId().getName();
92+
ServiceShape serviceShape = context.getService();
93+
String target = serviceShape.getId().getName(serviceShape) + "." + operation.getId().getName(serviceShape);
9294
writer.write("'x-amz-target': $S,", target);
9395
}
9496

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import software.amazon.smithy.model.shapes.DocumentShape;
2424
import software.amazon.smithy.model.shapes.MapShape;
2525
import software.amazon.smithy.model.shapes.MemberShape;
26+
import software.amazon.smithy.model.shapes.ServiceShape;
2627
import software.amazon.smithy.model.shapes.Shape;
2728
import software.amazon.smithy.model.shapes.StructureShape;
2829
import software.amazon.smithy.model.shapes.UnionShape;
@@ -152,9 +153,10 @@ public void serializeStructure(GenerationContext context, StructureShape shape)
152153
public void serializeUnion(GenerationContext context, UnionShape shape) {
153154
TypeScriptWriter writer = context.getWriter();
154155
Model model = context.getModel();
156+
ServiceShape serviceShape = context.getService();
155157

156158
// Visit over the union type, then get the right serialization for the member.
157-
writer.openBlock("return $L.visit(input, {", "});", shape.getId().getName(), () -> {
159+
writer.openBlock("return $L.visit(input, {", "});", shape.getId().getName(serviceShape), () -> {
158160
// Use a TreeMap to sort the members.
159161
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
160162
members.forEach((memberName, memberShape) -> {

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/QueryShapeSerVisitor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import software.amazon.smithy.model.shapes.DocumentShape;
2222
import software.amazon.smithy.model.shapes.MapShape;
2323
import software.amazon.smithy.model.shapes.MemberShape;
24+
import software.amazon.smithy.model.shapes.ServiceShape;
2425
import software.amazon.smithy.model.shapes.Shape;
2526
import software.amazon.smithy.model.shapes.StructureShape;
2627
import software.amazon.smithy.model.shapes.UnionShape;
@@ -272,12 +273,13 @@ protected boolean isFlattenedMember(GenerationContext context, MemberShape membe
272273
@Override
273274
protected void serializeUnion(GenerationContext context, UnionShape shape) {
274275
TypeScriptWriter writer = context.getWriter();
276+
ServiceShape serviceShape = context.getService();
275277

276278
// Set up a location to store the entry pair.
277279
writer.write("const entries: any = {};");
278280

279281
// Visit over the union type, then get the right serialization for the member.
280-
writer.openBlock("$L.visit(input, {", "});", shape.getId().getName(), () -> {
282+
writer.openBlock("$L.visit(input, {", "});", shape.getId().getName(serviceShape), () -> {
281283
shape.getAllMembers().forEach((memberName, memberShape) -> {
282284
writer.openBlock("$L: value => {", "},", memberName, () -> {
283285
serializeNamedMember(context, memberName, memberShape, "value");

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/XmlMemberSerVisitor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@
4949
* @see <a href="https://awslabs.github.io/smithy/spec/xml.html">Smithy XML traits.</a>
5050
*/
5151
final class XmlMemberSerVisitor extends DocumentMemberSerVisitor {
52+
private final GenerationContext context;
5253

5354
XmlMemberSerVisitor(GenerationContext context, String dataSource, Format defaultTimestampFormat) {
5455
super(context, dataSource, defaultTimestampFormat);
56+
this.context = context;
5557
}
5658

5759
@Override
@@ -112,7 +114,7 @@ String getAsXmlText(Shape shape, String dataSource) {
112114
// Handle the @xmlName trait for the shape itself.
113115
String nodeName = shape.getTrait(XmlNameTrait.class)
114116
.map(XmlNameTrait::getValue)
115-
.orElse(shape.getId().getName());
117+
.orElse(shape.getId().getName(context.getService()));
116118

117119
TypeScriptWriter writer = getContext().getWriter();
118120
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");

0 commit comments

Comments
 (0)