Skip to content

Commit eae855f

Browse files
committed
fixup! feat: support @httpApiKeyAuth trait
1 parent 38a5776 commit eae855f

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("httpApiKeyAuthMiddleware", () => {
5656
jest.clearAllMocks();
5757
});
5858

59-
it("should throw an error if the location is `query`", async () => {
59+
it("should set the query parameter if the location is `query`", async () => {
6060
const middleware = httpApiKeyAuthMiddleware(
6161
{
6262
apiKey: "exampleApiKey",
@@ -69,14 +69,15 @@ describe("httpApiKeyAuthMiddleware", () => {
6969

7070
const handler = middleware(mockNextHandler, {});
7171

72-
await expect(
73-
handler({
74-
input: {},
75-
request: new HttpRequest({}),
76-
})
77-
).rejects.toThrow("query parameter is not supported");
72+
await handler({
73+
input: {},
74+
request: new HttpRequest({}),
75+
});
7876

79-
expect(mockNextHandler.mock.calls.length).toEqual(0);
77+
expect(mockNextHandler.mock.calls.length).toEqual(1);
78+
expect(
79+
mockNextHandler.mock.calls[0][0].request.query.key
80+
).toBe("exampleApiKey");
8081
});
8182

8283
it("should throw an error if the api key has not been set", async () => {
@@ -169,4 +170,3 @@ describe("httpApiKeyAuthMiddleware", () => {
169170
});
170171
});
171172
});
172-

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ export const httpApiKeyAuthMiddleware =
9393
? `${options.scheme} ${resolvedConfig.apiKey}`
9494
: resolvedConfig.apiKey;
9595
} else if (options.in === "query") {
96-
// It's terrifying that this is an option; API keys should not be part of the URL.
97-
throw new Error(
98-
"Sorry, passing the API key in a query parameter is not supported yet."
99-
);
96+
// Set the query parameter, even if it's already been set.
97+
request.query[options.name] = resolvedConfig.apiKey;
10098
}
10199

102100
return next(args);
@@ -122,4 +120,3 @@ export const getHttpApiKeyAuthPlugin = (
122120
);
123121
},
124122
});
125-

0 commit comments

Comments
 (0)