Skip to content

Commit c42f8bd

Browse files
committed
fix(protocol_tests): update protocol test
1 parent c43448c commit c42f8bd

File tree

12 files changed

+711
-115
lines changed

12 files changed

+711
-115
lines changed

protocol_tests/aws-restjson/RestJsonProtocol.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ import {
3434
GreetingWithErrorsCommandInput,
3535
GreetingWithErrorsCommandOutput,
3636
} from "./commands/GreetingWithErrorsCommand";
37+
import {
38+
HttpEnumPayloadCommand,
39+
HttpEnumPayloadCommandInput,
40+
HttpEnumPayloadCommandOutput,
41+
} from "./commands/HttpEnumPayloadCommand";
3742
import {
3843
HttpPayloadTraitsCommand,
3944
HttpPayloadTraitsCommandInput,
@@ -79,6 +84,11 @@ import {
7984
HttpResponseCodeCommandInput,
8085
HttpResponseCodeCommandOutput,
8186
} from "./commands/HttpResponseCodeCommand";
87+
import {
88+
HttpStringPayloadCommand,
89+
HttpStringPayloadCommandInput,
90+
HttpStringPayloadCommandOutput,
91+
} from "./commands/HttpStringPayloadCommand";
8292
import {
8393
IgnoreQueryParamsInResponseCommand,
8494
IgnoreQueryParamsInResponseCommandInput,
@@ -425,6 +435,35 @@ export class RestJsonProtocol extends RestJsonProtocolClient {
425435
}
426436
}
427437

438+
public httpEnumPayload(
439+
args: HttpEnumPayloadCommandInput,
440+
options?: __HttpHandlerOptions
441+
): Promise<HttpEnumPayloadCommandOutput>;
442+
public httpEnumPayload(
443+
args: HttpEnumPayloadCommandInput,
444+
cb: (err: any, data?: HttpEnumPayloadCommandOutput) => void
445+
): void;
446+
public httpEnumPayload(
447+
args: HttpEnumPayloadCommandInput,
448+
options: __HttpHandlerOptions,
449+
cb: (err: any, data?: HttpEnumPayloadCommandOutput) => void
450+
): void;
451+
public httpEnumPayload(
452+
args: HttpEnumPayloadCommandInput,
453+
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: HttpEnumPayloadCommandOutput) => void),
454+
cb?: (err: any, data?: HttpEnumPayloadCommandOutput) => void
455+
): Promise<HttpEnumPayloadCommandOutput> | void {
456+
const command = new HttpEnumPayloadCommand(args);
457+
if (typeof optionsOrCb === "function") {
458+
this.send(command, optionsOrCb);
459+
} else if (typeof cb === "function") {
460+
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
461+
this.send(command, optionsOrCb || {}, cb);
462+
} else {
463+
return this.send(command, optionsOrCb);
464+
}
465+
}
466+
428467
/**
429468
* This examples serializes a blob shape in the payload.
430469
*
@@ -718,6 +757,35 @@ export class RestJsonProtocol extends RestJsonProtocolClient {
718757
}
719758
}
720759

760+
public httpStringPayload(
761+
args: HttpStringPayloadCommandInput,
762+
options?: __HttpHandlerOptions
763+
): Promise<HttpStringPayloadCommandOutput>;
764+
public httpStringPayload(
765+
args: HttpStringPayloadCommandInput,
766+
cb: (err: any, data?: HttpStringPayloadCommandOutput) => void
767+
): void;
768+
public httpStringPayload(
769+
args: HttpStringPayloadCommandInput,
770+
options: __HttpHandlerOptions,
771+
cb: (err: any, data?: HttpStringPayloadCommandOutput) => void
772+
): void;
773+
public httpStringPayload(
774+
args: HttpStringPayloadCommandInput,
775+
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: HttpStringPayloadCommandOutput) => void),
776+
cb?: (err: any, data?: HttpStringPayloadCommandOutput) => void
777+
): Promise<HttpStringPayloadCommandOutput> | void {
778+
const command = new HttpStringPayloadCommand(args);
779+
if (typeof optionsOrCb === "function") {
780+
this.send(command, optionsOrCb);
781+
} else if (typeof cb === "function") {
782+
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
783+
this.send(command, optionsOrCb || {}, cb);
784+
} else {
785+
return this.send(command, optionsOrCb);
786+
}
787+
}
788+
721789
/**
722790
* This example ensures that query string bound request parameters are
723791
* serialized in the body of responses if the structure is used in both

protocol_tests/aws-restjson/RestJsonProtocolClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
EndpointWithHostLabelOperationCommandOutput,
2121
} from "./commands/EndpointWithHostLabelOperationCommand";
2222
import { GreetingWithErrorsCommandInput, GreetingWithErrorsCommandOutput } from "./commands/GreetingWithErrorsCommand";
23+
import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "./commands/HttpEnumPayloadCommand";
2324
import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "./commands/HttpPayloadTraitsCommand";
2425
import {
2526
HttpPayloadTraitsWithMediaTypeCommandInput,
@@ -47,6 +48,7 @@ import {
4748
HttpRequestWithLabelsCommandOutput,
4849
} from "./commands/HttpRequestWithLabelsCommand";
4950
import { HttpResponseCodeCommandInput, HttpResponseCodeCommandOutput } from "./commands/HttpResponseCodeCommand";
51+
import { HttpStringPayloadCommandInput, HttpStringPayloadCommandOutput } from "./commands/HttpStringPayloadCommand";
5052
import {
5153
IgnoreQueryParamsInResponseCommandInput,
5254
IgnoreQueryParamsInResponseCommandOutput,
@@ -167,6 +169,7 @@ export type ServiceInputTypes =
167169
| EndpointOperationCommandInput
168170
| EndpointWithHostLabelOperationCommandInput
169171
| GreetingWithErrorsCommandInput
172+
| HttpEnumPayloadCommandInput
170173
| HttpPayloadTraitsCommandInput
171174
| HttpPayloadTraitsWithMediaTypeCommandInput
172175
| HttpPayloadWithStructureCommandInput
@@ -176,6 +179,7 @@ export type ServiceInputTypes =
176179
| HttpRequestWithLabelsAndTimestampFormatCommandInput
177180
| HttpRequestWithLabelsCommandInput
178181
| HttpResponseCodeCommandInput
182+
| HttpStringPayloadCommandInput
179183
| IgnoreQueryParamsInResponseCommandInput
180184
| InlineDocumentAsPayloadCommandInput
181185
| InlineDocumentCommandInput
@@ -210,6 +214,7 @@ export type ServiceOutputTypes =
210214
| EndpointOperationCommandOutput
211215
| EndpointWithHostLabelOperationCommandOutput
212216
| GreetingWithErrorsCommandOutput
217+
| HttpEnumPayloadCommandOutput
213218
| HttpPayloadTraitsCommandOutput
214219
| HttpPayloadTraitsWithMediaTypeCommandOutput
215220
| HttpPayloadWithStructureCommandOutput
@@ -219,6 +224,7 @@ export type ServiceOutputTypes =
219224
| HttpRequestWithLabelsAndTimestampFormatCommandOutput
220225
| HttpRequestWithLabelsCommandOutput
221226
| HttpResponseCodeCommandOutput
227+
| HttpStringPayloadCommandOutput
222228
| IgnoreQueryParamsInResponseCommandOutput
223229
| InlineDocumentAsPayloadCommandOutput
224230
| InlineDocumentCommandOutput

protocol_tests/aws-restjson/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from "./commands/EmptyInputAndEmptyOutputCommand";
77
export * from "./commands/EndpointOperationCommand";
88
export * from "./commands/EndpointWithHostLabelOperationCommand";
99
export * from "./commands/GreetingWithErrorsCommand";
10+
export * from "./commands/HttpEnumPayloadCommand";
1011
export * from "./commands/HttpPayloadTraitsCommand";
1112
export * from "./commands/HttpPayloadTraitsWithMediaTypeCommand";
1213
export * from "./commands/HttpPayloadWithStructureCommand";
@@ -16,6 +17,7 @@ export * from "./commands/HttpRequestWithGreedyLabelInPathCommand";
1617
export * from "./commands/HttpRequestWithLabelsCommand";
1718
export * from "./commands/HttpRequestWithLabelsAndTimestampFormatCommand";
1819
export * from "./commands/HttpResponseCodeCommand";
20+
export * from "./commands/HttpStringPayloadCommand";
1921
export * from "./commands/IgnoreQueryParamsInResponseCommand";
2022
export * from "./commands/InlineDocumentCommand";
2123
export * from "./commands/InlineDocumentAsPayloadCommand";

protocol_tests/aws-restjson/models/models_0.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ export namespace HostLabelInput {
126126
});
127127
}
128128

129+
export enum StringEnum {
130+
V = "enumvalue",
131+
}
132+
133+
export interface EnumPayloadInput {
134+
payload?: StringEnum | string;
135+
}
136+
137+
export namespace EnumPayloadInput {
138+
export const filterSensitiveLog = (obj: EnumPayloadInput): any => ({
139+
...obj,
140+
});
141+
}
142+
129143
/**
130144
* This error has test cases that test some of the dark corners of Amazon service
131145
* framework history. It should only be implemented by clients.
@@ -291,6 +305,16 @@ export namespace HttpResponseCodeOutput {
291305
});
292306
}
293307

308+
export interface StringPayloadInput {
309+
payload?: string;
310+
}
311+
312+
export namespace StringPayloadInput {
313+
export const filterSensitiveLog = (obj: StringPayloadInput): any => ({
314+
...obj,
315+
});
316+
}
317+
294318
export interface IgnoreQueryParamsInResponseOutput {
295319
baz?: string;
296320
}

protocol_tests/aws-restjson/protocols/Aws_restJson1.ts

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
EndpointWithHostLabelOperationCommandOutput,
2121
} from "../commands/EndpointWithHostLabelOperationCommand";
2222
import { GreetingWithErrorsCommandInput, GreetingWithErrorsCommandOutput } from "../commands/GreetingWithErrorsCommand";
23+
import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "../commands/HttpEnumPayloadCommand";
2324
import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "../commands/HttpPayloadTraitsCommand";
2425
import {
2526
HttpPayloadTraitsWithMediaTypeCommandInput,
@@ -47,6 +48,7 @@ import {
4748
HttpRequestWithLabelsCommandOutput,
4849
} from "../commands/HttpRequestWithLabelsCommand";
4950
import { HttpResponseCodeCommandInput, HttpResponseCodeCommandOutput } from "../commands/HttpResponseCodeCommand";
51+
import { HttpStringPayloadCommandInput, HttpStringPayloadCommandOutput } from "../commands/HttpStringPayloadCommand";
5052
import {
5153
IgnoreQueryParamsInResponseCommandInput,
5254
IgnoreQueryParamsInResponseCommandOutput,
@@ -364,6 +366,30 @@ export const serializeAws_restJson1GreetingWithErrorsCommand = async (
364366
});
365367
};
366368

369+
export const serializeAws_restJson1HttpEnumPayloadCommand = async (
370+
input: HttpEnumPayloadCommandInput,
371+
context: __SerdeContext
372+
): Promise<__HttpRequest> => {
373+
const headers: any = {
374+
"content-type": "text/plain",
375+
};
376+
let resolvedPath = "/EnumPayload";
377+
let body: any;
378+
if (input.payload !== undefined) {
379+
body = input.payload;
380+
}
381+
const { hostname, protocol = "https", port } = await context.endpoint();
382+
return new __HttpRequest({
383+
protocol,
384+
hostname,
385+
port,
386+
method: "POST",
387+
headers,
388+
path: resolvedPath,
389+
body,
390+
});
391+
};
392+
367393
export const serializeAws_restJson1HttpPayloadTraitsCommand = async (
368394
input: HttpPayloadTraitsCommandInput,
369395
context: __SerdeContext
@@ -728,6 +754,30 @@ export const serializeAws_restJson1HttpResponseCodeCommand = async (
728754
});
729755
};
730756

757+
export const serializeAws_restJson1HttpStringPayloadCommand = async (
758+
input: HttpStringPayloadCommandInput,
759+
context: __SerdeContext
760+
): Promise<__HttpRequest> => {
761+
const headers: any = {
762+
"content-type": "text/plain",
763+
};
764+
let resolvedPath = "/StringPayload";
765+
let body: any;
766+
if (input.payload !== undefined) {
767+
body = input.payload;
768+
}
769+
const { hostname, protocol = "https", port } = await context.endpoint();
770+
return new __HttpRequest({
771+
protocol,
772+
hostname,
773+
port,
774+
method: "POST",
775+
headers,
776+
path: resolvedPath,
777+
body,
778+
});
779+
};
780+
731781
export const serializeAws_restJson1IgnoreQueryParamsInResponseCommand = async (
732782
input: IgnoreQueryParamsInResponseCommandInput,
733783
context: __SerdeContext
@@ -1782,6 +1832,51 @@ const deserializeAws_restJson1GreetingWithErrorsCommandError = async (
17821832
return Promise.reject(Object.assign(new Error(message), response));
17831833
};
17841834

1835+
export const deserializeAws_restJson1HttpEnumPayloadCommand = async (
1836+
output: __HttpResponse,
1837+
context: __SerdeContext
1838+
): Promise<HttpEnumPayloadCommandOutput> => {
1839+
if (output.statusCode !== 200 && output.statusCode >= 300) {
1840+
return deserializeAws_restJson1HttpEnumPayloadCommandError(output, context);
1841+
}
1842+
const contents: HttpEnumPayloadCommandOutput = {
1843+
$metadata: deserializeMetadata(output),
1844+
payload: undefined,
1845+
};
1846+
const data: any = await collectBodyString(output.body, context);
1847+
contents.payload = data;
1848+
return Promise.resolve(contents);
1849+
};
1850+
1851+
const deserializeAws_restJson1HttpEnumPayloadCommandError = async (
1852+
output: __HttpResponse,
1853+
context: __SerdeContext
1854+
): Promise<HttpEnumPayloadCommandOutput> => {
1855+
const parsedOutput: any = {
1856+
...output,
1857+
body: await parseBody(output.body, context),
1858+
};
1859+
let response: __SmithyException & __MetadataBearer & { [key: string]: any };
1860+
let errorCode: string = "UnknownError";
1861+
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
1862+
switch (errorCode) {
1863+
default:
1864+
const parsedBody = parsedOutput.body;
1865+
errorCode = parsedBody.code || parsedBody.Code || errorCode;
1866+
response = {
1867+
...parsedBody,
1868+
name: `${errorCode}`,
1869+
message: parsedBody.message || parsedBody.Message || errorCode,
1870+
$fault: "client",
1871+
$metadata: deserializeMetadata(output),
1872+
} as any;
1873+
}
1874+
const message = response.message || response.Message || errorCode;
1875+
response.message = message;
1876+
delete response.Message;
1877+
return Promise.reject(Object.assign(new Error(message), response));
1878+
};
1879+
17851880
export const deserializeAws_restJson1HttpPayloadTraitsCommand = async (
17861881
output: __HttpResponse,
17871882
context: __SerdeContext
@@ -2209,6 +2304,51 @@ const deserializeAws_restJson1HttpResponseCodeCommandError = async (
22092304
return Promise.reject(Object.assign(new Error(message), response));
22102305
};
22112306

2307+
export const deserializeAws_restJson1HttpStringPayloadCommand = async (
2308+
output: __HttpResponse,
2309+
context: __SerdeContext
2310+
): Promise<HttpStringPayloadCommandOutput> => {
2311+
if (output.statusCode !== 200 && output.statusCode >= 300) {
2312+
return deserializeAws_restJson1HttpStringPayloadCommandError(output, context);
2313+
}
2314+
const contents: HttpStringPayloadCommandOutput = {
2315+
$metadata: deserializeMetadata(output),
2316+
payload: undefined,
2317+
};
2318+
const data: any = await collectBodyString(output.body, context);
2319+
contents.payload = data;
2320+
return Promise.resolve(contents);
2321+
};
2322+
2323+
const deserializeAws_restJson1HttpStringPayloadCommandError = async (
2324+
output: __HttpResponse,
2325+
context: __SerdeContext
2326+
): Promise<HttpStringPayloadCommandOutput> => {
2327+
const parsedOutput: any = {
2328+
...output,
2329+
body: await parseBody(output.body, context),
2330+
};
2331+
let response: __SmithyException & __MetadataBearer & { [key: string]: any };
2332+
let errorCode: string = "UnknownError";
2333+
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
2334+
switch (errorCode) {
2335+
default:
2336+
const parsedBody = parsedOutput.body;
2337+
errorCode = parsedBody.code || parsedBody.Code || errorCode;
2338+
response = {
2339+
...parsedBody,
2340+
name: `${errorCode}`,
2341+
message: parsedBody.message || parsedBody.Message || errorCode,
2342+
$fault: "client",
2343+
$metadata: deserializeMetadata(output),
2344+
} as any;
2345+
}
2346+
const message = response.message || response.Message || errorCode;
2347+
response.message = message;
2348+
delete response.Message;
2349+
return Promise.reject(Object.assign(new Error(message), response));
2350+
};
2351+
22122352
export const deserializeAws_restJson1IgnoreQueryParamsInResponseCommand = async (
22132353
output: __HttpResponse,
22142354
context: __SerdeContext

0 commit comments

Comments
 (0)