Skip to content

Commit

Permalink
chore(codegen): use lib serde helpers instead of codegen (#5855)
Browse files Browse the repository at this point in the history
* chore(codegen): use lib serde helpers instead of codegen

* feat: write error.$responseBodyText if available

* chore: codegen update to use imported serde helper functions

* chore: unused imports
  • Loading branch information
kuhe committed Mar 6, 2024
1 parent 6d98191 commit 304ca3e
Show file tree
Hide file tree
Showing 419 changed files with 811 additions and 19,675 deletions.
58 changes: 6 additions & 52 deletions clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// smithy-typescript generated code
import { awsExpectUnion as __expectUnion } from "@aws-sdk/core";
import {
awsExpectUnion as __expectUnion,
loadRestJsonErrorCode,
parseJsonBody as parseBody,
parseJsonErrorBody as parseErrorBody,
} from "@aws-sdk/core";
import { requestBuilder as rb } from "@smithy/core";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
import {
Expand Down Expand Up @@ -2452,54 +2457,3 @@ const _rAS = "retryAfterSeconds";
const _ra = "retry-after";
const _t = "type";
const _tK = "tagKeys";

const parseBody = (streamBody: any, context: __SerdeContext): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});

const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {
const value = await parseBody(errorBody, context);
value.message = value.message ?? value.Message;
return value;
};

/**
* Load an error code for the aws.rest-json-1.1 protocol.
*/
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => {
const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());

const sanitizeErrorCode = (rawValue: string | number): string => {
let cleanValue = rawValue;
if (typeof cleanValue === "number") {
cleanValue = cleanValue.toString();
}
if (cleanValue.indexOf(",") >= 0) {
cleanValue = cleanValue.split(",")[0];
}
if (cleanValue.indexOf(":") >= 0) {
cleanValue = cleanValue.split(":")[0];
}
if (cleanValue.indexOf("#") >= 0) {
cleanValue = cleanValue.split("#")[1];
}
return cleanValue;
};

const headerKey = findKey(output.headers, "x-amzn-errortype");
if (headerKey !== undefined) {
return sanitizeErrorCode(output.headers[headerKey]);
}

if (data.code !== undefined) {
return sanitizeErrorCode(data.code);
}

if (data["__type"] !== undefined) {
return sanitizeErrorCode(data["__type"]);
}
};
52 changes: 1 addition & 51 deletions clients/client-account/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// smithy-typescript generated code
import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core";
import { requestBuilder as rb } from "@smithy/core";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
import {
Expand Down Expand Up @@ -626,54 +627,3 @@ const isSerializableHeaderValue = (value: any): boolean =>
value !== "" &&
(!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) &&
(!Object.getOwnPropertyNames(value).includes("size") || value.size != 0);

const parseBody = (streamBody: any, context: __SerdeContext): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});

const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {
const value = await parseBody(errorBody, context);
value.message = value.message ?? value.Message;
return value;
};

/**
* Load an error code for the aws.rest-json-1.1 protocol.
*/
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => {
const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());

const sanitizeErrorCode = (rawValue: string | number): string => {
let cleanValue = rawValue;
if (typeof cleanValue === "number") {
cleanValue = cleanValue.toString();
}
if (cleanValue.indexOf(",") >= 0) {
cleanValue = cleanValue.split(",")[0];
}
if (cleanValue.indexOf(":") >= 0) {
cleanValue = cleanValue.split(":")[0];
}
if (cleanValue.indexOf("#") >= 0) {
cleanValue = cleanValue.split("#")[1];
}
return cleanValue;
};

const headerKey = findKey(output.headers, "x-amzn-errortype");
if (headerKey !== undefined) {
return sanitizeErrorCode(output.headers[headerKey]);
}

if (data.code !== undefined) {
return sanitizeErrorCode(data.code);
}

if (data["__type"] !== undefined) {
return sanitizeErrorCode(data["__type"]);
}
};
52 changes: 1 addition & 51 deletions clients/client-acm-pca/src/protocols/Aws_json1_1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// smithy-typescript generated code
import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
import {
_json,
Expand Down Expand Up @@ -1639,54 +1640,3 @@ function sharedHeaders(operation: string): __HeaderBag {
"x-amz-target": `ACMPrivateCA.${operation}`,
};
}

const parseBody = (streamBody: any, context: __SerdeContext): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});

const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {
const value = await parseBody(errorBody, context);
value.message = value.message ?? value.Message;
return value;
};

/**
* Load an error code for the aws.rest-json-1.1 protocol.
*/
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => {
const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());

const sanitizeErrorCode = (rawValue: string | number): string => {
let cleanValue = rawValue;
if (typeof cleanValue === "number") {
cleanValue = cleanValue.toString();
}
if (cleanValue.indexOf(",") >= 0) {
cleanValue = cleanValue.split(",")[0];
}
if (cleanValue.indexOf(":") >= 0) {
cleanValue = cleanValue.split(":")[0];
}
if (cleanValue.indexOf("#") >= 0) {
cleanValue = cleanValue.split("#")[1];
}
return cleanValue;
};

const headerKey = findKey(output.headers, "x-amzn-errortype");
if (headerKey !== undefined) {
return sanitizeErrorCode(output.headers[headerKey]);
}

if (data.code !== undefined) {
return sanitizeErrorCode(data.code);
}

if (data["__type"] !== undefined) {
return sanitizeErrorCode(data["__type"]);
}
};
52 changes: 1 addition & 51 deletions clients/client-acm/src/protocols/Aws_json1_1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// smithy-typescript generated code
import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
import {
_json,
Expand Down Expand Up @@ -1178,54 +1179,3 @@ function sharedHeaders(operation: string): __HeaderBag {
"x-amz-target": `CertificateManager.${operation}`,
};
}

const parseBody = (streamBody: any, context: __SerdeContext): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});

const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {
const value = await parseBody(errorBody, context);
value.message = value.message ?? value.Message;
return value;
};

/**
* Load an error code for the aws.rest-json-1.1 protocol.
*/
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => {
const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());

const sanitizeErrorCode = (rawValue: string | number): string => {
let cleanValue = rawValue;
if (typeof cleanValue === "number") {
cleanValue = cleanValue.toString();
}
if (cleanValue.indexOf(",") >= 0) {
cleanValue = cleanValue.split(",")[0];
}
if (cleanValue.indexOf(":") >= 0) {
cleanValue = cleanValue.split(":")[0];
}
if (cleanValue.indexOf("#") >= 0) {
cleanValue = cleanValue.split("#")[1];
}
return cleanValue;
};

const headerKey = findKey(output.headers, "x-amzn-errortype");
if (headerKey !== undefined) {
return sanitizeErrorCode(output.headers[headerKey]);
}

if (data.code !== undefined) {
return sanitizeErrorCode(data.code);
}

if (data["__type"] !== undefined) {
return sanitizeErrorCode(data["__type"]);
}
};
52 changes: 1 addition & 51 deletions clients/client-alexa-for-business/src/protocols/Aws_json1_1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// smithy-typescript generated code
import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
import {
_json,
Expand Down Expand Up @@ -4730,54 +4731,3 @@ function sharedHeaders(operation: string): __HeaderBag {
"x-amz-target": `AlexaForBusiness.${operation}`,
};
}

const parseBody = (streamBody: any, context: __SerdeContext): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});

const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {
const value = await parseBody(errorBody, context);
value.message = value.message ?? value.Message;
return value;
};

/**
* Load an error code for the aws.rest-json-1.1 protocol.
*/
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => {
const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());

const sanitizeErrorCode = (rawValue: string | number): string => {
let cleanValue = rawValue;
if (typeof cleanValue === "number") {
cleanValue = cleanValue.toString();
}
if (cleanValue.indexOf(",") >= 0) {
cleanValue = cleanValue.split(",")[0];
}
if (cleanValue.indexOf(":") >= 0) {
cleanValue = cleanValue.split(":")[0];
}
if (cleanValue.indexOf("#") >= 0) {
cleanValue = cleanValue.split("#")[1];
}
return cleanValue;
};

const headerKey = findKey(output.headers, "x-amzn-errortype");
if (headerKey !== undefined) {
return sanitizeErrorCode(output.headers[headerKey]);
}

if (data.code !== undefined) {
return sanitizeErrorCode(data.code);
}

if (data["__type"] !== undefined) {
return sanitizeErrorCode(data["__type"]);
}
};
58 changes: 6 additions & 52 deletions clients/client-amp/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// smithy-typescript generated code
import { awsExpectUnion as __expectUnion } from "@aws-sdk/core";
import {
awsExpectUnion as __expectUnion,
loadRestJsonErrorCode,
parseJsonBody as parseBody,
parseJsonErrorBody as parseErrorBody,
} from "@aws-sdk/core";
import { requestBuilder as rb } from "@smithy/core";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
import {
Expand Down Expand Up @@ -1642,54 +1647,3 @@ const _nT = "nextToken";
const _rAS = "retryAfterSeconds";
const _ra = "retry-after";
const _tK = "tagKeys";

const parseBody = (streamBody: any, context: __SerdeContext): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});

const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {
const value = await parseBody(errorBody, context);
value.message = value.message ?? value.Message;
return value;
};

/**
* Load an error code for the aws.rest-json-1.1 protocol.
*/
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => {
const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());

const sanitizeErrorCode = (rawValue: string | number): string => {
let cleanValue = rawValue;
if (typeof cleanValue === "number") {
cleanValue = cleanValue.toString();
}
if (cleanValue.indexOf(",") >= 0) {
cleanValue = cleanValue.split(",")[0];
}
if (cleanValue.indexOf(":") >= 0) {
cleanValue = cleanValue.split(":")[0];
}
if (cleanValue.indexOf("#") >= 0) {
cleanValue = cleanValue.split("#")[1];
}
return cleanValue;
};

const headerKey = findKey(output.headers, "x-amzn-errortype");
if (headerKey !== undefined) {
return sanitizeErrorCode(output.headers[headerKey]);
}

if (data.code !== undefined) {
return sanitizeErrorCode(data.code);
}

if (data["__type"] !== undefined) {
return sanitizeErrorCode(data["__type"]);
}
};
Loading

0 comments on commit 304ca3e

Please sign in to comment.