Skip to content
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

feat(codegen): general data mapping function #3830

Merged
merged 4 commits into from Aug 2, 2022
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -43,6 +43,7 @@ dist
dist-*

/verdaccio/*
/storage/.verdaccio-db.json
!/verdaccio/config.yaml

*.tsbuildinfo
Expand Down
1,062 changes: 428 additions & 634 deletions clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts

Large diffs are not rendered by default.

124 changes: 55 additions & 69 deletions clients/client-account/src/protocols/Aws_restJson1.ts
Expand Up @@ -5,6 +5,8 @@ import {
expectNonNull as __expectNonNull,
expectObject as __expectObject,
expectString as __expectString,
map as __map,
throwDefaultError,
} from "@aws-sdk/smithy-client";
import {
Endpoint as __Endpoint,
Expand Down Expand Up @@ -181,11 +183,11 @@ export const deserializeAws_restJson1DeleteAlternateContactCommand = async (
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1DeleteAlternateContactCommandError(output, context);
}
const contents: DeleteAlternateContactCommandOutput = {
const contents: any = map({
$metadata: deserializeMetadata(output),
};
});
await collectBody(output.body, context);
return Promise.resolve(contents);
return contents;
};

const deserializeAws_restJson1DeleteAlternateContactCommandError = async (
Expand All @@ -196,7 +198,6 @@ const deserializeAws_restJson1DeleteAlternateContactCommandError = async (
...output,
body: await parseBody(output.body, context),
};
let response: __BaseException;
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
Expand All @@ -216,14 +217,12 @@ const deserializeAws_restJson1DeleteAlternateContactCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata,
throwDefaultError({
output,
parsedBody,
exceptionCtor: __BaseException,
errorCode,
});
throw __decorateServiceException(response, parsedBody);
}
};

Expand All @@ -234,15 +233,14 @@ export const deserializeAws_restJson1GetAlternateContactCommand = async (
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1GetAlternateContactCommandError(output, context);
}
const contents: GetAlternateContactCommandOutput = {
const contents: any = map({
$metadata: deserializeMetadata(output),
AlternateContact: undefined,
};
});
const data: Record<string, any> = __expectNonNull(__expectObject(await parseBody(output.body, context)), "body");
if (data.AlternateContact !== undefined && data.AlternateContact !== null) {
if (data.AlternateContact != null) {
contents.AlternateContact = deserializeAws_restJson1AlternateContact(data.AlternateContact, context);
}
return Promise.resolve(contents);
return contents;
};

const deserializeAws_restJson1GetAlternateContactCommandError = async (
Expand All @@ -253,7 +251,6 @@ const deserializeAws_restJson1GetAlternateContactCommandError = async (
...output,
body: await parseBody(output.body, context),
};
let response: __BaseException;
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
Expand All @@ -273,14 +270,12 @@ const deserializeAws_restJson1GetAlternateContactCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata,
throwDefaultError({
output,
parsedBody,
exceptionCtor: __BaseException,
errorCode,
});
throw __decorateServiceException(response, parsedBody);
}
};

Expand All @@ -291,15 +286,14 @@ export const deserializeAws_restJson1GetContactInformationCommand = async (
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1GetContactInformationCommandError(output, context);
}
const contents: GetContactInformationCommandOutput = {
const contents: any = map({
$metadata: deserializeMetadata(output),
ContactInformation: undefined,
};
});
const data: Record<string, any> = __expectNonNull(__expectObject(await parseBody(output.body, context)), "body");
if (data.ContactInformation !== undefined && data.ContactInformation !== null) {
if (data.ContactInformation != null) {
contents.ContactInformation = deserializeAws_restJson1ContactInformation(data.ContactInformation, context);
}
return Promise.resolve(contents);
return contents;
};

const deserializeAws_restJson1GetContactInformationCommandError = async (
Expand All @@ -310,7 +304,6 @@ const deserializeAws_restJson1GetContactInformationCommandError = async (
...output,
body: await parseBody(output.body, context),
};
let response: __BaseException;
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
Expand All @@ -330,14 +323,12 @@ const deserializeAws_restJson1GetContactInformationCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata,
throwDefaultError({
output,
parsedBody,
exceptionCtor: __BaseException,
errorCode,
});
throw __decorateServiceException(response, parsedBody);
}
};

Expand All @@ -348,11 +339,11 @@ export const deserializeAws_restJson1PutAlternateContactCommand = async (
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1PutAlternateContactCommandError(output, context);
}
const contents: PutAlternateContactCommandOutput = {
const contents: any = map({
$metadata: deserializeMetadata(output),
};
});
await collectBody(output.body, context);
return Promise.resolve(contents);
return contents;
};

const deserializeAws_restJson1PutAlternateContactCommandError = async (
Expand All @@ -363,7 +354,6 @@ const deserializeAws_restJson1PutAlternateContactCommandError = async (
...output,
body: await parseBody(output.body, context),
};
let response: __BaseException;
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
Expand All @@ -380,14 +370,12 @@ const deserializeAws_restJson1PutAlternateContactCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata,
throwDefaultError({
output,
parsedBody,
exceptionCtor: __BaseException,
errorCode,
});
throw __decorateServiceException(response, parsedBody);
}
};

Expand All @@ -398,11 +386,11 @@ export const deserializeAws_restJson1PutContactInformationCommand = async (
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1PutContactInformationCommandError(output, context);
}
const contents: PutContactInformationCommandOutput = {
const contents: any = map({
$metadata: deserializeMetadata(output),
};
});
await collectBody(output.body, context);
return Promise.resolve(contents);
return contents;
};

const deserializeAws_restJson1PutContactInformationCommandError = async (
Expand All @@ -413,7 +401,6 @@ const deserializeAws_restJson1PutContactInformationCommandError = async (
...output,
body: await parseBody(output.body, context),
};
let response: __BaseException;
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
Expand All @@ -430,24 +417,23 @@ const deserializeAws_restJson1PutContactInformationCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata,
throwDefaultError({
output,
parsedBody,
exceptionCtor: __BaseException,
errorCode,
});
throw __decorateServiceException(response, parsedBody);
}
};

const map = __map;
const deserializeAws_restJson1AccessDeniedExceptionResponse = async (
parsedOutput: any,
context: __SerdeContext
): Promise<AccessDeniedException> => {
const contents: any = {};
const contents: any = map({});
const data: any = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
if (data.message != null) {
contents.message = __expectString(data.message);
}
const exception = new AccessDeniedException({
Expand All @@ -461,9 +447,9 @@ const deserializeAws_restJson1InternalServerExceptionResponse = async (
parsedOutput: any,
context: __SerdeContext
): Promise<InternalServerException> => {
const contents: any = {};
const contents: any = map({});
const data: any = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
if (data.message != null) {
contents.message = __expectString(data.message);
}
const exception = new InternalServerException({
Expand All @@ -477,9 +463,9 @@ const deserializeAws_restJson1ResourceNotFoundExceptionResponse = async (
parsedOutput: any,
context: __SerdeContext
): Promise<ResourceNotFoundException> => {
const contents: any = {};
const contents: any = map({});
const data: any = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
if (data.message != null) {
contents.message = __expectString(data.message);
}
const exception = new ResourceNotFoundException({
Expand All @@ -493,9 +479,9 @@ const deserializeAws_restJson1TooManyRequestsExceptionResponse = async (
parsedOutput: any,
context: __SerdeContext
): Promise<TooManyRequestsException> => {
const contents: any = {};
const contents: any = map({});
const data: any = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
if (data.message != null) {
contents.message = __expectString(data.message);
}
const exception = new TooManyRequestsException({
Expand All @@ -509,9 +495,9 @@ const deserializeAws_restJson1ValidationExceptionResponse = async (
parsedOutput: any,
context: __SerdeContext
): Promise<ValidationException> => {
const contents: any = {};
const contents: any = map({});
const data: any = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
if (data.message != null) {
contents.message = __expectString(data.message);
}
const exception = new ValidationException({
Expand Down