Skip to content

Commit 3864faa

Browse files
author
Steven Yuan
authored
fix(codegen): use TopDownIndex::getContainedOperations() for operation iterations (#1109)
1 parent 2764ee8 commit 3864faa

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import software.amazon.smithy.codegen.core.SymbolProvider;
2929
import software.amazon.smithy.model.Model;
3030
import software.amazon.smithy.model.knowledge.ServiceIndex;
31+
import software.amazon.smithy.model.knowledge.TopDownIndex;
3132
import software.amazon.smithy.model.shapes.ServiceShape;
3233
import software.amazon.smithy.model.shapes.ShapeId;
3334
import software.amazon.smithy.typescript.codegen.auth.AuthUtils;
@@ -229,8 +230,9 @@ private void generateHttpAuthSchemeConfig(
229230

230231
// feat(experimentalIdentityAndAuth): gather HttpAuthSchemes to generate
231232
ServiceIndex serviceIndex = ServiceIndex.of(model);
233+
TopDownIndex topDownIndex = TopDownIndex.of(model);
232234
Map<ShapeId, HttpAuthScheme> allEffectiveHttpAuthSchemes =
233-
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(service, serviceIndex, authIndex);
235+
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(service, serviceIndex, authIndex, topDownIndex);
234236
List<HttpAuthSchemeTarget> targetAuthSchemes = getHttpAuthSchemeTargets(target, allEffectiveHttpAuthSchemes);
235237

236238
// Generate only if the "inherited" target is different than the current target

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/AuthUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import software.amazon.smithy.codegen.core.SymbolDependency;
1818
import software.amazon.smithy.model.knowledge.ServiceIndex;
1919
import software.amazon.smithy.model.knowledge.ServiceIndex.AuthSchemeMode;
20+
import software.amazon.smithy.model.knowledge.TopDownIndex;
2021
import software.amazon.smithy.model.shapes.ServiceShape;
2122
import software.amazon.smithy.model.shapes.ShapeId;
2223
import software.amazon.smithy.model.traits.Trait;
@@ -75,15 +76,16 @@ private AuthUtils() {}
7576
public static Map<ShapeId, HttpAuthScheme> getAllEffectiveNoAuthAwareAuthSchemes(
7677
ServiceShape serviceShape,
7778
ServiceIndex serviceIndex,
78-
SupportedHttpAuthSchemesIndex authIndex
79+
SupportedHttpAuthSchemesIndex authIndex,
80+
TopDownIndex topDownIndex
7981
) {
8082
Map<ShapeId, HttpAuthScheme> effectiveAuthSchemes = new TreeMap<>();
8183
var serviceEffectiveAuthSchemes =
8284
serviceIndex.getEffectiveAuthSchemes(serviceShape, AuthSchemeMode.NO_AUTH_AWARE);
8385
for (ShapeId shapeId : serviceEffectiveAuthSchemes.keySet()) {
8486
effectiveAuthSchemes.put(shapeId, authIndex.getHttpAuthScheme(shapeId));
8587
}
86-
for (var operation : serviceShape.getAllOperations()) {
88+
for (var operation : topDownIndex.getContainedOperations(serviceShape)) {
8789
var operationEffectiveAuthSchemes =
8890
serviceIndex.getEffectiveAuthSchemes(serviceShape, operation, AuthSchemeMode.NO_AUTH_AWARE);
8991
for (ShapeId shapeId : operationEffectiveAuthSchemes.keySet()) {

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/HttpAuthSchemeProviderGenerator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import software.amazon.smithy.model.Model;
1717
import software.amazon.smithy.model.knowledge.ServiceIndex;
1818
import software.amazon.smithy.model.knowledge.ServiceIndex.AuthSchemeMode;
19+
import software.amazon.smithy.model.knowledge.TopDownIndex;
20+
import software.amazon.smithy.model.shapes.OperationShape;
1921
import software.amazon.smithy.model.shapes.ServiceShape;
2022
import software.amazon.smithy.model.shapes.ShapeId;
2123
import software.amazon.smithy.model.traits.Trait;
@@ -59,6 +61,7 @@ public class HttpAuthSchemeProviderGenerator implements Runnable {
5961

6062
private final SupportedHttpAuthSchemesIndex authIndex;
6163
private final ServiceIndex serviceIndex;
64+
private final TopDownIndex topDownIndex;
6265
private final ServiceShape serviceShape;
6366
private final Symbol serviceSymbol;
6467
private final String serviceName;
@@ -88,11 +91,12 @@ public HttpAuthSchemeProviderGenerator(
8891

8992
this.authIndex = new SupportedHttpAuthSchemesIndex(integrations, model, settings);
9093
this.serviceIndex = ServiceIndex.of(model);
94+
this.topDownIndex = TopDownIndex.of(model);
9195
this.serviceShape = settings.getService(model);
9296
this.serviceSymbol = symbolProvider.toSymbol(serviceShape);
9397
this.serviceName = CodegenUtils.getServiceName(settings, model, symbolProvider);
9498
this.effectiveHttpAuthSchemes =
95-
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(serviceShape, serviceIndex, authIndex);
99+
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(serviceShape, serviceIndex, authIndex, topDownIndex);
96100
this.httpAuthSchemeParameters =
97101
AuthUtils.collectHttpAuthSchemeParameters(effectiveHttpAuthSchemes.values());
98102
}
@@ -395,7 +399,8 @@ private void generateDefaultHttpAuthSchemeProviderFunction() {
395399
w.openBlock("switch (authParameters.operation) {", "};", () -> {
396400
var serviceAuthSchemes = serviceIndex.getEffectiveAuthSchemes(
397401
serviceShape, AuthSchemeMode.NO_AUTH_AWARE);
398-
for (ShapeId operationShapeId : serviceShape.getAllOperations()) {
402+
for (OperationShape operationShape : topDownIndex.getContainedOperations(serviceShape)) {
403+
ShapeId operationShapeId = operationShape.getId();
399404
var operationAuthSchemes = serviceIndex.getEffectiveAuthSchemes(
400405
serviceShape, operationShapeId, AuthSchemeMode.NO_AUTH_AWARE);
401406
// Skip operation generation if operation auth schemes are equivalent to the default service

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/integration/AddHttpAuthSchemePlugin.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.stream.Collectors;
1212
import software.amazon.smithy.codegen.core.Symbol;
1313
import software.amazon.smithy.model.knowledge.ServiceIndex;
14+
import software.amazon.smithy.model.knowledge.TopDownIndex;
1415
import software.amazon.smithy.model.shapes.ServiceShape;
1516
import software.amazon.smithy.model.shapes.ShapeId;
1617
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
@@ -145,8 +146,9 @@ private getIdentityProviderConfigProvider() {
145146
s.getModel(),
146147
s.getSettings());
147148
ServiceIndex serviceIndex = ServiceIndex.of(s.getModel());
148-
Map<ShapeId, HttpAuthScheme> httpAuthSchemes =
149-
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(s.getService(), serviceIndex, authIndex);
149+
TopDownIndex topDownIndex = TopDownIndex.of(s.getModel());
150+
Map<ShapeId, HttpAuthScheme> httpAuthSchemes = AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(
151+
s.getService(), serviceIndex, authIndex, topDownIndex);
150152
for (HttpAuthScheme scheme : httpAuthSchemes.values()) {
151153
if (scheme == null) {
152154
continue;
@@ -177,8 +179,9 @@ public void customize(TypeScriptCodegenContext codegenContext) {
177179
codegenContext.settings());
178180
ServiceShape serviceShape = codegenContext.settings().getService(codegenContext.model());
179181
ServiceIndex serviceIndex = ServiceIndex.of(codegenContext.model());
182+
TopDownIndex topDownIndex = TopDownIndex.of(codegenContext.model());
180183
Map<ShapeId, HttpAuthScheme> httpAuthSchemes =
181-
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(serviceShape, serviceIndex, authIndex);
184+
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(serviceShape, serviceIndex, authIndex, topDownIndex);
182185
Map<String, ConfigField> configFields =
183186
AuthUtils.collectConfigFields(httpAuthSchemes.values());
184187
Map<Symbol, ResolveConfigFunction> resolveConfigFunctions =

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/integration/HttpAuthRuntimeExtensionIntegration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Map;
1010
import software.amazon.smithy.model.Model;
1111
import software.amazon.smithy.model.knowledge.ServiceIndex;
12+
import software.amazon.smithy.model.knowledge.TopDownIndex;
1213
import software.amazon.smithy.model.shapes.ServiceShape;
1314
import software.amazon.smithy.model.shapes.ShapeId;
1415
import software.amazon.smithy.typescript.codegen.CodegenUtils;
@@ -60,11 +61,12 @@ public void customize(TypeScriptCodegenContext codegenContext) {
6061
codegenContext.model(),
6162
codegenContext.settings());
6263
ServiceIndex serviceIndex = ServiceIndex.of(codegenContext.model());
64+
TopDownIndex topDownIndex = TopDownIndex.of(codegenContext.model());
6365
String serviceName = CodegenUtils.getServiceName(
6466
codegenContext.settings(), codegenContext.model(), codegenContext.symbolProvider());
6567
ServiceShape serviceShape = codegenContext.settings().getService(codegenContext.model());
6668
Map<ShapeId, HttpAuthScheme> effectiveAuthSchemes =
67-
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(serviceShape, serviceIndex, authIndex);
69+
AuthUtils.getAllEffectiveNoAuthAwareAuthSchemes(serviceShape, serviceIndex, authIndex, topDownIndex);
6870
Map<String, ConfigField> configFields = AuthUtils.collectConfigFields(effectiveAuthSchemes.values());
6971

7072
generateHttpAuthExtensionConfigurationInterface(

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/AddHttpApiKeyAuthPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import software.amazon.smithy.codegen.core.Symbol;
1414
import software.amazon.smithy.model.Model;
1515
import software.amazon.smithy.model.knowledge.ServiceIndex;
16+
import software.amazon.smithy.model.knowledge.TopDownIndex;
1617
import software.amazon.smithy.model.shapes.OperationShape;
1718
import software.amazon.smithy.model.shapes.ServiceShape;
18-
import software.amazon.smithy.model.shapes.ShapeId;
1919
import software.amazon.smithy.model.traits.HttpApiKeyAuthTrait;
2020
import software.amazon.smithy.model.traits.OptionalAuthTrait;
2121
import software.amazon.smithy.typescript.codegen.CodegenUtils;
@@ -155,8 +155,8 @@ private static boolean hasEffectiveHttpApiKeyAuthTrait(
155155
ServiceShape service
156156
) {
157157
ServiceIndex serviceIndex = ServiceIndex.of(model);
158-
for (ShapeId id : service.getAllOperations()) {
159-
OperationShape operation = model.expectShape(id, OperationShape.class);
158+
TopDownIndex topDownIndex = TopDownIndex.of(model);
159+
for (OperationShape operation : topDownIndex.getContainedOperations(service)) {
160160
if (operation.hasTrait(OptionalAuthTrait.ID)) {
161161
continue;
162162
}

0 commit comments

Comments
 (0)