Skip to content

chore(codegen): use lib serde helpers instead of codegen #5855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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