Skip to content

Commit a636b58

Browse files
fix: missing export for api key auth middleware (#528)
1 parent 6432d24 commit a636b58

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
@SmithyInternalApi
4545
public final class AddHttpApiKeyAuthPlugin implements TypeScriptIntegration {
4646

47+
public static final String INTEGRATION_NAME = "HttpApiKeyAuth";
48+
4749
/**
4850
* Plug into code generation for the client.
4951
*
@@ -62,15 +64,15 @@ public List<RuntimeClientPlugin> getClientPlugins() {
6264
// Add the config if the service uses HTTP API key authorization.
6365
RuntimeClientPlugin.builder()
6466
.inputConfig(Symbol.builder()
65-
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/HttpApiKeyAuth", "/")
67+
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME, "/")
6668
.name("HttpApiKeyAuthInputConfig")
6769
.build())
6870
.resolvedConfig(Symbol.builder()
69-
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/HttpApiKeyAuth", "/")
71+
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME, "/")
7072
.name("HttpApiKeyAuthResolvedConfig")
7173
.build())
7274
.resolveFunction(Symbol.builder()
73-
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/HttpApiKeyAuth", "/")
75+
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME, "/")
7476
.name("resolveHttpApiKeyAuthConfig")
7577
.build())
7678
.servicePredicate((m, s) -> hasEffectiveHttpApiKeyAuthTrait(m, s))
@@ -79,7 +81,7 @@ public List<RuntimeClientPlugin> getClientPlugins() {
7981
// Add the middleware to operations that use HTTP API key authorization.
8082
RuntimeClientPlugin.builder()
8183
.pluginFunction(Symbol.builder()
82-
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/HttpApiKeyAuth", "/")
84+
.namespace("./" + CodegenUtils.SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME, "/")
8385
.name("getHttpApiKeyAuthPlugin")
8486
.build())
8587
.additionalPluginFunctionParamsSupplier((m, s, o) -> new HashMap<String, Object>() {{
@@ -119,7 +121,7 @@ public void writeAdditionalFiles(
119121

120122
// Write the middleware source.
121123
writerFactory.accept(
122-
Paths.get(CodegenUtils.SOURCE_FOLDER, "middleware", "HttpApiKeyAuth", "index.ts").toString(),
124+
Paths.get(CodegenUtils.SOURCE_FOLDER, "middleware", INTEGRATION_NAME, "index.ts").toString(),
123125
writer -> {
124126
String source = IoUtils.readUtf8Resource(getClass(), "http-api-key-auth.ts");
125127
writer.write("$L$L", noTouchNoticePrefix, "http-api-key-auth.ts");
@@ -128,7 +130,7 @@ public void writeAdditionalFiles(
128130

129131
// Write the middleware tests.
130132
writerFactory.accept(
131-
Paths.get(CodegenUtils.SOURCE_FOLDER, "middleware", "HttpApiKeyAuth", "index.spec.ts").toString(),
133+
Paths.get(CodegenUtils.SOURCE_FOLDER, "middleware", INTEGRATION_NAME, "index.spec.ts").toString(),
132134
writer -> {
133135
writer.addDependency(SymbolDependency.builder()
134136
.dependencyType("devDependencies")
@@ -142,6 +144,20 @@ public void writeAdditionalFiles(
142144
});
143145
}
144146

147+
@Override
148+
public void writeAdditionalExports(
149+
TypeScriptSettings settings,
150+
Model model,
151+
SymbolProvider symbolProvider,
152+
TypeScriptWriter writer
153+
) {
154+
boolean isClientSdk = settings.generateClient();
155+
ServiceShape service = settings.getService(model);
156+
if (isClientSdk && hasEffectiveHttpApiKeyAuthTrait(model, service)) {
157+
writer.write("export * from \"./middleware/$1L\";", INTEGRATION_NAME);
158+
}
159+
}
160+
145161
// The service has the effective trait if it's in the "effective auth schemes" response
146162
// AND if not all of the operations have the optional auth trait.
147163
private static boolean hasEffectiveHttpApiKeyAuthTrait(Model model, ServiceShape service) {

smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/integration/AddHttpApiKeyAuthPluginTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ private void testInjects(String filename, String extra) {
7171
// Make sure that the middleware file was written and exports the plugin symbol.
7272
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/middleware/HttpApiKeyAuth/index.ts").get(),
7373
containsString("export const getHttpApiKeyAuthPlugin"));
74+
75+
// Ensure that the middleware was being exported in the index file.
76+
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/index.ts").get(),
77+
containsString("from \"./middleware/HttpApiKeyAuth\""));
7478
}
7579

7680
private MockManifest generate(String filename)
@@ -124,5 +128,9 @@ private void testDoesNotInject(String filename) {
124128
// Make sure that the middleware file was not written.
125129
assertThat(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/middleware/HttpApiKeyAuth/index.ts"),
126130
is(false));
131+
132+
// Ensure that the middleware was not being exported in the index file.
133+
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/index.ts").get(),
134+
not(containsString("from \"./middleware/HttpApiKeyAuth\"")));
127135
}
128136
}

0 commit comments

Comments
 (0)