Skip to content

Commit c8b148c

Browse files
authored
fix(core/protocols): allow HttpBindingProtocol to generate idempotency tokens (#1774)
1 parent e00e61c commit c8b148c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

.changeset/tender-ducks-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/core": patch
3+
---
4+
5+
idempotency token generation for HttpBindingProtocol

packages/core/src/submodules/protocols/HttpBindingProtocol.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
SerdeFunctions,
1515
ShapeDeserializer,
1616
ShapeSerializer,
17+
StaticStructureSchema,
1718
StringSchema,
1819
TimestampDefaultSchema,
1920
TimestampEpochSecondsSchema,
@@ -206,4 +207,41 @@ describe(HttpBindingProtocol.name, () => {
206207
header: "header-value",
207208
});
208209
});
210+
211+
it("should fill in undefined idempotency tokens", async () => {
212+
const protocol = new StringRestProtocol();
213+
const request = await protocol.serializeRequest(
214+
op(
215+
"",
216+
"",
217+
{
218+
http: ["GET", "/{labelToken}/Operation", 200],
219+
},
220+
[
221+
3,
222+
"ns",
223+
"Struct",
224+
0,
225+
["name", "queryToken", "labelToken", "headerToken"],
226+
[
227+
0,
228+
[0, { idempotencyToken: 1, httpQuery: "token" }],
229+
[0, { idempotencyToken: 1, httpLabel: 1 }],
230+
[0, { idempotencyToken: 1, httpHeader: "header-token" }],
231+
],
232+
] satisfies StaticStructureSchema,
233+
"unit"
234+
),
235+
{
236+
Name: "my-name",
237+
},
238+
{
239+
endpoint: async () => parseUrl("https://localhost/custom"),
240+
} as any
241+
);
242+
243+
expect(request.query?.token).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
244+
expect(request.path).toMatch(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/);
245+
expect(request.headers?.["header-token"]).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
246+
});
209247
});

packages/core/src/submodules/protocols/HttpBindingProtocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export abstract class HttpBindingProtocol extends HttpProtocol {
7878
const memberTraits = memberNs.getMergedTraits() ?? {};
7979
const inputMemberValue = input[memberName];
8080

81-
if (inputMemberValue == null) {
81+
if (inputMemberValue == null && !memberNs.isIdempotencyToken()) {
8282
continue;
8383
}
8484

0 commit comments

Comments
 (0)