Skip to content

Commit

Permalink
fix(protocol_tests): update protocol test
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Apr 20, 2021
1 parent c43448c commit c42f8bd
Show file tree
Hide file tree
Showing 12 changed files with 711 additions and 115 deletions.
68 changes: 68 additions & 0 deletions protocol_tests/aws-restjson/RestJsonProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import {
GreetingWithErrorsCommandInput,
GreetingWithErrorsCommandOutput,
} from "./commands/GreetingWithErrorsCommand";
import {
HttpEnumPayloadCommand,
HttpEnumPayloadCommandInput,
HttpEnumPayloadCommandOutput,
} from "./commands/HttpEnumPayloadCommand";
import {
HttpPayloadTraitsCommand,
HttpPayloadTraitsCommandInput,
Expand Down Expand Up @@ -79,6 +84,11 @@ import {
HttpResponseCodeCommandInput,
HttpResponseCodeCommandOutput,
} from "./commands/HttpResponseCodeCommand";
import {
HttpStringPayloadCommand,
HttpStringPayloadCommandInput,
HttpStringPayloadCommandOutput,
} from "./commands/HttpStringPayloadCommand";
import {
IgnoreQueryParamsInResponseCommand,
IgnoreQueryParamsInResponseCommandInput,
Expand Down Expand Up @@ -425,6 +435,35 @@ export class RestJsonProtocol extends RestJsonProtocolClient {
}
}

public httpEnumPayload(
args: HttpEnumPayloadCommandInput,
options?: __HttpHandlerOptions
): Promise<HttpEnumPayloadCommandOutput>;
public httpEnumPayload(
args: HttpEnumPayloadCommandInput,
cb: (err: any, data?: HttpEnumPayloadCommandOutput) => void
): void;
public httpEnumPayload(
args: HttpEnumPayloadCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: HttpEnumPayloadCommandOutput) => void
): void;
public httpEnumPayload(
args: HttpEnumPayloadCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: HttpEnumPayloadCommandOutput) => void),
cb?: (err: any, data?: HttpEnumPayloadCommandOutput) => void
): Promise<HttpEnumPayloadCommandOutput> | void {
const command = new HttpEnumPayloadCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* This examples serializes a blob shape in the payload.
*
Expand Down Expand Up @@ -718,6 +757,35 @@ export class RestJsonProtocol extends RestJsonProtocolClient {
}
}

public httpStringPayload(
args: HttpStringPayloadCommandInput,
options?: __HttpHandlerOptions
): Promise<HttpStringPayloadCommandOutput>;
public httpStringPayload(
args: HttpStringPayloadCommandInput,
cb: (err: any, data?: HttpStringPayloadCommandOutput) => void
): void;
public httpStringPayload(
args: HttpStringPayloadCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: HttpStringPayloadCommandOutput) => void
): void;
public httpStringPayload(
args: HttpStringPayloadCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: HttpStringPayloadCommandOutput) => void),
cb?: (err: any, data?: HttpStringPayloadCommandOutput) => void
): Promise<HttpStringPayloadCommandOutput> | void {
const command = new HttpStringPayloadCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* This example ensures that query string bound request parameters are
* serialized in the body of responses if the structure is used in both
Expand Down
6 changes: 6 additions & 0 deletions protocol_tests/aws-restjson/RestJsonProtocolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EndpointWithHostLabelOperationCommandOutput,
} from "./commands/EndpointWithHostLabelOperationCommand";
import { GreetingWithErrorsCommandInput, GreetingWithErrorsCommandOutput } from "./commands/GreetingWithErrorsCommand";
import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "./commands/HttpEnumPayloadCommand";
import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "./commands/HttpPayloadTraitsCommand";
import {
HttpPayloadTraitsWithMediaTypeCommandInput,
Expand Down Expand Up @@ -47,6 +48,7 @@ import {
HttpRequestWithLabelsCommandOutput,
} from "./commands/HttpRequestWithLabelsCommand";
import { HttpResponseCodeCommandInput, HttpResponseCodeCommandOutput } from "./commands/HttpResponseCodeCommand";
import { HttpStringPayloadCommandInput, HttpStringPayloadCommandOutput } from "./commands/HttpStringPayloadCommand";
import {
IgnoreQueryParamsInResponseCommandInput,
IgnoreQueryParamsInResponseCommandOutput,
Expand Down Expand Up @@ -167,6 +169,7 @@ export type ServiceInputTypes =
| EndpointOperationCommandInput
| EndpointWithHostLabelOperationCommandInput
| GreetingWithErrorsCommandInput
| HttpEnumPayloadCommandInput
| HttpPayloadTraitsCommandInput
| HttpPayloadTraitsWithMediaTypeCommandInput
| HttpPayloadWithStructureCommandInput
Expand All @@ -176,6 +179,7 @@ export type ServiceInputTypes =
| HttpRequestWithLabelsAndTimestampFormatCommandInput
| HttpRequestWithLabelsCommandInput
| HttpResponseCodeCommandInput
| HttpStringPayloadCommandInput
| IgnoreQueryParamsInResponseCommandInput
| InlineDocumentAsPayloadCommandInput
| InlineDocumentCommandInput
Expand Down Expand Up @@ -210,6 +214,7 @@ export type ServiceOutputTypes =
| EndpointOperationCommandOutput
| EndpointWithHostLabelOperationCommandOutput
| GreetingWithErrorsCommandOutput
| HttpEnumPayloadCommandOutput
| HttpPayloadTraitsCommandOutput
| HttpPayloadTraitsWithMediaTypeCommandOutput
| HttpPayloadWithStructureCommandOutput
Expand All @@ -219,6 +224,7 @@ export type ServiceOutputTypes =
| HttpRequestWithLabelsAndTimestampFormatCommandOutput
| HttpRequestWithLabelsCommandOutput
| HttpResponseCodeCommandOutput
| HttpStringPayloadCommandOutput
| IgnoreQueryParamsInResponseCommandOutput
| InlineDocumentAsPayloadCommandOutput
| InlineDocumentCommandOutput
Expand Down
2 changes: 2 additions & 0 deletions protocol_tests/aws-restjson/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "./commands/EmptyInputAndEmptyOutputCommand";
export * from "./commands/EndpointOperationCommand";
export * from "./commands/EndpointWithHostLabelOperationCommand";
export * from "./commands/GreetingWithErrorsCommand";
export * from "./commands/HttpEnumPayloadCommand";
export * from "./commands/HttpPayloadTraitsCommand";
export * from "./commands/HttpPayloadTraitsWithMediaTypeCommand";
export * from "./commands/HttpPayloadWithStructureCommand";
Expand All @@ -16,6 +17,7 @@ export * from "./commands/HttpRequestWithGreedyLabelInPathCommand";
export * from "./commands/HttpRequestWithLabelsCommand";
export * from "./commands/HttpRequestWithLabelsAndTimestampFormatCommand";
export * from "./commands/HttpResponseCodeCommand";
export * from "./commands/HttpStringPayloadCommand";
export * from "./commands/IgnoreQueryParamsInResponseCommand";
export * from "./commands/InlineDocumentCommand";
export * from "./commands/InlineDocumentAsPayloadCommand";
Expand Down
24 changes: 24 additions & 0 deletions protocol_tests/aws-restjson/models/models_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ export namespace HostLabelInput {
});
}

export enum StringEnum {
V = "enumvalue",
}

export interface EnumPayloadInput {
payload?: StringEnum | string;
}

export namespace EnumPayloadInput {
export const filterSensitiveLog = (obj: EnumPayloadInput): any => ({
...obj,
});
}

/**
* This error has test cases that test some of the dark corners of Amazon service
* framework history. It should only be implemented by clients.
Expand Down Expand Up @@ -291,6 +305,16 @@ export namespace HttpResponseCodeOutput {
});
}

export interface StringPayloadInput {
payload?: string;
}

export namespace StringPayloadInput {
export const filterSensitiveLog = (obj: StringPayloadInput): any => ({
...obj,
});
}

export interface IgnoreQueryParamsInResponseOutput {
baz?: string;
}
Expand Down
140 changes: 140 additions & 0 deletions protocol_tests/aws-restjson/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EndpointWithHostLabelOperationCommandOutput,
} from "../commands/EndpointWithHostLabelOperationCommand";
import { GreetingWithErrorsCommandInput, GreetingWithErrorsCommandOutput } from "../commands/GreetingWithErrorsCommand";
import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "../commands/HttpEnumPayloadCommand";
import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "../commands/HttpPayloadTraitsCommand";
import {
HttpPayloadTraitsWithMediaTypeCommandInput,
Expand Down Expand Up @@ -47,6 +48,7 @@ import {
HttpRequestWithLabelsCommandOutput,
} from "../commands/HttpRequestWithLabelsCommand";
import { HttpResponseCodeCommandInput, HttpResponseCodeCommandOutput } from "../commands/HttpResponseCodeCommand";
import { HttpStringPayloadCommandInput, HttpStringPayloadCommandOutput } from "../commands/HttpStringPayloadCommand";
import {
IgnoreQueryParamsInResponseCommandInput,
IgnoreQueryParamsInResponseCommandOutput,
Expand Down Expand Up @@ -364,6 +366,30 @@ export const serializeAws_restJson1GreetingWithErrorsCommand = async (
});
};

export const serializeAws_restJson1HttpEnumPayloadCommand = async (
input: HttpEnumPayloadCommandInput,
context: __SerdeContext
): Promise<__HttpRequest> => {
const headers: any = {
"content-type": "text/plain",
};
let resolvedPath = "/EnumPayload";
let body: any;
if (input.payload !== undefined) {
body = input.payload;
}
const { hostname, protocol = "https", port } = await context.endpoint();
return new __HttpRequest({
protocol,
hostname,
port,
method: "POST",
headers,
path: resolvedPath,
body,
});
};

export const serializeAws_restJson1HttpPayloadTraitsCommand = async (
input: HttpPayloadTraitsCommandInput,
context: __SerdeContext
Expand Down Expand Up @@ -728,6 +754,30 @@ export const serializeAws_restJson1HttpResponseCodeCommand = async (
});
};

export const serializeAws_restJson1HttpStringPayloadCommand = async (
input: HttpStringPayloadCommandInput,
context: __SerdeContext
): Promise<__HttpRequest> => {
const headers: any = {
"content-type": "text/plain",
};
let resolvedPath = "/StringPayload";
let body: any;
if (input.payload !== undefined) {
body = input.payload;
}
const { hostname, protocol = "https", port } = await context.endpoint();
return new __HttpRequest({
protocol,
hostname,
port,
method: "POST",
headers,
path: resolvedPath,
body,
});
};

export const serializeAws_restJson1IgnoreQueryParamsInResponseCommand = async (
input: IgnoreQueryParamsInResponseCommandInput,
context: __SerdeContext
Expand Down Expand Up @@ -1782,6 +1832,51 @@ const deserializeAws_restJson1GreetingWithErrorsCommandError = async (
return Promise.reject(Object.assign(new Error(message), response));
};

export const deserializeAws_restJson1HttpEnumPayloadCommand = async (
output: __HttpResponse,
context: __SerdeContext
): Promise<HttpEnumPayloadCommandOutput> => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1HttpEnumPayloadCommandError(output, context);
}
const contents: HttpEnumPayloadCommandOutput = {
$metadata: deserializeMetadata(output),
payload: undefined,
};
const data: any = await collectBodyString(output.body, context);
contents.payload = data;
return Promise.resolve(contents);
};

const deserializeAws_restJson1HttpEnumPayloadCommandError = async (
output: __HttpResponse,
context: __SerdeContext
): Promise<HttpEnumPayloadCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
};
let response: __SmithyException & __MetadataBearer & { [key: string]: any };
let errorCode: string = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.code || parsedBody.Code || errorCode;
response = {
...parsedBody,
name: `${errorCode}`,
message: parsedBody.message || parsedBody.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
} as any;
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};

export const deserializeAws_restJson1HttpPayloadTraitsCommand = async (
output: __HttpResponse,
context: __SerdeContext
Expand Down Expand Up @@ -2209,6 +2304,51 @@ const deserializeAws_restJson1HttpResponseCodeCommandError = async (
return Promise.reject(Object.assign(new Error(message), response));
};

export const deserializeAws_restJson1HttpStringPayloadCommand = async (
output: __HttpResponse,
context: __SerdeContext
): Promise<HttpStringPayloadCommandOutput> => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1HttpStringPayloadCommandError(output, context);
}
const contents: HttpStringPayloadCommandOutput = {
$metadata: deserializeMetadata(output),
payload: undefined,
};
const data: any = await collectBodyString(output.body, context);
contents.payload = data;
return Promise.resolve(contents);
};

const deserializeAws_restJson1HttpStringPayloadCommandError = async (
output: __HttpResponse,
context: __SerdeContext
): Promise<HttpStringPayloadCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
};
let response: __SmithyException & __MetadataBearer & { [key: string]: any };
let errorCode: string = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.code || parsedBody.Code || errorCode;
response = {
...parsedBody,
name: `${errorCode}`,
message: parsedBody.message || parsedBody.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
} as any;
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};

export const deserializeAws_restJson1IgnoreQueryParamsInResponseCommand = async (
output: __HttpResponse,
context: __SerdeContext
Expand Down

0 comments on commit c42f8bd

Please sign in to comment.