;
+ httpEmptyPrefixHeaders(
+ args: HttpEmptyPrefixHeadersCommandInput,
+ cb: (err: any, data?: HttpEmptyPrefixHeadersCommandOutput) => void
+ ): void;
+ httpEmptyPrefixHeaders(
+ args: HttpEmptyPrefixHeadersCommandInput,
+ options: __HttpHandlerOptions,
+ cb: (err: any, data?: HttpEmptyPrefixHeadersCommandOutput) => void
+ ): void;
+
/**
* @see {@link HttpEnumPayloadCommand}
*/
diff --git a/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts b/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts
index 56e96a0f94e9..5310b45e7ddc 100644
--- a/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts
+++ b/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts
@@ -109,6 +109,10 @@ import {
HttpChecksumRequiredCommandInput,
HttpChecksumRequiredCommandOutput,
} from "./commands/HttpChecksumRequiredCommand";
+import {
+ HttpEmptyPrefixHeadersCommandInput,
+ HttpEmptyPrefixHeadersCommandOutput,
+} from "./commands/HttpEmptyPrefixHeadersCommand";
import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "./commands/HttpEnumPayloadCommand";
import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "./commands/HttpPayloadTraitsCommand";
import {
@@ -375,6 +379,7 @@ export type ServiceInputTypes =
| GreetingWithErrorsCommandInput
| HostWithPathOperationCommandInput
| HttpChecksumRequiredCommandInput
+ | HttpEmptyPrefixHeadersCommandInput
| HttpEnumPayloadCommandInput
| HttpPayloadTraitsCommandInput
| HttpPayloadTraitsWithMediaTypeCommandInput
@@ -484,6 +489,7 @@ export type ServiceOutputTypes =
| GreetingWithErrorsCommandOutput
| HostWithPathOperationCommandOutput
| HttpChecksumRequiredCommandOutput
+ | HttpEmptyPrefixHeadersCommandOutput
| HttpEnumPayloadCommandOutput
| HttpPayloadTraitsCommandOutput
| HttpPayloadTraitsWithMediaTypeCommandOutput
diff --git a/private/aws-protocoltests-restjson/src/commands/GreetingWithErrorsCommand.ts b/private/aws-protocoltests-restjson/src/commands/GreetingWithErrorsCommand.ts
index 508e82674200..0b0a5f8d4230 100644
--- a/private/aws-protocoltests-restjson/src/commands/GreetingWithErrorsCommand.ts
+++ b/private/aws-protocoltests-restjson/src/commands/GreetingWithErrorsCommand.ts
@@ -57,15 +57,15 @@ export interface GreetingWithErrorsCommandOutput extends GreetingWithErrorsOutpu
* @see {@link GreetingWithErrorsCommandOutput} for command's `response` shape.
* @see {@link RestJsonProtocolClientResolvedConfig | config} for RestJsonProtocolClient's `config` shape.
*
- * @throws {@link FooError} (server fault)
- * This error has test cases that test some of the dark corners of Amazon service
- * framework history. It should only be implemented by clients.
+ * @throws {@link InvalidGreeting} (client fault)
+ * This error is thrown when an invalid greeting value is provided.
*
* @throws {@link ComplexError} (client fault)
* This error is thrown when a request is invalid.
*
- * @throws {@link InvalidGreeting} (client fault)
- * This error is thrown when an invalid greeting value is provided.
+ * @throws {@link FooError} (server fault)
+ * This error has test cases that test some of the dark corners of Amazon service
+ * framework history. It should only be implemented by clients.
*
* @throws {@link RestJsonProtocolServiceException}
* Base exception class for all service exceptions from RestJsonProtocol service.
diff --git a/private/aws-protocoltests-restjson/src/commands/HttpEmptyPrefixHeadersCommand.ts b/private/aws-protocoltests-restjson/src/commands/HttpEmptyPrefixHeadersCommand.ts
new file mode 100644
index 000000000000..397fe143295d
--- /dev/null
+++ b/private/aws-protocoltests-restjson/src/commands/HttpEmptyPrefixHeadersCommand.ts
@@ -0,0 +1,93 @@
+// smithy-typescript generated code
+import { getSerdePlugin } from "@smithy/middleware-serde";
+import { Command as $Command } from "@smithy/smithy-client";
+import { MetadataBearer as __MetadataBearer } from "@smithy/types";
+
+import { HttpEmptyPrefixHeadersInput, HttpEmptyPrefixHeadersOutput } from "../models/models_0";
+import { de_HttpEmptyPrefixHeadersCommand, se_HttpEmptyPrefixHeadersCommand } from "../protocols/Aws_restJson1";
+import { RestJsonProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../RestJsonProtocolClient";
+
+/**
+ * @public
+ */
+export type { __MetadataBearer };
+export { $Command };
+/**
+ * @public
+ *
+ * The input for {@link HttpEmptyPrefixHeadersCommand}.
+ */
+export interface HttpEmptyPrefixHeadersCommandInput extends HttpEmptyPrefixHeadersInput {}
+/**
+ * @public
+ *
+ * The output of {@link HttpEmptyPrefixHeadersCommand}.
+ */
+export interface HttpEmptyPrefixHeadersCommandOutput extends HttpEmptyPrefixHeadersOutput, __MetadataBearer {}
+
+/**
+ * Clients that perform this test extract all headers from the response.
+ * @example
+ * Use a bare-bones client and the command you need to make an API call.
+ * ```javascript
+ * import { RestJsonProtocolClient, HttpEmptyPrefixHeadersCommand } from "@aws-sdk/aws-protocoltests-restjson"; // ES Modules import
+ * // const { RestJsonProtocolClient, HttpEmptyPrefixHeadersCommand } = require("@aws-sdk/aws-protocoltests-restjson"); // CommonJS import
+ * const client = new RestJsonProtocolClient(config);
+ * const input = { // HttpEmptyPrefixHeadersInput
+ * prefixHeaders: { // StringMap
+ * "": "STRING_VALUE",
+ * },
+ * specificHeader: "STRING_VALUE",
+ * };
+ * const command = new HttpEmptyPrefixHeadersCommand(input);
+ * const response = await client.send(command);
+ * // { // HttpEmptyPrefixHeadersOutput
+ * // prefixHeaders: { // StringMap
+ * // "": "STRING_VALUE",
+ * // },
+ * // specificHeader: "STRING_VALUE",
+ * // };
+ *
+ * ```
+ *
+ * @param HttpEmptyPrefixHeadersCommandInput - {@link HttpEmptyPrefixHeadersCommandInput}
+ * @returns {@link HttpEmptyPrefixHeadersCommandOutput}
+ * @see {@link HttpEmptyPrefixHeadersCommandInput} for command's `input` shape.
+ * @see {@link HttpEmptyPrefixHeadersCommandOutput} for command's `response` shape.
+ * @see {@link RestJsonProtocolClientResolvedConfig | config} for RestJsonProtocolClient's `config` shape.
+ *
+ * @throws {@link RestJsonProtocolServiceException}
+ * Base exception class for all service exceptions from RestJsonProtocol service.
+ *
+ *
+ * @public
+ */
+export class HttpEmptyPrefixHeadersCommand extends $Command
+ .classBuilder<
+ HttpEmptyPrefixHeadersCommandInput,
+ HttpEmptyPrefixHeadersCommandOutput,
+ RestJsonProtocolClientResolvedConfig,
+ ServiceInputTypes,
+ ServiceOutputTypes
+ >()
+ .m(function (this: any, Command: any, cs: any, config: RestJsonProtocolClientResolvedConfig, o: any) {
+ return [getSerdePlugin(config, this.serialize, this.deserialize)];
+ })
+ .s("RestJson", "HttpEmptyPrefixHeaders", {})
+ .n("RestJsonProtocolClient", "HttpEmptyPrefixHeadersCommand")
+ .f(void 0, void 0)
+ .ser(se_HttpEmptyPrefixHeadersCommand)
+ .de(de_HttpEmptyPrefixHeadersCommand)
+ .build() {
+ /** @internal type navigation helper, not in runtime. */
+ protected declare static __types: {
+ api: {
+ input: HttpEmptyPrefixHeadersInput;
+ output: HttpEmptyPrefixHeadersOutput;
+ };
+ sdk: {
+ input: HttpEmptyPrefixHeadersCommandInput;
+ output: HttpEmptyPrefixHeadersCommandOutput;
+ };
+ };
+}
diff --git a/private/aws-protocoltests-restjson/src/commands/index.ts b/private/aws-protocoltests-restjson/src/commands/index.ts
index 6623b538bd7e..f7eda1900482 100644
--- a/private/aws-protocoltests-restjson/src/commands/index.ts
+++ b/private/aws-protocoltests-restjson/src/commands/index.ts
@@ -14,6 +14,7 @@ export * from "./FractionalSecondsCommand";
export * from "./GreetingWithErrorsCommand";
export * from "./HostWithPathOperationCommand";
export * from "./HttpChecksumRequiredCommand";
+export * from "./HttpEmptyPrefixHeadersCommand";
export * from "./HttpEnumPayloadCommand";
export * from "./HttpPayloadTraitsCommand";
export * from "./HttpPayloadTraitsWithMediaTypeCommand";
diff --git a/private/aws-protocoltests-restjson/src/models/models_0.ts b/private/aws-protocoltests-restjson/src/models/models_0.ts
index b6c85cff7236..fd6778ad51ae 100644
--- a/private/aws-protocoltests-restjson/src/models/models_0.ts
+++ b/private/aws-protocoltests-restjson/src/models/models_0.ts
@@ -328,6 +328,22 @@ export interface HttpChecksumRequiredInputOutput {
foo?: string | undefined;
}
+/**
+ * @public
+ */
+export interface HttpEmptyPrefixHeadersInput {
+ prefixHeaders?: Record | undefined;
+ specificHeader?: string | undefined;
+}
+
+/**
+ * @public
+ */
+export interface HttpEmptyPrefixHeadersOutput {
+ prefixHeaders?: Record | undefined;
+ specificHeader?: string | undefined;
+}
+
/**
* @public
*/
diff --git a/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts b/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts
index 86463ad43a99..8e2842a902f6 100644
--- a/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts
+++ b/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts
@@ -105,6 +105,10 @@ import {
HttpChecksumRequiredCommandInput,
HttpChecksumRequiredCommandOutput,
} from "../commands/HttpChecksumRequiredCommand";
+import {
+ HttpEmptyPrefixHeadersCommandInput,
+ HttpEmptyPrefixHeadersCommandOutput,
+} from "../commands/HttpEmptyPrefixHeadersCommand";
import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "../commands/HttpEnumPayloadCommand";
import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "../commands/HttpPayloadTraitsCommand";
import {
@@ -724,6 +728,28 @@ export const se_HttpChecksumRequiredCommand = async (
return b.build();
};
+/**
+ * serializeAws_restJson1HttpEmptyPrefixHeadersCommand
+ */
+export const se_HttpEmptyPrefixHeadersCommand = async (
+ input: HttpEmptyPrefixHeadersCommandInput,
+ context: __SerdeContext
+): Promise<__HttpRequest> => {
+ const b = rb(input, context);
+ const headers: any = map({}, isSerializableHeaderValue, {
+ ...(input.prefixHeaders !== undefined &&
+ Object.keys(input.prefixHeaders).reduce((acc: any, suffix: string) => {
+ acc[`${suffix.toLowerCase()}`] = input.prefixHeaders![suffix];
+ return acc;
+ }, {})),
+ [_h]: input[_sH]!,
+ });
+ b.bp("/HttpEmptyPrefixHeaders");
+ let body: any;
+ b.m("GET").h(headers).b(body);
+ return b.build();
+};
+
/**
* serializeAws_restJson1HttpEnumPayloadCommand
*/
@@ -843,12 +869,12 @@ export const se_HttpPrefixHeadersCommand = async (
): Promise<__HttpRequest> => {
const b = rb(input, context);
const headers: any = map({}, isSerializableHeaderValue, {
- [_xf]: input[_f]!,
...(input.fooMap !== undefined &&
Object.keys(input.fooMap).reduce((acc: any, suffix: string) => {
acc[`x-foo-${suffix.toLowerCase()}`] = input.fooMap![suffix];
return acc;
}, {})),
+ [_xf]: input[_f]!,
});
b.bp("/HttpPrefixHeaders");
let body: any;
@@ -2922,6 +2948,33 @@ export const de_HttpChecksumRequiredCommand = async (
return contents;
};
+/**
+ * deserializeAws_restJson1HttpEmptyPrefixHeadersCommand
+ */
+export const de_HttpEmptyPrefixHeadersCommand = async (
+ output: __HttpResponse,
+ context: __SerdeContext
+): Promise => {
+ if (output.statusCode !== 200 && output.statusCode >= 300) {
+ return de_CommandError(output, context);
+ }
+ const contents: any = map({
+ $metadata: deserializeMetadata(output),
+ [_sH]: [, output.headers[_h]],
+ prefixHeaders: [
+ ,
+ Object.keys(output.headers)
+ .filter((header) => header.startsWith(""))
+ .reduce((acc, header) => {
+ acc[header.substring(0)] = output.headers[header];
+ return acc;
+ }, {} as any),
+ ],
+ });
+ await collectBody(output.body, context);
+ return contents;
+};
+
/**
* deserializeAws_restJson1HttpEnumPayloadCommand
*/
@@ -5519,6 +5572,7 @@ const _qSu = "queryShort";
const _qT = "queryTimestamp";
const _qTL = "queryTimestampList";
const _s = "shortinheader";
+const _sH = "specificHeader";
const _sIH = "shortInHeader";
const _sIQ = "shortInQuery";
const _t = "timestamp";
diff --git a/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts b/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts
index 1a8cad7801e7..e7884ac2d07b 100644
--- a/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts
+++ b/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts
@@ -20,6 +20,7 @@ import { FractionalSecondsCommand } from "../../src/commands/FractionalSecondsCo
import { GreetingWithErrorsCommand } from "../../src/commands/GreetingWithErrorsCommand";
import { HostWithPathOperationCommand } from "../../src/commands/HostWithPathOperationCommand";
import { HttpChecksumRequiredCommand } from "../../src/commands/HttpChecksumRequiredCommand";
+import { HttpEmptyPrefixHeadersCommand } from "../../src/commands/HttpEmptyPrefixHeadersCommand";
import { HttpEnumPayloadCommand } from "../../src/commands/HttpEnumPayloadCommand";
import { HttpPayloadTraitsCommand } from "../../src/commands/HttpPayloadTraitsCommand";
import { HttpPayloadTraitsWithMediaTypeCommand } from "../../src/commands/HttpPayloadTraitsWithMediaTypeCommand";
@@ -1793,14 +1794,22 @@ it("RestJsonGreetingWithErrorsNoPayload:Response", async () => {
});
/**
- * Serializes the X-Amzn-ErrorType header. For an example service, see Amazon EKS.
+ * Parses simple JSON errors
*/
-it("RestJsonFooErrorUsingXAmznErrorType:Error:GreetingWithErrors", async () => {
+it("RestJsonInvalidGreetingError:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
- requestHandler: new ResponseDeserializationTestHandler(false, 500, {
- "x-amzn-errortype": "FooError",
- }),
+ requestHandler: new ResponseDeserializationTestHandler(
+ false,
+ 400,
+ {
+ "x-amzn-errortype": "InvalidGreeting",
+ "content-type": "application/json",
+ },
+ `{
+ "Message": "Hi"
+ }`
+ ),
});
const params: any = {};
@@ -1809,30 +1818,51 @@ it("RestJsonFooErrorUsingXAmznErrorType:Error:GreetingWithErrors", async () => {
try {
await client.send(command);
} catch (err) {
- if (err.name !== "FooError") {
+ if (err.name !== "InvalidGreeting") {
console.log(err);
- fail(`Expected a FooError to be thrown, got ${err.name} instead`);
+ fail(`Expected a InvalidGreeting to be thrown, got ${err.name} instead`);
return;
}
const r: any = err;
- expect(r["$metadata"].httpStatusCode).toBe(500);
+ expect(r["$metadata"].httpStatusCode).toBe(400);
+ const paramsToValidate: any = [
+ {
+ message: "Hi",
+ },
+ ][0];
+ Object.keys(paramsToValidate).forEach((param) => {
+ expect(
+ r[param],
+ `The output field ${param} should have been defined in ${JSON.stringify(r, null, 2)}`
+ ).toBeDefined();
+ expect(equivalentContents(paramsToValidate[param], r[param])).toBe(true);
+ });
return;
}
fail("Expected an exception to be thrown from response");
});
/**
- * Some X-Amzn-Errortype headers contain URLs. Clients need to split the URL on ':' and take only the first half of the string. For example, 'ValidationException:http://internal.amazon.com/coral/com.amazon.coral.validate/'
- * is to be interpreted as 'ValidationException'.
- *
- * For an example service see Amazon Polly.
+ * Serializes a complex error with no message member
*/
-it("RestJsonFooErrorUsingXAmznErrorTypeWithUri:Error:GreetingWithErrors", async () => {
+it("RestJsonComplexErrorWithNoMessage:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
- requestHandler: new ResponseDeserializationTestHandler(false, 500, {
- "x-amzn-errortype": "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
- }),
+ requestHandler: new ResponseDeserializationTestHandler(
+ false,
+ 403,
+ {
+ "x-amzn-errortype": "ComplexError",
+ "x-header": "Header",
+ "content-type": "application/json",
+ },
+ `{
+ "TopLevel": "Top level",
+ "Nested": {
+ "Fooooo": "bar"
+ }
+ }`
+ ),
});
const params: any = {};
@@ -1841,28 +1871,46 @@ it("RestJsonFooErrorUsingXAmznErrorTypeWithUri:Error:GreetingWithErrors", async
try {
await client.send(command);
} catch (err) {
- if (err.name !== "FooError") {
+ if (err.name !== "ComplexError") {
console.log(err);
- fail(`Expected a FooError to be thrown, got ${err.name} instead`);
+ fail(`Expected a ComplexError to be thrown, got ${err.name} instead`);
return;
}
const r: any = err;
- expect(r["$metadata"].httpStatusCode).toBe(500);
+ expect(r["$metadata"].httpStatusCode).toBe(403);
+ const paramsToValidate: any = [
+ {
+ Header: "Header",
+ TopLevel: "Top level",
+ Nested: {
+ Foo: "bar",
+ },
+ },
+ ][0];
+ Object.keys(paramsToValidate).forEach((param) => {
+ expect(
+ r[param],
+ `The output field ${param} should have been defined in ${JSON.stringify(r, null, 2)}`
+ ).toBeDefined();
+ expect(equivalentContents(paramsToValidate[param], r[param])).toBe(true);
+ });
return;
}
fail("Expected an exception to be thrown from response");
});
-/**
- * X-Amzn-Errortype might contain a URL and a namespace. Client should extract only the shape name. This is a pathalogical case that might not actually happen in any deployed AWS service.
- */
-it("RestJsonFooErrorUsingXAmznErrorTypeWithUriAndNamespace:Error:GreetingWithErrors", async () => {
+it("RestJsonEmptyComplexErrorWithNoMessage:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
- requestHandler: new ResponseDeserializationTestHandler(false, 500, {
- "x-amzn-errortype":
- "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
- }),
+ requestHandler: new ResponseDeserializationTestHandler(
+ false,
+ 403,
+ {
+ "x-amzn-errortype": "ComplexError",
+ "content-type": "application/json",
+ },
+ `{}`
+ ),
});
const params: any = {};
@@ -1871,36 +1919,27 @@ it("RestJsonFooErrorUsingXAmznErrorTypeWithUriAndNamespace:Error:GreetingWithErr
try {
await client.send(command);
} catch (err) {
- if (err.name !== "FooError") {
+ if (err.name !== "ComplexError") {
console.log(err);
- fail(`Expected a FooError to be thrown, got ${err.name} instead`);
+ fail(`Expected a ComplexError to be thrown, got ${err.name} instead`);
return;
}
const r: any = err;
- expect(r["$metadata"].httpStatusCode).toBe(500);
+ expect(r["$metadata"].httpStatusCode).toBe(403);
return;
}
fail("Expected an exception to be thrown from response");
});
/**
- * This example uses the 'code' property in the output rather than X-Amzn-Errortype. Some services do this though it's preferable to send the X-Amzn-Errortype. Client implementations must first check for the X-Amzn-Errortype and then check for a top-level 'code' property.
- *
- * For example service see Amazon S3 Glacier.
+ * Serializes the X-Amzn-ErrorType header. For an example service, see Amazon EKS.
*/
-it("RestJsonFooErrorUsingCode:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorUsingXAmznErrorType:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
- requestHandler: new ResponseDeserializationTestHandler(
- false,
- 500,
- {
- "content-type": "application/json",
- },
- `{
- "code": "FooError"
- }`
- ),
+ requestHandler: new ResponseDeserializationTestHandler(false, 500, {
+ "x-amzn-errortype": "FooError",
+ }),
});
const params: any = {};
@@ -1922,21 +1961,17 @@ it("RestJsonFooErrorUsingCode:Error:GreetingWithErrors", async () => {
});
/**
- * Some services serialize errors using code, and it might contain a namespace. Clients should just take the last part of the string after '#'.
+ * Some X-Amzn-Errortype headers contain URLs. Clients need to split the URL on ':' and take only the first half of the string. For example, 'ValidationException:http://internal.amazon.com/coral/com.amazon.coral.validate/'
+ * is to be interpreted as 'ValidationException'.
+ *
+ * For an example service see Amazon Polly.
*/
-it("RestJsonFooErrorUsingCodeAndNamespace:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorUsingXAmznErrorTypeWithUri:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
- requestHandler: new ResponseDeserializationTestHandler(
- false,
- 500,
- {
- "content-type": "application/json",
- },
- `{
- "code": "aws.protocoltests.restjson#FooError"
- }`
- ),
+ requestHandler: new ResponseDeserializationTestHandler(false, 500, {
+ "x-amzn-errortype": "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
+ }),
});
const params: any = {};
@@ -1958,21 +1993,15 @@ it("RestJsonFooErrorUsingCodeAndNamespace:Error:GreetingWithErrors", async () =>
});
/**
- * Some services serialize errors using code, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
+ * X-Amzn-Errortype might contain a URL and a namespace. Client should extract only the shape name. This is a pathalogical case that might not actually happen in any deployed AWS service.
*/
-it("RestJsonFooErrorUsingCodeUriAndNamespace:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorUsingXAmznErrorTypeWithUriAndNamespace:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
- requestHandler: new ResponseDeserializationTestHandler(
- false,
- 500,
- {
- "content-type": "application/json",
- },
- `{
- "code": "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
- }`
- ),
+ requestHandler: new ResponseDeserializationTestHandler(false, 500, {
+ "x-amzn-errortype":
+ "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
+ }),
});
const params: any = {};
@@ -1994,9 +2023,11 @@ it("RestJsonFooErrorUsingCodeUriAndNamespace:Error:GreetingWithErrors", async ()
});
/**
- * Some services serialize errors using __type.
+ * This example uses the 'code' property in the output rather than X-Amzn-Errortype. Some services do this though it's preferable to send the X-Amzn-Errortype. Client implementations must first check for the X-Amzn-Errortype and then check for a top-level 'code' property.
+ *
+ * For example service see Amazon S3 Glacier.
*/
-it("RestJsonFooErrorWithDunderType:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorUsingCode:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
requestHandler: new ResponseDeserializationTestHandler(
@@ -2006,7 +2037,7 @@ it("RestJsonFooErrorWithDunderType:Error:GreetingWithErrors", async () => {
"content-type": "application/json",
},
`{
- "__type": "FooError"
+ "code": "FooError"
}`
),
});
@@ -2030,9 +2061,9 @@ it("RestJsonFooErrorWithDunderType:Error:GreetingWithErrors", async () => {
});
/**
- * Some services serialize errors using __type, and it might contain a namespace. Clients should just take the last part of the string after '#'.
+ * Some services serialize errors using code, and it might contain a namespace. Clients should just take the last part of the string after '#'.
*/
-it("RestJsonFooErrorWithDunderTypeAndNamespace:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorUsingCodeAndNamespace:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
requestHandler: new ResponseDeserializationTestHandler(
@@ -2042,7 +2073,7 @@ it("RestJsonFooErrorWithDunderTypeAndNamespace:Error:GreetingWithErrors", async
"content-type": "application/json",
},
`{
- "__type": "aws.protocoltests.restjson#FooError"
+ "code": "aws.protocoltests.restjson#FooError"
}`
),
});
@@ -2066,9 +2097,9 @@ it("RestJsonFooErrorWithDunderTypeAndNamespace:Error:GreetingWithErrors", async
});
/**
- * Some services serialize errors using __type, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
+ * Some services serialize errors using code, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
*/
-it("RestJsonFooErrorWithDunderTypeUriAndNamespace:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorUsingCodeUriAndNamespace:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
requestHandler: new ResponseDeserializationTestHandler(
@@ -2078,7 +2109,7 @@ it("RestJsonFooErrorWithDunderTypeUriAndNamespace:Error:GreetingWithErrors", asy
"content-type": "application/json",
},
`{
- "__type": "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
+ "code": "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
}`
),
});
@@ -2102,24 +2133,19 @@ it("RestJsonFooErrorWithDunderTypeUriAndNamespace:Error:GreetingWithErrors", asy
});
/**
- * Serializes a complex error with no message member
+ * Some services serialize errors using __type.
*/
-it("RestJsonComplexErrorWithNoMessage:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorWithDunderType:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
requestHandler: new ResponseDeserializationTestHandler(
false,
- 403,
+ 500,
{
- "x-amzn-errortype": "ComplexError",
- "x-header": "Header",
"content-type": "application/json",
},
`{
- "TopLevel": "Top level",
- "Nested": {
- "Fooooo": "bar"
- }
+ "__type": "FooError"
}`
),
});
@@ -2130,45 +2156,33 @@ it("RestJsonComplexErrorWithNoMessage:Error:GreetingWithErrors", async () => {
try {
await client.send(command);
} catch (err) {
- if (err.name !== "ComplexError") {
+ if (err.name !== "FooError") {
console.log(err);
- fail(`Expected a ComplexError to be thrown, got ${err.name} instead`);
+ fail(`Expected a FooError to be thrown, got ${err.name} instead`);
return;
}
const r: any = err;
- expect(r["$metadata"].httpStatusCode).toBe(403);
- const paramsToValidate: any = [
- {
- Header: "Header",
- TopLevel: "Top level",
- Nested: {
- Foo: "bar",
- },
- },
- ][0];
- Object.keys(paramsToValidate).forEach((param) => {
- expect(
- r[param],
- `The output field ${param} should have been defined in ${JSON.stringify(r, null, 2)}`
- ).toBeDefined();
- expect(equivalentContents(paramsToValidate[param], r[param])).toBe(true);
- });
+ expect(r["$metadata"].httpStatusCode).toBe(500);
return;
}
fail("Expected an exception to be thrown from response");
});
-it("RestJsonEmptyComplexErrorWithNoMessage:Error:GreetingWithErrors", async () => {
+/**
+ * Some services serialize errors using __type, and it might contain a namespace. Clients should just take the last part of the string after '#'.
+ */
+it("RestJsonFooErrorWithDunderTypeAndNamespace:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
requestHandler: new ResponseDeserializationTestHandler(
false,
- 403,
+ 500,
{
- "x-amzn-errortype": "ComplexError",
"content-type": "application/json",
},
- `{}`
+ `{
+ "__type": "aws.protocoltests.restjson#FooError"
+ }`
),
});
@@ -2178,33 +2192,32 @@ it("RestJsonEmptyComplexErrorWithNoMessage:Error:GreetingWithErrors", async () =
try {
await client.send(command);
} catch (err) {
- if (err.name !== "ComplexError") {
+ if (err.name !== "FooError") {
console.log(err);
- fail(`Expected a ComplexError to be thrown, got ${err.name} instead`);
+ fail(`Expected a FooError to be thrown, got ${err.name} instead`);
return;
}
const r: any = err;
- expect(r["$metadata"].httpStatusCode).toBe(403);
+ expect(r["$metadata"].httpStatusCode).toBe(500);
return;
}
fail("Expected an exception to be thrown from response");
});
/**
- * Parses simple JSON errors
+ * Some services serialize errors using __type, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
*/
-it("RestJsonInvalidGreetingError:Error:GreetingWithErrors", async () => {
+it("RestJsonFooErrorWithDunderTypeUriAndNamespace:Error:GreetingWithErrors", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
requestHandler: new ResponseDeserializationTestHandler(
false,
- 400,
+ 500,
{
- "x-amzn-errortype": "InvalidGreeting",
"content-type": "application/json",
},
`{
- "Message": "Hi"
+ "__type": "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
}`
),
});
@@ -2215,25 +2228,13 @@ it("RestJsonInvalidGreetingError:Error:GreetingWithErrors", async () => {
try {
await client.send(command);
} catch (err) {
- if (err.name !== "InvalidGreeting") {
+ if (err.name !== "FooError") {
console.log(err);
- fail(`Expected a InvalidGreeting to be thrown, got ${err.name} instead`);
+ fail(`Expected a FooError to be thrown, got ${err.name} instead`);
return;
}
const r: any = err;
- expect(r["$metadata"].httpStatusCode).toBe(400);
- const paramsToValidate: any = [
- {
- message: "Hi",
- },
- ][0];
- Object.keys(paramsToValidate).forEach((param) => {
- expect(
- r[param],
- `The output field ${param} should have been defined in ${JSON.stringify(r, null, 2)}`
- ).toBeDefined();
- expect(equivalentContents(paramsToValidate[param], r[param])).toBe(true);
- });
+ expect(r["$metadata"].httpStatusCode).toBe(500);
return;
}
fail("Expected an exception to be thrown from response");
@@ -2306,6 +2307,83 @@ it("RestJsonHttpChecksumRequired:Request", async () => {
}
});
+/**
+ * Serializes all request headers, using specific when present
+ */
+it("RestJsonHttpEmptyPrefixHeadersRequestClient:Request", async () => {
+ const client = new RestJsonProtocolClient({
+ ...clientParams,
+ requestHandler: new RequestSerializationTestHandler(),
+ });
+
+ const command = new HttpEmptyPrefixHeadersCommand({
+ prefixHeaders: {
+ "x-foo": "Foo",
+ hello: "Hello",
+ } as any,
+ specificHeader: "There",
+ } as any);
+ try {
+ await client.send(command);
+ fail("Expected an EXPECTED_REQUEST_SERIALIZATION_ERROR to be thrown");
+ return;
+ } catch (err) {
+ if (!(err instanceof EXPECTED_REQUEST_SERIALIZATION_ERROR)) {
+ fail(err);
+ return;
+ }
+ const r = err.request;
+ expect(r.method).toBe("GET");
+ expect(r.path).toBe("/HttpEmptyPrefixHeaders");
+
+ expect(r.headers["hello"]).toBe("There");
+ expect(r.headers["x-foo"]).toBe("Foo");
+
+ expect(!r.body || r.body === `{}`).toBeTruthy();
+ }
+});
+
+/**
+ * Deserializes all response headers with the same for prefix and specific
+ */
+it("RestJsonHttpEmptyPrefixHeadersResponseClient:Response", async () => {
+ const client = new RestJsonProtocolClient({
+ ...clientParams,
+ requestHandler: new ResponseDeserializationTestHandler(true, 200, {
+ "x-foo": "Foo",
+ hello: "There",
+ }),
+ });
+
+ const params: any = {};
+ const command = new HttpEmptyPrefixHeadersCommand(params);
+
+ let r: any;
+ try {
+ r = await client.send(command);
+ } catch (err) {
+ fail("Expected a valid response to be returned, got " + err);
+ return;
+ }
+ expect(r["$metadata"].httpStatusCode).toBe(200);
+ const paramsToValidate: any = [
+ {
+ prefixHeaders: {
+ "x-foo": "Foo",
+ hello: "There",
+ },
+ specificHeader: "There",
+ },
+ ][0];
+ Object.keys(paramsToValidate).forEach((param) => {
+ expect(
+ r[param],
+ `The output field ${param} should have been defined in ${JSON.stringify(r, null, 2)}`
+ ).toBeDefined();
+ expect(equivalentContents(paramsToValidate[param], r[param])).toBe(true);
+ });
+});
+
it("RestJsonEnumPayloadRequest:Request", async () => {
const client = new RestJsonProtocolClient({
...clientParams,
diff --git a/private/aws-protocoltests-restxml/README.md b/private/aws-protocoltests-restxml/README.md
index dc72ab39fefe..032461861391 100644
--- a/private/aws-protocoltests-restxml/README.md
+++ b/private/aws-protocoltests-restxml/README.md
@@ -1058,6 +1058,14 @@ HttpChecksumRequired
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/rest-xml-protocol/command/HttpChecksumRequiredCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-rest-xml-protocol/Interface/HttpChecksumRequiredCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-rest-xml-protocol/Interface/HttpChecksumRequiredCommandOutput/)
+