Skip to content

Commit f2f40d3

Browse files
committed
fixup! feat: support @httpApiKeyAuth trait
1 parent 960f792 commit f2f40d3

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/integration/http-api-key-auth.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("httpApiKeyAuthMiddleware", () => {
8080
).toBe("exampleApiKey");
8181
});
8282

83-
it("should throw an error if the api key has not been set", async () => {
83+
it("should skip if the api key has not been set", async () => {
8484
const middleware = httpApiKeyAuthMiddleware(
8585
{},
8686
{
@@ -92,14 +92,12 @@ describe("httpApiKeyAuthMiddleware", () => {
9292

9393
const handler = middleware(mockNextHandler, {});
9494

95-
await expect(
96-
handler({
97-
input: {},
98-
request: new HttpRequest({}),
99-
})
100-
).rejects.toThrow("no API key was provided");
95+
await handler({
96+
input: {},
97+
request: {},
98+
});
10199

102-
expect(mockNextHandler.mock.calls.length).toEqual(0);
100+
expect(mockNextHandler.mock.calls.length).toEqual(1);
103101
});
104102

105103
it("should skip if the request is not an HttpRequest", async () => {

smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/integration/http-api-key-auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export const httpApiKeyAuthMiddleware =
8383
if (!HttpRequest.isInstance(args.request)) return next(args);
8484

8585
// This middleware will not be injected if the operation has the @optionalAuth trait.
86+
// We don't know if we're the only auth middleware, so let the service deal with the
87+
// absence of the API key (or let other middleware do its job).
8688
if (!pluginConfig.apiKey) {
87-
throw new Error(
88-
"API key authorization is required but no API key was provided in the client configuration"
89-
);
89+
return next(args);
9090
}
9191

9292
return next({

0 commit comments

Comments
 (0)