Skip to content

Commit e171183

Browse files
chore: update base64 codegen (#2786)
* chore: update generated code * fix(codegen): run all base64 ssdk tests
1 parent cc17fa2 commit e171183

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

clients/client-lex-runtime-service/protocols/Aws_restJson1.ts

+19-13
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,21 @@ export const serializeAws_restJson1PostContentCommand = async (
153153
"content-type": "application/octet-stream",
154154
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
155155
...(isSerializableHeaderValue(input.sessionAttributes) && {
156-
"x-amz-lex-session-attributes": Buffer.from(__LazyJsonString.fromObject(input.sessionAttributes!)).toString(
157-
"base64"
156+
"x-amz-lex-session-attributes": context.base64Encoder(
157+
Buffer.from(__LazyJsonString.fromObject(input.sessionAttributes!))
158158
),
159159
}),
160160
...(isSerializableHeaderValue(input.requestAttributes) && {
161-
"x-amz-lex-request-attributes": Buffer.from(__LazyJsonString.fromObject(input.requestAttributes!)).toString(
162-
"base64"
161+
"x-amz-lex-request-attributes": context.base64Encoder(
162+
Buffer.from(__LazyJsonString.fromObject(input.requestAttributes!))
163163
),
164164
}),
165165
...(isSerializableHeaderValue(input.contentType) && { "content-type": input.contentType! }),
166166
...(isSerializableHeaderValue(input.accept) && { accept: input.accept! }),
167167
...(isSerializableHeaderValue(input.activeContexts) && {
168-
"x-amz-lex-active-contexts": Buffer.from(__LazyJsonString.fromObject(input.activeContexts!)).toString("base64"),
168+
"x-amz-lex-active-contexts": context.base64Encoder(
169+
Buffer.from(__LazyJsonString.fromObject(input.activeContexts!))
170+
),
169171
}),
170172
};
171173
let resolvedPath =
@@ -575,20 +577,22 @@ export const deserializeAws_restJson1PostContentCommand = async (
575577
}
576578
if (output.headers["x-amz-lex-nlu-intent-confidence"] !== undefined) {
577579
contents.nluIntentConfidence = new __LazyJsonString(
578-
Buffer.from(output.headers["x-amz-lex-nlu-intent-confidence"], "base64").toString("ascii")
580+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-nlu-intent-confidence"])).toString("utf8")
579581
);
580582
}
581583
if (output.headers["x-amz-lex-alternative-intents"] !== undefined) {
582584
contents.alternativeIntents = new __LazyJsonString(
583-
Buffer.from(output.headers["x-amz-lex-alternative-intents"], "base64").toString("ascii")
585+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-alternative-intents"])).toString("utf8")
584586
);
585587
}
586588
if (output.headers["x-amz-lex-slots"] !== undefined) {
587-
contents.slots = new __LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii"));
589+
contents.slots = new __LazyJsonString(
590+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-slots"])).toString("utf8")
591+
);
588592
}
589593
if (output.headers["x-amz-lex-session-attributes"] !== undefined) {
590594
contents.sessionAttributes = new __LazyJsonString(
591-
Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii")
595+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-session-attributes"])).toString("utf8")
592596
);
593597
}
594598
if (output.headers["x-amz-lex-sentiment"] !== undefined) {
@@ -623,7 +627,7 @@ export const deserializeAws_restJson1PostContentCommand = async (
623627
}
624628
if (output.headers["x-amz-lex-active-contexts"] !== undefined) {
625629
contents.activeContexts = new __LazyJsonString(
626-
Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii")
630+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-active-contexts"])).toString("utf8")
627631
);
628632
}
629633
const data: any = output.body;
@@ -940,11 +944,13 @@ export const deserializeAws_restJson1PutSessionCommand = async (
940944
contents.intentName = output.headers["x-amz-lex-intent-name"];
941945
}
942946
if (output.headers["x-amz-lex-slots"] !== undefined) {
943-
contents.slots = new __LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii"));
947+
contents.slots = new __LazyJsonString(
948+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-slots"])).toString("utf8")
949+
);
944950
}
945951
if (output.headers["x-amz-lex-session-attributes"] !== undefined) {
946952
contents.sessionAttributes = new __LazyJsonString(
947-
Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii")
953+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-session-attributes"])).toString("utf8")
948954
);
949955
}
950956
if (output.headers["x-amz-lex-message"] !== undefined) {
@@ -967,7 +973,7 @@ export const deserializeAws_restJson1PutSessionCommand = async (
967973
}
968974
if (output.headers["x-amz-lex-active-contexts"] !== undefined) {
969975
contents.activeContexts = new __LazyJsonString(
970-
Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii")
976+
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-active-contexts"])).toString("utf8")
971977
);
972978
}
973979
const data: any = output.body;

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java

-5
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,6 @@ private static boolean filterMalformedRequestTests(
326326
if (testCase.getId().equals("RestJsonBodyMalformedMapNullValue")) {
327327
return true;
328328
}
329-
//TODO: Buffer.from isn't decoding base64 strictly.
330-
if (testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case1")
331-
|| testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case2")) {
332-
return true;
333-
}
334329

335330
//TODO: Fixed after Smithy 1.11.0
336331
if (testCase.getId().equals("RestJsonPathTimestampDefaultRejectsDifferent8601Formats_case14")) {

protocol_tests/aws-restjson/protocols/Aws_restJson1.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ export const serializeAws_restJson1MediaTypeHeaderCommand = async (
12821282
const { hostname, protocol = "https", port, path: basePath } = await context.endpoint();
12831283
const headers: any = {
12841284
...(isSerializableHeaderValue(input.json) && {
1285-
"x-json": Buffer.from(__LazyJsonString.fromObject(input.json!)).toString("base64"),
1285+
"x-json": context.base64Encoder(Buffer.from(__LazyJsonString.fromObject(input.json!))),
12861286
}),
12871287
};
12881288
let resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/MediaTypeHeader";
@@ -3299,7 +3299,7 @@ export const deserializeAws_restJson1MediaTypeHeaderCommand = async (
32993299
json: undefined,
33003300
};
33013301
if (output.headers["x-json"] !== undefined) {
3302-
contents.json = new __LazyJsonString(Buffer.from(output.headers["x-json"], "base64").toString("ascii"));
3302+
contents.json = new __LazyJsonString(Buffer.from(context.base64Decoder(output.headers["x-json"])).toString("utf8"));
33033303
}
33043304
await collectBody(output.body, context);
33053305
return Promise.resolve(contents);

0 commit comments

Comments
 (0)