Skip to content

Commit

Permalink
chore: update base64 codegen (#2786)
Browse files Browse the repository at this point in the history
* chore: update generated code

* fix(codegen): run all base64 ssdk tests
  • Loading branch information
JordonPhillips authored Sep 14, 2021
1 parent cc17fa2 commit e171183
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
32 changes: 19 additions & 13 deletions clients/client-lex-runtime-service/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,21 @@ export const serializeAws_restJson1PostContentCommand = async (
"content-type": "application/octet-stream",
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
...(isSerializableHeaderValue(input.sessionAttributes) && {
"x-amz-lex-session-attributes": Buffer.from(__LazyJsonString.fromObject(input.sessionAttributes!)).toString(
"base64"
"x-amz-lex-session-attributes": context.base64Encoder(
Buffer.from(__LazyJsonString.fromObject(input.sessionAttributes!))
),
}),
...(isSerializableHeaderValue(input.requestAttributes) && {
"x-amz-lex-request-attributes": Buffer.from(__LazyJsonString.fromObject(input.requestAttributes!)).toString(
"base64"
"x-amz-lex-request-attributes": context.base64Encoder(
Buffer.from(__LazyJsonString.fromObject(input.requestAttributes!))
),
}),
...(isSerializableHeaderValue(input.contentType) && { "content-type": input.contentType! }),
...(isSerializableHeaderValue(input.accept) && { accept: input.accept! }),
...(isSerializableHeaderValue(input.activeContexts) && {
"x-amz-lex-active-contexts": Buffer.from(__LazyJsonString.fromObject(input.activeContexts!)).toString("base64"),
"x-amz-lex-active-contexts": context.base64Encoder(
Buffer.from(__LazyJsonString.fromObject(input.activeContexts!))
),
}),
};
let resolvedPath =
Expand Down Expand Up @@ -575,20 +577,22 @@ export const deserializeAws_restJson1PostContentCommand = async (
}
if (output.headers["x-amz-lex-nlu-intent-confidence"] !== undefined) {
contents.nluIntentConfidence = new __LazyJsonString(
Buffer.from(output.headers["x-amz-lex-nlu-intent-confidence"], "base64").toString("ascii")
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-nlu-intent-confidence"])).toString("utf8")
);
}
if (output.headers["x-amz-lex-alternative-intents"] !== undefined) {
contents.alternativeIntents = new __LazyJsonString(
Buffer.from(output.headers["x-amz-lex-alternative-intents"], "base64").toString("ascii")
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-alternative-intents"])).toString("utf8")
);
}
if (output.headers["x-amz-lex-slots"] !== undefined) {
contents.slots = new __LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii"));
contents.slots = new __LazyJsonString(
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-slots"])).toString("utf8")
);
}
if (output.headers["x-amz-lex-session-attributes"] !== undefined) {
contents.sessionAttributes = new __LazyJsonString(
Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii")
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-session-attributes"])).toString("utf8")
);
}
if (output.headers["x-amz-lex-sentiment"] !== undefined) {
Expand Down Expand Up @@ -623,7 +627,7 @@ export const deserializeAws_restJson1PostContentCommand = async (
}
if (output.headers["x-amz-lex-active-contexts"] !== undefined) {
contents.activeContexts = new __LazyJsonString(
Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii")
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-active-contexts"])).toString("utf8")
);
}
const data: any = output.body;
Expand Down Expand Up @@ -940,11 +944,13 @@ export const deserializeAws_restJson1PutSessionCommand = async (
contents.intentName = output.headers["x-amz-lex-intent-name"];
}
if (output.headers["x-amz-lex-slots"] !== undefined) {
contents.slots = new __LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii"));
contents.slots = new __LazyJsonString(
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-slots"])).toString("utf8")
);
}
if (output.headers["x-amz-lex-session-attributes"] !== undefined) {
contents.sessionAttributes = new __LazyJsonString(
Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii")
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-session-attributes"])).toString("utf8")
);
}
if (output.headers["x-amz-lex-message"] !== undefined) {
Expand All @@ -967,7 +973,7 @@ export const deserializeAws_restJson1PutSessionCommand = async (
}
if (output.headers["x-amz-lex-active-contexts"] !== undefined) {
contents.activeContexts = new __LazyJsonString(
Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii")
Buffer.from(context.base64Decoder(output.headers["x-amz-lex-active-contexts"])).toString("utf8")
);
}
const data: any = output.body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,6 @@ private static boolean filterMalformedRequestTests(
if (testCase.getId().equals("RestJsonBodyMalformedMapNullValue")) {
return true;
}
//TODO: Buffer.from isn't decoding base64 strictly.
if (testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case1")
|| testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case2")) {
return true;
}

//TODO: Fixed after Smithy 1.11.0
if (testCase.getId().equals("RestJsonPathTimestampDefaultRejectsDifferent8601Formats_case14")) {
Expand Down
4 changes: 2 additions & 2 deletions protocol_tests/aws-restjson/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ export const serializeAws_restJson1MediaTypeHeaderCommand = async (
const { hostname, protocol = "https", port, path: basePath } = await context.endpoint();
const headers: any = {
...(isSerializableHeaderValue(input.json) && {
"x-json": Buffer.from(__LazyJsonString.fromObject(input.json!)).toString("base64"),
"x-json": context.base64Encoder(Buffer.from(__LazyJsonString.fromObject(input.json!))),
}),
};
let resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/MediaTypeHeader";
Expand Down Expand Up @@ -3299,7 +3299,7 @@ export const deserializeAws_restJson1MediaTypeHeaderCommand = async (
json: undefined,
};
if (output.headers["x-json"] !== undefined) {
contents.json = new __LazyJsonString(Buffer.from(output.headers["x-json"], "base64").toString("ascii"));
contents.json = new __LazyJsonString(Buffer.from(context.base64Decoder(output.headers["x-json"])).toString("utf8"));
}
await collectBody(output.body, context);
return Promise.resolve(contents);
Expand Down

0 comments on commit e171183

Please sign in to comment.