diff --git a/codegen/gradle.properties b/codegen/gradle.properties index 4e208b07effa..7222c0ff2b94 100644 --- a/codegen/gradle.properties +++ b/codegen/gradle.properties @@ -1,2 +1,2 @@ -smithyVersion=1.52.0 +smithyVersion=1.53.0 smithyGradleVersion=0.6.0 diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java index a4f1b7333ad3..dad49a7dea5c 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java @@ -400,6 +400,11 @@ private static boolean filterMalformedRequestTests( return true; } + // ToDo: https://github.com/aws/aws-sdk-js-v3/issues/6907 + if (testCase.getId().equals("RestJsonWithoutBodyEmptyInputExpectsEmptyContentType")) { + return true; + } + return false; } } diff --git a/private/aws-protocoltests-json-10/src/JSONRPC10.ts b/private/aws-protocoltests-json-10/src/JSONRPC10.ts index 400e0d2e07ad..3736b21f2f3b 100644 --- a/private/aws-protocoltests-json-10/src/JSONRPC10.ts +++ b/private/aws-protocoltests-json-10/src/JSONRPC10.ts @@ -58,6 +58,11 @@ import { OperationWithRequiredMembersCommandInput, OperationWithRequiredMembersCommandOutput, } from "./commands/OperationWithRequiredMembersCommand"; +import { + OperationWithRequiredMembersWithDefaultsCommand, + OperationWithRequiredMembersWithDefaultsCommandInput, + OperationWithRequiredMembersWithDefaultsCommandOutput, +} from "./commands/OperationWithRequiredMembersWithDefaultsCommand"; import { PutWithContentEncodingCommand, PutWithContentEncodingCommandInput, @@ -83,6 +88,7 @@ const commands = { OperationWithDefaultsCommand, OperationWithNestedStructureCommand, OperationWithRequiredMembersCommand, + OperationWithRequiredMembersWithDefaultsCommand, PutWithContentEncodingCommand, SimpleScalarPropertiesCommand, }; @@ -296,6 +302,24 @@ export interface JSONRPC10 { cb: (err: any, data?: OperationWithRequiredMembersCommandOutput) => void ): void; + /** + * @see {@link OperationWithRequiredMembersWithDefaultsCommand} + */ + operationWithRequiredMembersWithDefaults(): Promise; + operationWithRequiredMembersWithDefaults( + args: OperationWithRequiredMembersWithDefaultsCommandInput, + options?: __HttpHandlerOptions + ): Promise; + operationWithRequiredMembersWithDefaults( + args: OperationWithRequiredMembersWithDefaultsCommandInput, + cb: (err: any, data?: OperationWithRequiredMembersWithDefaultsCommandOutput) => void + ): void; + operationWithRequiredMembersWithDefaults( + args: OperationWithRequiredMembersWithDefaultsCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: OperationWithRequiredMembersWithDefaultsCommandOutput) => void + ): void; + /** * @see {@link PutWithContentEncodingCommand} */ diff --git a/private/aws-protocoltests-json-10/src/JSONRPC10Client.ts b/private/aws-protocoltests-json-10/src/JSONRPC10Client.ts index 0598872cd4d4..66dd75436134 100644 --- a/private/aws-protocoltests-json-10/src/JSONRPC10Client.ts +++ b/private/aws-protocoltests-json-10/src/JSONRPC10Client.ts @@ -93,6 +93,10 @@ import { OperationWithRequiredMembersCommandInput, OperationWithRequiredMembersCommandOutput, } from "./commands/OperationWithRequiredMembersCommand"; +import { + OperationWithRequiredMembersWithDefaultsCommandInput, + OperationWithRequiredMembersWithDefaultsCommandOutput, +} from "./commands/OperationWithRequiredMembersWithDefaultsCommand"; import { PutWithContentEncodingCommandInput, PutWithContentEncodingCommandOutput, @@ -122,6 +126,7 @@ export type ServiceInputTypes = | OperationWithDefaultsCommandInput | OperationWithNestedStructureCommandInput | OperationWithRequiredMembersCommandInput + | OperationWithRequiredMembersWithDefaultsCommandInput | PutWithContentEncodingCommandInput | SimpleScalarPropertiesCommandInput; @@ -141,6 +146,7 @@ export type ServiceOutputTypes = | OperationWithDefaultsCommandOutput | OperationWithNestedStructureCommandOutput | OperationWithRequiredMembersCommandOutput + | OperationWithRequiredMembersWithDefaultsCommandOutput | PutWithContentEncodingCommandOutput | SimpleScalarPropertiesCommandOutput; diff --git a/private/aws-protocoltests-json-10/src/commands/OperationWithRequiredMembersWithDefaultsCommand.ts b/private/aws-protocoltests-json-10/src/commands/OperationWithRequiredMembersWithDefaultsCommand.ts new file mode 100644 index 000000000000..00326913f01b --- /dev/null +++ b/private/aws-protocoltests-json-10/src/commands/OperationWithRequiredMembersWithDefaultsCommand.ts @@ -0,0 +1,106 @@ +// 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 { JSONRPC10ClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../JSONRPC10Client"; +import { OperationWithRequiredMembersWithDefaultsOutput } from "../models/models_0"; +import { + de_OperationWithRequiredMembersWithDefaultsCommand, + se_OperationWithRequiredMembersWithDefaultsCommand, +} from "../protocols/Aws_json1_0"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link OperationWithRequiredMembersWithDefaultsCommand}. + */ +export interface OperationWithRequiredMembersWithDefaultsCommandInput {} +/** + * @public + * + * The output of {@link OperationWithRequiredMembersWithDefaultsCommand}. + */ +export interface OperationWithRequiredMembersWithDefaultsCommandOutput + extends OperationWithRequiredMembersWithDefaultsOutput, + __MetadataBearer {} + +/** + * @public + * + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { JSONRPC10Client, OperationWithRequiredMembersWithDefaultsCommand } from "@aws-sdk/aws-protocoltests-json-10"; // ES Modules import + * // const { JSONRPC10Client, OperationWithRequiredMembersWithDefaultsCommand } = require("@aws-sdk/aws-protocoltests-json-10"); // CommonJS import + * const client = new JSONRPC10Client(config); + * const input = {}; + * const command = new OperationWithRequiredMembersWithDefaultsCommand(input); + * const response = await client.send(command); + * // { // OperationWithRequiredMembersWithDefaultsOutput + * // requiredString: "STRING_VALUE", // required + * // requiredBoolean: true || false, // required + * // requiredList: [ // RequiredStringList // required + * // "STRING_VALUE", + * // ], + * // requiredTimestamp: new Date("TIMESTAMP"), // required + * // requiredBlob: new Uint8Array(), // required + * // requiredByte: 0, // BYTE_VALUE // required + * // requiredShort: Number("short"), // required + * // requiredInteger: Number("int"), // required + * // requiredLong: Number("long"), // required + * // requiredFloat: Number("float"), // required + * // requiredDouble: Number("double"), // required + * // requiredMap: { // RequiredStringMap // required + * // "": "STRING_VALUE", + * // }, + * // requiredEnum: "FOO" || "BAR" || "BAZ", // required + * // requiredIntEnum: 1 || 2, // required + * // }; + * + * ``` + * + * @param OperationWithRequiredMembersWithDefaultsCommandInput - {@link OperationWithRequiredMembersWithDefaultsCommandInput} + * @returns {@link OperationWithRequiredMembersWithDefaultsCommandOutput} + * @see {@link OperationWithRequiredMembersWithDefaultsCommandInput} for command's `input` shape. + * @see {@link OperationWithRequiredMembersWithDefaultsCommandOutput} for command's `response` shape. + * @see {@link JSONRPC10ClientResolvedConfig | config} for JSONRPC10Client's `config` shape. + * + * @throws {@link JSONRPC10ServiceException} + *

Base exception class for all service exceptions from JSONRPC10 service.

+ * + */ +export class OperationWithRequiredMembersWithDefaultsCommand extends $Command + .classBuilder< + OperationWithRequiredMembersWithDefaultsCommandInput, + OperationWithRequiredMembersWithDefaultsCommandOutput, + JSONRPC10ClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .m(function (this: any, Command: any, cs: any, config: JSONRPC10ClientResolvedConfig, o: any) { + return [getSerdePlugin(config, this.serialize, this.deserialize)]; + }) + .s("JsonRpc10", "OperationWithRequiredMembersWithDefaults", {}) + .n("JSONRPC10Client", "OperationWithRequiredMembersWithDefaultsCommand") + .f(void 0, void 0) + .ser(se_OperationWithRequiredMembersWithDefaultsCommand) + .de(de_OperationWithRequiredMembersWithDefaultsCommand) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: {}; + output: OperationWithRequiredMembersWithDefaultsOutput; + }; + sdk: { + input: OperationWithRequiredMembersWithDefaultsCommandInput; + output: OperationWithRequiredMembersWithDefaultsCommandOutput; + }; + }; +} diff --git a/private/aws-protocoltests-json-10/src/commands/index.ts b/private/aws-protocoltests-json-10/src/commands/index.ts index 298a00e5d9fe..62d4da9ffed0 100644 --- a/private/aws-protocoltests-json-10/src/commands/index.ts +++ b/private/aws-protocoltests-json-10/src/commands/index.ts @@ -11,5 +11,6 @@ export * from "./NoInputAndOutputCommand"; export * from "./OperationWithDefaultsCommand"; export * from "./OperationWithNestedStructureCommand"; export * from "./OperationWithRequiredMembersCommand"; +export * from "./OperationWithRequiredMembersWithDefaultsCommand"; export * from "./PutWithContentEncodingCommand"; export * from "./SimpleScalarPropertiesCommand"; diff --git a/private/aws-protocoltests-json-10/src/models/models_0.ts b/private/aws-protocoltests-json-10/src/models/models_0.ts index 850971afdfef..bcdd073298b8 100644 --- a/private/aws-protocoltests-json-10/src/models/models_0.ts +++ b/private/aws-protocoltests-json-10/src/models/models_0.ts @@ -547,6 +547,45 @@ export interface OperationWithRequiredMembersOutput { requiredMap: Record | undefined; } +/** + * @public + * @enum + */ +export const RequiredEnum = { + BAR: "BAR", + BAZ: "BAZ", + FOO: "FOO", +} as const; +/** + * @public + */ +export type RequiredEnum = (typeof RequiredEnum)[keyof typeof RequiredEnum]; + +export enum RequiredIntEnum { + ONE = 1, + TWO = 2, +} + +/** + * @public + */ +export interface OperationWithRequiredMembersWithDefaultsOutput { + requiredString: string | undefined; + requiredBoolean: boolean | undefined; + requiredList: string[] | undefined; + requiredTimestamp: Date | undefined; + requiredBlob: Uint8Array | undefined; + requiredByte: number | undefined; + requiredShort: number | undefined; + requiredInteger: number | undefined; + requiredLong: number | undefined; + requiredFloat: number | undefined; + requiredDouble: number | undefined; + requiredMap: Record | undefined; + requiredEnum: RequiredEnum | undefined; + requiredIntEnum: RequiredIntEnum | undefined; +} + /** * @public */ diff --git a/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts b/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts index 0b31132bf035..7bd8fa7b2884 100644 --- a/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts +++ b/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts @@ -71,6 +71,10 @@ import { OperationWithRequiredMembersCommandInput, OperationWithRequiredMembersCommandOutput, } from "../commands/OperationWithRequiredMembersCommand"; +import { + OperationWithRequiredMembersWithDefaultsCommandInput, + OperationWithRequiredMembersWithDefaultsCommandOutput, +} from "../commands/OperationWithRequiredMembersWithDefaultsCommand"; import { PutWithContentEncodingCommandInput, PutWithContentEncodingCommandOutput, @@ -101,6 +105,7 @@ import { OperationWithDefaultsOutput, OperationWithNestedStructureInput, OperationWithRequiredMembersOutput, + OperationWithRequiredMembersWithDefaultsOutput, PutWithContentEncodingInput, SimpleScalarPropertiesInput, SimpleScalarPropertiesOutput, @@ -276,6 +281,18 @@ export const se_OperationWithRequiredMembersCommand = async ( return buildHttpRpcRequest(context, headers, "/", undefined, body); }; +/** + * serializeAws_json1_0OperationWithRequiredMembersWithDefaultsCommand + */ +export const se_OperationWithRequiredMembersWithDefaultsCommand = async ( + input: OperationWithRequiredMembersWithDefaultsCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const headers: __HeaderBag = sharedHeaders("OperationWithRequiredMembersWithDefaults"); + const body = "{}"; + return buildHttpRpcRequest(context, headers, "/", undefined, body); +}; + /** * serializeAws_json1_0PutWithContentEncodingCommand */ @@ -530,6 +547,26 @@ export const de_OperationWithRequiredMembersCommand = async ( return response; }; +/** + * deserializeAws_json1_0OperationWithRequiredMembersWithDefaultsCommand + */ +export const de_OperationWithRequiredMembersWithDefaultsCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + if (output.statusCode >= 300) { + return de_CommandError(output, context); + } + const data: any = await parseBody(output.body, context); + let contents: any = {}; + contents = de_OperationWithRequiredMembersWithDefaultsOutput(data, context); + const response: OperationWithRequiredMembersWithDefaultsCommandOutput = { + $metadata: deserializeMetadata(output), + ...contents, + }; + return response; +}; + /** * deserializeAws_json1_0PutWithContentEncodingCommand */ @@ -918,6 +955,31 @@ const de_OperationWithRequiredMembersOutput = ( }) as any; }; +/** + * deserializeAws_json1_0OperationWithRequiredMembersWithDefaultsOutput + */ +const de_OperationWithRequiredMembersWithDefaultsOutput = ( + output: any, + context: __SerdeContext +): OperationWithRequiredMembersWithDefaultsOutput => { + return take(output, { + requiredBlob: context.base64Decoder, + requiredBoolean: __expectBoolean, + requiredByte: __expectByte, + requiredDouble: __limitedParseDouble, + requiredEnum: __expectString, + requiredFloat: __limitedParseFloat32, + requiredIntEnum: __expectInt32, + requiredInteger: __expectInt32, + requiredList: _json, + requiredLong: __expectLong, + requiredMap: _json, + requiredShort: __expectShort, + requiredString: __expectString, + requiredTimestamp: (_: any) => __expectNonNull(__parseEpochTimestamp(__expectNumber(_))), + }) as any; +}; + // de_RequiredStringList omitted. // de_RequiredStringMap omitted. diff --git a/private/aws-protocoltests-json-10/test/functional/awsjson1_0.spec.ts b/private/aws-protocoltests-json-10/test/functional/awsjson1_0.spec.ts index a868bb62a139..055b7cb94983 100644 --- a/private/aws-protocoltests-json-10/test/functional/awsjson1_0.spec.ts +++ b/private/aws-protocoltests-json-10/test/functional/awsjson1_0.spec.ts @@ -15,6 +15,7 @@ import { NoInputAndOutputCommand } from "../../src/commands/NoInputAndOutputComm import { OperationWithDefaultsCommand } from "../../src/commands/OperationWithDefaultsCommand"; import { OperationWithNestedStructureCommand } from "../../src/commands/OperationWithNestedStructureCommand"; import { OperationWithRequiredMembersCommand } from "../../src/commands/OperationWithRequiredMembersCommand"; +import { OperationWithRequiredMembersWithDefaultsCommand } from "../../src/commands/OperationWithRequiredMembersWithDefaultsCommand"; import { PutWithContentEncodingCommand } from "../../src/commands/PutWithContentEncodingCommand"; import { SimpleScalarPropertiesCommand } from "../../src/commands/SimpleScalarPropertiesCommand"; import { JSONRPC10Client } from "../../src/JSONRPC10Client"; @@ -2748,6 +2749,57 @@ it.skip("AwsJson10ClientErrorCorrectsWhenServerFailsToSerializeRequiredValues:Re }); }); +/** + * Client error corrects with default values when server fails to serialize required values. + */ +it.skip("AwsJson10ClientErrorCorrectsWithDefaultValuesWhenServerFailsToSerializeRequiredValues:Response", async () => { + const client = new JSONRPC10Client({ + ...clientParams, + requestHandler: new ResponseDeserializationTestHandler( + true, + 200, + { + "content-type": "application/x-amz-json-1.0", + }, + `{}` + ), + }); + + const params: any = {}; + const command = new OperationWithRequiredMembersWithDefaultsCommand(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 = [ + { + requiredString: "hi", + requiredBoolean: true, + requiredList: [], + requiredTimestamp: new Date(1 * 1000), + requiredBlob: Uint8Array.from("blob", (c) => c.charCodeAt(0)), + requiredByte: 1, + requiredShort: 1, + requiredInteger: 10, + requiredLong: 100, + requiredFloat: 1.0, + requiredDouble: 1.0, + requiredMap: {}, + requiredEnum: "FOO", + requiredIntEnum: 1, + }, + ][0]; + Object.keys(paramsToValidate).forEach((param) => { + expect(r[param]).toBeDefined(); + expect(equivalentContents(paramsToValidate[param], r[param])).toBe(true); + }); +}); + /** * Compression algorithm encoding is appended to the Content-Encoding header. */ diff --git a/private/aws-protocoltests-json/src/JsonProtocol.ts b/private/aws-protocoltests-json/src/JsonProtocol.ts index 03b372f4bdcc..bc2257cef4f9 100644 --- a/private/aws-protocoltests-json/src/JsonProtocol.ts +++ b/private/aws-protocoltests-json/src/JsonProtocol.ts @@ -43,6 +43,11 @@ import { HostWithPathOperationCommandOutput, } from "./commands/HostWithPathOperationCommand"; import { JsonEnumsCommand, JsonEnumsCommandInput, JsonEnumsCommandOutput } from "./commands/JsonEnumsCommand"; +import { + JsonIntEnumsCommand, + JsonIntEnumsCommandInput, + JsonIntEnumsCommandOutput, +} from "./commands/JsonIntEnumsCommand"; import { JsonUnionsCommand, JsonUnionsCommandInput, JsonUnionsCommandOutput } from "./commands/JsonUnionsCommand"; import { KitchenSinkOperationCommand, @@ -91,6 +96,7 @@ const commands = { GreetingWithErrorsCommand, HostWithPathOperationCommand, JsonEnumsCommand, + JsonIntEnumsCommand, JsonUnionsCommand, KitchenSinkOperationCommand, NullOperationCommand, @@ -251,6 +257,18 @@ export interface JsonProtocol { cb: (err: any, data?: JsonEnumsCommandOutput) => void ): void; + /** + * @see {@link JsonIntEnumsCommand} + */ + jsonIntEnums(): Promise; + jsonIntEnums(args: JsonIntEnumsCommandInput, options?: __HttpHandlerOptions): Promise; + jsonIntEnums(args: JsonIntEnumsCommandInput, cb: (err: any, data?: JsonIntEnumsCommandOutput) => void): void; + jsonIntEnums( + args: JsonIntEnumsCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: JsonIntEnumsCommandOutput) => void + ): void; + /** * @see {@link JsonUnionsCommand} */ diff --git a/private/aws-protocoltests-json/src/JsonProtocolClient.ts b/private/aws-protocoltests-json/src/JsonProtocolClient.ts index 970cb32152e4..c8c87c787018 100644 --- a/private/aws-protocoltests-json/src/JsonProtocolClient.ts +++ b/private/aws-protocoltests-json/src/JsonProtocolClient.ts @@ -78,6 +78,7 @@ import { HostWithPathOperationCommandOutput, } from "./commands/HostWithPathOperationCommand"; import { JsonEnumsCommandInput, JsonEnumsCommandOutput } from "./commands/JsonEnumsCommand"; +import { JsonIntEnumsCommandInput, JsonIntEnumsCommandOutput } from "./commands/JsonIntEnumsCommand"; import { JsonUnionsCommandInput, JsonUnionsCommandOutput } from "./commands/JsonUnionsCommand"; import { KitchenSinkOperationCommandInput, @@ -122,6 +123,7 @@ export type ServiceInputTypes = | GreetingWithErrorsCommandInput | HostWithPathOperationCommandInput | JsonEnumsCommandInput + | JsonIntEnumsCommandInput | JsonUnionsCommandInput | KitchenSinkOperationCommandInput | NullOperationCommandInput @@ -144,6 +146,7 @@ export type ServiceOutputTypes = | GreetingWithErrorsCommandOutput | HostWithPathOperationCommandOutput | JsonEnumsCommandOutput + | JsonIntEnumsCommandOutput | JsonUnionsCommandOutput | KitchenSinkOperationCommandOutput | NullOperationCommandOutput diff --git a/private/aws-protocoltests-json/src/commands/JsonIntEnumsCommand.ts b/private/aws-protocoltests-json/src/commands/JsonIntEnumsCommand.ts new file mode 100644 index 000000000000..3b58fde8e4c2 --- /dev/null +++ b/private/aws-protocoltests-json/src/commands/JsonIntEnumsCommand.ts @@ -0,0 +1,108 @@ +// 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 { JsonProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../JsonProtocolClient"; +import { JsonIntEnumsInputOutput } from "../models/models_0"; +import { de_JsonIntEnumsCommand, se_JsonIntEnumsCommand } from "../protocols/Aws_json1_1"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link JsonIntEnumsCommand}. + */ +export interface JsonIntEnumsCommandInput extends JsonIntEnumsInputOutput {} +/** + * @public + * + * The output of {@link JsonIntEnumsCommand}. + */ +export interface JsonIntEnumsCommandOutput extends JsonIntEnumsInputOutput, __MetadataBearer {} + +/** + * This example serializes intEnums as top level properties, in lists, sets, and maps. + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { JsonProtocolClient, JsonIntEnumsCommand } from "@aws-sdk/aws-protocoltests-json"; // ES Modules import + * // const { JsonProtocolClient, JsonIntEnumsCommand } = require("@aws-sdk/aws-protocoltests-json"); // CommonJS import + * const client = new JsonProtocolClient(config); + * const input = { // JsonIntEnumsInputOutput + * intEnum1: 1 || 2 || 3, + * intEnum2: 1 || 2 || 3, + * intEnum3: 1 || 2 || 3, + * intEnumList: [ // IntegerEnumList + * 1 || 2 || 3, + * ], + * intEnumSet: [ // IntegerEnumSet + * 1 || 2 || 3, + * ], + * intEnumMap: { // IntegerEnumMap + * "": 1 || 2 || 3, + * }, + * }; + * const command = new JsonIntEnumsCommand(input); + * const response = await client.send(command); + * // { // JsonIntEnumsInputOutput + * // intEnum1: 1 || 2 || 3, + * // intEnum2: 1 || 2 || 3, + * // intEnum3: 1 || 2 || 3, + * // intEnumList: [ // IntegerEnumList + * // 1 || 2 || 3, + * // ], + * // intEnumSet: [ // IntegerEnumSet + * // 1 || 2 || 3, + * // ], + * // intEnumMap: { // IntegerEnumMap + * // "": 1 || 2 || 3, + * // }, + * // }; + * + * ``` + * + * @param JsonIntEnumsCommandInput - {@link JsonIntEnumsCommandInput} + * @returns {@link JsonIntEnumsCommandOutput} + * @see {@link JsonIntEnumsCommandInput} for command's `input` shape. + * @see {@link JsonIntEnumsCommandOutput} for command's `response` shape. + * @see {@link JsonProtocolClientResolvedConfig | config} for JsonProtocolClient's `config` shape. + * + * @throws {@link JsonProtocolServiceException} + *

Base exception class for all service exceptions from JsonProtocol service.

+ * + * @public + */ +export class JsonIntEnumsCommand extends $Command + .classBuilder< + JsonIntEnumsCommandInput, + JsonIntEnumsCommandOutput, + JsonProtocolClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .m(function (this: any, Command: any, cs: any, config: JsonProtocolClientResolvedConfig, o: any) { + return [getSerdePlugin(config, this.serialize, this.deserialize)]; + }) + .s("JsonProtocol", "JsonIntEnums", {}) + .n("JsonProtocolClient", "JsonIntEnumsCommand") + .f(void 0, void 0) + .ser(se_JsonIntEnumsCommand) + .de(de_JsonIntEnumsCommand) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: JsonIntEnumsInputOutput; + output: JsonIntEnumsInputOutput; + }; + sdk: { + input: JsonIntEnumsCommandInput; + output: JsonIntEnumsCommandOutput; + }; + }; +} diff --git a/private/aws-protocoltests-json/src/commands/index.ts b/private/aws-protocoltests-json/src/commands/index.ts index 481cd11a7e66..746b42f15764 100644 --- a/private/aws-protocoltests-json/src/commands/index.ts +++ b/private/aws-protocoltests-json/src/commands/index.ts @@ -8,6 +8,7 @@ export * from "./FractionalSecondsCommand"; export * from "./GreetingWithErrorsCommand"; export * from "./HostWithPathOperationCommand"; export * from "./JsonEnumsCommand"; +export * from "./JsonIntEnumsCommand"; export * from "./JsonUnionsCommand"; export * from "./KitchenSinkOperationCommand"; export * from "./NullOperationCommand"; diff --git a/private/aws-protocoltests-json/src/models/models_0.ts b/private/aws-protocoltests-json/src/models/models_0.ts index a1b32754523b..b977bd944e51 100644 --- a/private/aws-protocoltests-json/src/models/models_0.ts +++ b/private/aws-protocoltests-json/src/models/models_0.ts @@ -30,6 +30,12 @@ export const FooEnum = { */ export type FooEnum = (typeof FooEnum)[keyof typeof FooEnum]; +export enum IntegerEnum { + A = 1, + B = 2, + C = 3, +} + /** * @public */ @@ -194,6 +200,18 @@ export interface JsonEnumsInputOutput { fooEnumMap?: Record | undefined; } +/** + * @public + */ +export interface JsonIntEnumsInputOutput { + intEnum1?: IntegerEnum | undefined; + intEnum2?: IntegerEnum | undefined; + intEnum3?: IntegerEnum | undefined; + intEnumList?: IntegerEnum[] | undefined; + intEnumSet?: IntegerEnum[] | undefined; + intEnumMap?: Record | undefined; +} + /** * A union with a representative set of types for members. * @public diff --git a/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts b/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts index 8cc15b3c2fe0..bfc1a6357302 100644 --- a/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts +++ b/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts @@ -59,6 +59,7 @@ import { HostWithPathOperationCommandOutput, } from "../commands/HostWithPathOperationCommand"; import { JsonEnumsCommandInput, JsonEnumsCommandOutput } from "../commands/JsonEnumsCommand"; +import { JsonIntEnumsCommandInput, JsonIntEnumsCommandOutput } from "../commands/JsonIntEnumsCommand"; import { JsonUnionsCommandInput, JsonUnionsCommandOutput } from "../commands/JsonUnionsCommand"; import { KitchenSinkOperationCommandInput, @@ -99,8 +100,10 @@ import { FractionalSecondsOutput, GreetingStruct, HostLabelInput, + IntegerEnum, InvalidGreeting, JsonEnumsInputOutput, + JsonIntEnumsInputOutput, KitchenSink, MyUnion, NullOperationInputOutput, @@ -243,6 +246,19 @@ export const se_JsonEnumsCommand = async ( return buildHttpRpcRequest(context, headers, "/", undefined, body); }; +/** + * serializeAws_json1_1JsonIntEnumsCommand + */ +export const se_JsonIntEnumsCommand = async ( + input: JsonIntEnumsCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const headers: __HeaderBag = sharedHeaders("JsonIntEnums"); + let body: any; + body = JSON.stringify(_json(input)); + return buildHttpRpcRequest(context, headers, "/", undefined, body); +}; + /** * serializeAws_json1_1JsonUnionsCommand */ @@ -515,6 +531,26 @@ export const de_JsonEnumsCommand = async ( return response; }; +/** + * deserializeAws_json1_1JsonIntEnumsCommand + */ +export const de_JsonIntEnumsCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + if (output.statusCode >= 300) { + return de_CommandError(output, context); + } + const data: any = await parseBody(output.body, context); + let contents: any = {}; + contents = _json(data); + const response: JsonIntEnumsCommandOutput = { + $metadata: deserializeMetadata(output), + ...contents, + }; + return response; +}; + /** * deserializeAws_json1_1JsonUnionsCommand */ @@ -787,6 +823,8 @@ const se_Document = (input: __DocumentType, context: __SerdeContext): any => { // se_JsonEnumsInputOutput omitted. +// se_JsonIntEnumsInputOutput omitted. + /** * serializeAws_json1_1KitchenSink */ @@ -948,6 +986,12 @@ const se_UnionInputOutput = (input: UnionInputOutput, context: __SerdeContext): // se_GreetingStruct omitted. +// se_IntegerEnumList omitted. + +// se_IntegerEnumMap omitted. + +// se_IntegerEnumSet omitted. + /** * serializeAws_json1_1SparseStringList */ @@ -1046,6 +1090,8 @@ const de_FractionalSecondsOutput = (output: any, context: __SerdeContext): Fract // de_JsonEnumsInputOutput omitted. +// de_JsonIntEnumsInputOutput omitted. + /** * deserializeAws_json1_1KitchenSink */ @@ -1232,6 +1278,12 @@ const de_UnionInputOutput = (output: any, context: __SerdeContext): UnionInputOu // de_GreetingStruct omitted. +// de_IntegerEnumList omitted. + +// de_IntegerEnumMap omitted. + +// de_IntegerEnumSet omitted. + /** * deserializeAws_json1_1SparseStringList */ diff --git a/private/aws-protocoltests-json/test/functional/awsjson1_1.spec.ts b/private/aws-protocoltests-json/test/functional/awsjson1_1.spec.ts index d34e81ffd364..99f430f63304 100644 --- a/private/aws-protocoltests-json/test/functional/awsjson1_1.spec.ts +++ b/private/aws-protocoltests-json/test/functional/awsjson1_1.spec.ts @@ -12,6 +12,7 @@ import { FractionalSecondsCommand } from "../../src/commands/FractionalSecondsCo import { GreetingWithErrorsCommand } from "../../src/commands/GreetingWithErrorsCommand"; import { HostWithPathOperationCommand } from "../../src/commands/HostWithPathOperationCommand"; import { JsonEnumsCommand } from "../../src/commands/JsonEnumsCommand"; +import { JsonIntEnumsCommand } from "../../src/commands/JsonIntEnumsCommand"; import { JsonUnionsCommand } from "../../src/commands/JsonUnionsCommand"; import { KitchenSinkOperationCommand } from "../../src/commands/KitchenSinkOperationCommand"; import { NullOperationCommand } from "../../src/commands/NullOperationCommand"; @@ -1226,6 +1227,131 @@ it("AwsJson11Enums:Response", async () => { }); }); +/** + * Serializes simple scalar properties + */ +it("AwsJson11IntEnums:Request", async () => { + const client = new JsonProtocolClient({ + ...clientParams, + requestHandler: new RequestSerializationTestHandler(), + }); + + const command = new JsonIntEnumsCommand({ + intEnum1: 1, + intEnum2: 2, + intEnum3: 3, + intEnumList: [1, 2], + intEnumSet: [1, 2], + intEnumMap: { + a: 1, + b: 2, + } as any, + } 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("POST"); + expect(r.path).toBe("/"); + + expect(r.headers["content-type"]).toBeDefined(); + expect(r.headers["content-type"]).toBe("application/x-amz-json-1.1"); + expect(r.headers["x-amz-target"]).toBeDefined(); + expect(r.headers["x-amz-target"]).toBe("JsonProtocol.JsonIntEnums"); + + expect(r.body).toBeDefined(); + const utf8Encoder = client.config.utf8Encoder; + const bodyString = `{ + \"intEnum1\": 1, + \"intEnum2\": 2, + \"intEnum3\": 3, + \"intEnumList\": [ + 1, + 2 + ], + \"intEnumSet\": [ + 1, + 2 + ], + \"intEnumMap\": { + \"a\": 1, + \"b\": 2 + } + }`; + const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); + expect(unequalParts).toBeUndefined(); + } +}); + +/** + * Serializes simple scalar properties + */ +it("AwsJson11IntEnums:Response", async () => { + const client = new JsonProtocolClient({ + ...clientParams, + requestHandler: new ResponseDeserializationTestHandler( + true, + 200, + { + "x-amz-target": "JsonProtocol.JsonIntEnums", + "content-type": "application/x-amz-json-1.1", + }, + `{ + "intEnum1": 1, + "intEnum2": 2, + "intEnum3": 3, + "intEnumList": [ + 1, + 2 + ], + "intEnumSet": [ + 1, + 2 + ], + "intEnumMap": { + "a": 1, + "b": 2 + } + }` + ), + }); + + const params: any = {}; + const command = new JsonIntEnumsCommand(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 = [ + { + intEnum1: 1, + intEnum2: 2, + intEnum3: 3, + intEnumList: [1, 2], + intEnumSet: [1, 2], + intEnumMap: { + a: 1, + b: 2, + }, + }, + ][0]; + Object.keys(paramsToValidate).forEach((param) => { + expect(r[param]).toBeDefined(); + expect(equivalentContents(paramsToValidate[param], r[param])).toBe(true); + }); +}); + /** * Serializes a string union value */ diff --git a/private/aws-protocoltests-restjson/src/RestJsonProtocol.ts b/private/aws-protocoltests-restjson/src/RestJsonProtocol.ts index 28cd1014aa82..9ca86dc27491 100644 --- a/private/aws-protocoltests-restjson/src/RestJsonProtocol.ts +++ b/private/aws-protocoltests-restjson/src/RestJsonProtocol.ts @@ -217,6 +217,11 @@ import { MalformedContentTypeWithoutBodyCommandInput, MalformedContentTypeWithoutBodyCommandOutput, } from "./commands/MalformedContentTypeWithoutBodyCommand"; +import { + MalformedContentTypeWithoutBodyEmptyInputCommand, + MalformedContentTypeWithoutBodyEmptyInputCommandInput, + MalformedContentTypeWithoutBodyEmptyInputCommandOutput, +} from "./commands/MalformedContentTypeWithoutBodyEmptyInputCommand"; import { MalformedContentTypeWithPayloadCommand, MalformedContentTypeWithPayloadCommandInput, @@ -412,6 +417,16 @@ import { RecursiveShapesCommandInput, RecursiveShapesCommandOutput, } from "./commands/RecursiveShapesCommand"; +import { + ResponseCodeHttpFallbackCommand, + ResponseCodeHttpFallbackCommandInput, + ResponseCodeHttpFallbackCommandOutput, +} from "./commands/ResponseCodeHttpFallbackCommand"; +import { + ResponseCodeRequiredCommand, + ResponseCodeRequiredCommandInput, + ResponseCodeRequiredCommandOutput, +} from "./commands/ResponseCodeRequiredCommand"; import { SimpleScalarPropertiesCommand, SimpleScalarPropertiesCommandInput, @@ -537,6 +552,7 @@ const commands = { MalformedContentTypeWithBodyCommand, MalformedContentTypeWithGenericStringCommand, MalformedContentTypeWithoutBodyCommand, + MalformedContentTypeWithoutBodyEmptyInputCommand, MalformedContentTypeWithPayloadCommand, MalformedDoubleCommand, MalformedFloatCommand, @@ -576,6 +592,8 @@ const commands = { QueryParamsAsStringListMapCommand, QueryPrecedenceCommand, RecursiveShapesCommand, + ResponseCodeHttpFallbackCommand, + ResponseCodeRequiredCommand, SimpleScalarPropertiesCommand, SparseJsonListsCommand, SparseJsonMapsCommand, @@ -1368,6 +1386,24 @@ export interface RestJsonProtocol { cb: (err: any, data?: MalformedContentTypeWithoutBodyCommandOutput) => void ): void; + /** + * @see {@link MalformedContentTypeWithoutBodyEmptyInputCommand} + */ + malformedContentTypeWithoutBodyEmptyInput(): Promise; + malformedContentTypeWithoutBodyEmptyInput( + args: MalformedContentTypeWithoutBodyEmptyInputCommandInput, + options?: __HttpHandlerOptions + ): Promise; + malformedContentTypeWithoutBodyEmptyInput( + args: MalformedContentTypeWithoutBodyEmptyInputCommandInput, + cb: (err: any, data?: MalformedContentTypeWithoutBodyEmptyInputCommandOutput) => void + ): void; + malformedContentTypeWithoutBodyEmptyInput( + args: MalformedContentTypeWithoutBodyEmptyInputCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: MalformedContentTypeWithoutBodyEmptyInputCommandOutput) => void + ): void; + /** * @see {@link MalformedContentTypeWithPayloadCommand} */ @@ -2010,6 +2046,42 @@ export interface RestJsonProtocol { cb: (err: any, data?: RecursiveShapesCommandOutput) => void ): void; + /** + * @see {@link ResponseCodeHttpFallbackCommand} + */ + responseCodeHttpFallback(): Promise; + responseCodeHttpFallback( + args: ResponseCodeHttpFallbackCommandInput, + options?: __HttpHandlerOptions + ): Promise; + responseCodeHttpFallback( + args: ResponseCodeHttpFallbackCommandInput, + cb: (err: any, data?: ResponseCodeHttpFallbackCommandOutput) => void + ): void; + responseCodeHttpFallback( + args: ResponseCodeHttpFallbackCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: ResponseCodeHttpFallbackCommandOutput) => void + ): void; + + /** + * @see {@link ResponseCodeRequiredCommand} + */ + responseCodeRequired(): Promise; + responseCodeRequired( + args: ResponseCodeRequiredCommandInput, + options?: __HttpHandlerOptions + ): Promise; + responseCodeRequired( + args: ResponseCodeRequiredCommandInput, + cb: (err: any, data?: ResponseCodeRequiredCommandOutput) => void + ): void; + responseCodeRequired( + args: ResponseCodeRequiredCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: ResponseCodeRequiredCommandOutput) => void + ): void; + /** * @see {@link SimpleScalarPropertiesCommand} */ diff --git a/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts b/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts index e2b1671a07dc..135b00aaaa8c 100644 --- a/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts +++ b/private/aws-protocoltests-restjson/src/RestJsonProtocolClient.ts @@ -192,6 +192,10 @@ import { MalformedContentTypeWithoutBodyCommandInput, MalformedContentTypeWithoutBodyCommandOutput, } from "./commands/MalformedContentTypeWithoutBodyCommand"; +import { + MalformedContentTypeWithoutBodyEmptyInputCommandInput, + MalformedContentTypeWithoutBodyEmptyInputCommandOutput, +} from "./commands/MalformedContentTypeWithoutBodyEmptyInputCommand"; import { MalformedContentTypeWithPayloadCommandInput, MalformedContentTypeWithPayloadCommandOutput, @@ -303,6 +307,14 @@ import { } from "./commands/QueryParamsAsStringListMapCommand"; import { QueryPrecedenceCommandInput, QueryPrecedenceCommandOutput } from "./commands/QueryPrecedenceCommand"; import { RecursiveShapesCommandInput, RecursiveShapesCommandOutput } from "./commands/RecursiveShapesCommand"; +import { + ResponseCodeHttpFallbackCommandInput, + ResponseCodeHttpFallbackCommandOutput, +} from "./commands/ResponseCodeHttpFallbackCommand"; +import { + ResponseCodeRequiredCommandInput, + ResponseCodeRequiredCommandOutput, +} from "./commands/ResponseCodeRequiredCommand"; import { SimpleScalarPropertiesCommandInput, SimpleScalarPropertiesCommandOutput, @@ -396,6 +408,7 @@ export type ServiceInputTypes = | MalformedContentTypeWithGenericStringCommandInput | MalformedContentTypeWithPayloadCommandInput | MalformedContentTypeWithoutBodyCommandInput + | MalformedContentTypeWithoutBodyEmptyInputCommandInput | MalformedDoubleCommandInput | MalformedFloatCommandInput | MalformedIntegerCommandInput @@ -434,6 +447,8 @@ export type ServiceInputTypes = | QueryParamsAsStringListMapCommandInput | QueryPrecedenceCommandInput | RecursiveShapesCommandInput + | ResponseCodeHttpFallbackCommandInput + | ResponseCodeRequiredCommandInput | SimpleScalarPropertiesCommandInput | SparseJsonListsCommandInput | SparseJsonMapsCommandInput @@ -502,6 +517,7 @@ export type ServiceOutputTypes = | MalformedContentTypeWithGenericStringCommandOutput | MalformedContentTypeWithPayloadCommandOutput | MalformedContentTypeWithoutBodyCommandOutput + | MalformedContentTypeWithoutBodyEmptyInputCommandOutput | MalformedDoubleCommandOutput | MalformedFloatCommandOutput | MalformedIntegerCommandOutput @@ -540,6 +556,8 @@ export type ServiceOutputTypes = | QueryParamsAsStringListMapCommandOutput | QueryPrecedenceCommandOutput | RecursiveShapesCommandOutput + | ResponseCodeHttpFallbackCommandOutput + | ResponseCodeRequiredCommandOutput | SimpleScalarPropertiesCommandOutput | SparseJsonListsCommandOutput | SparseJsonMapsCommandOutput diff --git a/private/aws-protocoltests-restjson/src/commands/MalformedContentTypeWithoutBodyEmptyInputCommand.ts b/private/aws-protocoltests-restjson/src/commands/MalformedContentTypeWithoutBodyEmptyInputCommand.ts new file mode 100644 index 000000000000..67920f245a1d --- /dev/null +++ b/private/aws-protocoltests-restjson/src/commands/MalformedContentTypeWithoutBodyEmptyInputCommand.ts @@ -0,0 +1,88 @@ +// 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 { MalformedContentTypeWithoutBodyEmptyInputInput } from "../models/models_0"; +import { + de_MalformedContentTypeWithoutBodyEmptyInputCommand, + se_MalformedContentTypeWithoutBodyEmptyInputCommand, +} from "../protocols/Aws_restJson1"; +import { RestJsonProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../RestJsonProtocolClient"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link MalformedContentTypeWithoutBodyEmptyInputCommand}. + */ +export interface MalformedContentTypeWithoutBodyEmptyInputCommandInput + extends MalformedContentTypeWithoutBodyEmptyInputInput {} +/** + * @public + * + * The output of {@link MalformedContentTypeWithoutBodyEmptyInputCommand}. + */ +export interface MalformedContentTypeWithoutBodyEmptyInputCommandOutput extends __MetadataBearer {} + +/** + * @public + * + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { RestJsonProtocolClient, MalformedContentTypeWithoutBodyEmptyInputCommand } from "@aws-sdk/aws-protocoltests-restjson"; // ES Modules import + * // const { RestJsonProtocolClient, MalformedContentTypeWithoutBodyEmptyInputCommand } = require("@aws-sdk/aws-protocoltests-restjson"); // CommonJS import + * const client = new RestJsonProtocolClient(config); + * const input = { // MalformedContentTypeWithoutBodyEmptyInputInput + * header: "STRING_VALUE", + * }; + * const command = new MalformedContentTypeWithoutBodyEmptyInputCommand(input); + * const response = await client.send(command); + * // {}; + * + * ``` + * + * @param MalformedContentTypeWithoutBodyEmptyInputCommandInput - {@link MalformedContentTypeWithoutBodyEmptyInputCommandInput} + * @returns {@link MalformedContentTypeWithoutBodyEmptyInputCommandOutput} + * @see {@link MalformedContentTypeWithoutBodyEmptyInputCommandInput} for command's `input` shape. + * @see {@link MalformedContentTypeWithoutBodyEmptyInputCommandOutput} 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.

+ * + */ +export class MalformedContentTypeWithoutBodyEmptyInputCommand extends $Command + .classBuilder< + MalformedContentTypeWithoutBodyEmptyInputCommandInput, + MalformedContentTypeWithoutBodyEmptyInputCommandOutput, + RestJsonProtocolClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .m(function (this: any, Command: any, cs: any, config: RestJsonProtocolClientResolvedConfig, o: any) { + return [getSerdePlugin(config, this.serialize, this.deserialize)]; + }) + .s("RestJson", "MalformedContentTypeWithoutBodyEmptyInput", {}) + .n("RestJsonProtocolClient", "MalformedContentTypeWithoutBodyEmptyInputCommand") + .f(void 0, void 0) + .ser(se_MalformedContentTypeWithoutBodyEmptyInputCommand) + .de(de_MalformedContentTypeWithoutBodyEmptyInputCommand) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: MalformedContentTypeWithoutBodyEmptyInputInput; + output: {}; + }; + sdk: { + input: MalformedContentTypeWithoutBodyEmptyInputCommandInput; + output: MalformedContentTypeWithoutBodyEmptyInputCommandOutput; + }; + }; +} diff --git a/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersClientCommand.ts b/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersClientCommand.ts index 836586041640..7fdb1a6e1ab8 100644 --- a/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersClientCommand.ts +++ b/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersClientCommand.ts @@ -26,7 +26,7 @@ export interface NullAndEmptyHeadersClientCommandInput extends NullAndEmptyHeade export interface NullAndEmptyHeadersClientCommandOutput extends NullAndEmptyHeadersIO, __MetadataBearer {} /** - * Null and empty headers are not sent over the wire. + * Null headers are not sent over the wire, empty headers are serialized to "" * @example * Use a bare-bones client and the command you need to make an API call. * ```javascript diff --git a/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersServerCommand.ts b/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersServerCommand.ts index d68155cf079c..f21bbc1e6972 100644 --- a/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersServerCommand.ts +++ b/private/aws-protocoltests-restjson/src/commands/NullAndEmptyHeadersServerCommand.ts @@ -26,7 +26,7 @@ export interface NullAndEmptyHeadersServerCommandInput extends NullAndEmptyHeade export interface NullAndEmptyHeadersServerCommandOutput extends NullAndEmptyHeadersIO, __MetadataBearer {} /** - * Null and empty headers are not sent over the wire. + * Null headers are not sent over the wire, empty headers are serialized to "" * @example * Use a bare-bones client and the command you need to make an API call. * ```javascript diff --git a/private/aws-protocoltests-restjson/src/commands/ResponseCodeHttpFallbackCommand.ts b/private/aws-protocoltests-restjson/src/commands/ResponseCodeHttpFallbackCommand.ts new file mode 100644 index 000000000000..925080305b7a --- /dev/null +++ b/private/aws-protocoltests-restjson/src/commands/ResponseCodeHttpFallbackCommand.ts @@ -0,0 +1,82 @@ +// 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 { ResponseCodeHttpFallbackInputOutput } from "../models/models_0"; +import { de_ResponseCodeHttpFallbackCommand, se_ResponseCodeHttpFallbackCommand } from "../protocols/Aws_restJson1"; +import { RestJsonProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../RestJsonProtocolClient"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link ResponseCodeHttpFallbackCommand}. + */ +export interface ResponseCodeHttpFallbackCommandInput extends ResponseCodeHttpFallbackInputOutput {} +/** + * @public + * + * The output of {@link ResponseCodeHttpFallbackCommand}. + */ +export interface ResponseCodeHttpFallbackCommandOutput extends ResponseCodeHttpFallbackInputOutput, __MetadataBearer {} + +/** + * @public + * + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { RestJsonProtocolClient, ResponseCodeHttpFallbackCommand } from "@aws-sdk/aws-protocoltests-restjson"; // ES Modules import + * // const { RestJsonProtocolClient, ResponseCodeHttpFallbackCommand } = require("@aws-sdk/aws-protocoltests-restjson"); // CommonJS import + * const client = new RestJsonProtocolClient(config); + * const input = {}; + * const command = new ResponseCodeHttpFallbackCommand(input); + * const response = await client.send(command); + * // {}; + * + * ``` + * + * @param ResponseCodeHttpFallbackCommandInput - {@link ResponseCodeHttpFallbackCommandInput} + * @returns {@link ResponseCodeHttpFallbackCommandOutput} + * @see {@link ResponseCodeHttpFallbackCommandInput} for command's `input` shape. + * @see {@link ResponseCodeHttpFallbackCommandOutput} 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.

+ * + */ +export class ResponseCodeHttpFallbackCommand extends $Command + .classBuilder< + ResponseCodeHttpFallbackCommandInput, + ResponseCodeHttpFallbackCommandOutput, + RestJsonProtocolClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .m(function (this: any, Command: any, cs: any, config: RestJsonProtocolClientResolvedConfig, o: any) { + return [getSerdePlugin(config, this.serialize, this.deserialize)]; + }) + .s("RestJson", "ResponseCodeHttpFallback", {}) + .n("RestJsonProtocolClient", "ResponseCodeHttpFallbackCommand") + .f(void 0, void 0) + .ser(se_ResponseCodeHttpFallbackCommand) + .de(de_ResponseCodeHttpFallbackCommand) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: {}; + output: {}; + }; + sdk: { + input: ResponseCodeHttpFallbackCommandInput; + output: ResponseCodeHttpFallbackCommandOutput; + }; + }; +} diff --git a/private/aws-protocoltests-restjson/src/commands/ResponseCodeRequiredCommand.ts b/private/aws-protocoltests-restjson/src/commands/ResponseCodeRequiredCommand.ts new file mode 100644 index 000000000000..160d2770bfa9 --- /dev/null +++ b/private/aws-protocoltests-restjson/src/commands/ResponseCodeRequiredCommand.ts @@ -0,0 +1,84 @@ +// 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 { ResponseCodeRequiredOutput } from "../models/models_0"; +import { de_ResponseCodeRequiredCommand, se_ResponseCodeRequiredCommand } from "../protocols/Aws_restJson1"; +import { RestJsonProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../RestJsonProtocolClient"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link ResponseCodeRequiredCommand}. + */ +export interface ResponseCodeRequiredCommandInput {} +/** + * @public + * + * The output of {@link ResponseCodeRequiredCommand}. + */ +export interface ResponseCodeRequiredCommandOutput extends ResponseCodeRequiredOutput, __MetadataBearer {} + +/** + * @public + * + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { RestJsonProtocolClient, ResponseCodeRequiredCommand } from "@aws-sdk/aws-protocoltests-restjson"; // ES Modules import + * // const { RestJsonProtocolClient, ResponseCodeRequiredCommand } = require("@aws-sdk/aws-protocoltests-restjson"); // CommonJS import + * const client = new RestJsonProtocolClient(config); + * const input = {}; + * const command = new ResponseCodeRequiredCommand(input); + * const response = await client.send(command); + * // { // ResponseCodeRequiredOutput + * // responseCode: Number("int"), // required + * // }; + * + * ``` + * + * @param ResponseCodeRequiredCommandInput - {@link ResponseCodeRequiredCommandInput} + * @returns {@link ResponseCodeRequiredCommandOutput} + * @see {@link ResponseCodeRequiredCommandInput} for command's `input` shape. + * @see {@link ResponseCodeRequiredCommandOutput} 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.

+ * + */ +export class ResponseCodeRequiredCommand extends $Command + .classBuilder< + ResponseCodeRequiredCommandInput, + ResponseCodeRequiredCommandOutput, + RestJsonProtocolClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .m(function (this: any, Command: any, cs: any, config: RestJsonProtocolClientResolvedConfig, o: any) { + return [getSerdePlugin(config, this.serialize, this.deserialize)]; + }) + .s("RestJson", "ResponseCodeRequired", {}) + .n("RestJsonProtocolClient", "ResponseCodeRequiredCommand") + .f(void 0, void 0) + .ser(se_ResponseCodeRequiredCommand) + .de(de_ResponseCodeRequiredCommand) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: {}; + output: ResponseCodeRequiredOutput; + }; + sdk: { + input: ResponseCodeRequiredCommandInput; + output: ResponseCodeRequiredCommandOutput; + }; + }; +} diff --git a/private/aws-protocoltests-restjson/src/commands/index.ts b/private/aws-protocoltests-restjson/src/commands/index.ts index f433279c386a..6623b538bd7e 100644 --- a/private/aws-protocoltests-restjson/src/commands/index.ts +++ b/private/aws-protocoltests-restjson/src/commands/index.ts @@ -47,6 +47,7 @@ export * from "./MalformedContentTypeWithBodyCommand"; export * from "./MalformedContentTypeWithGenericStringCommand"; export * from "./MalformedContentTypeWithPayloadCommand"; export * from "./MalformedContentTypeWithoutBodyCommand"; +export * from "./MalformedContentTypeWithoutBodyEmptyInputCommand"; export * from "./MalformedDoubleCommand"; export * from "./MalformedFloatCommand"; export * from "./MalformedIntegerCommand"; @@ -85,6 +86,8 @@ export * from "./QueryIdempotencyTokenAutoFillCommand"; export * from "./QueryParamsAsStringListMapCommand"; export * from "./QueryPrecedenceCommand"; export * from "./RecursiveShapesCommand"; +export * from "./ResponseCodeHttpFallbackCommand"; +export * from "./ResponseCodeRequiredCommand"; export * from "./SimpleScalarPropertiesCommand"; export * from "./SparseJsonListsCommand"; export * from "./SparseJsonMapsCommand"; diff --git a/private/aws-protocoltests-restjson/src/models/models_0.ts b/private/aws-protocoltests-restjson/src/models/models_0.ts index 96eba9aadf1e..b6c85cff7236 100644 --- a/private/aws-protocoltests-restjson/src/models/models_0.ts +++ b/private/aws-protocoltests-restjson/src/models/models_0.ts @@ -888,6 +888,13 @@ export interface MalformedContentTypeWithGenericStringInput { payload?: string | undefined; } +/** + * @public + */ +export interface MalformedContentTypeWithoutBodyEmptyInputInput { + header?: string | undefined; +} + /** * @public */ @@ -1393,6 +1400,18 @@ export interface QueryPrecedenceInput { baz?: Record | undefined; } +/** + * @public + */ +export interface ResponseCodeHttpFallbackInputOutput {} + +/** + * @public + */ +export interface ResponseCodeRequiredOutput { + responseCode: number | 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 af7d61e075f4..86463ad43a99 100644 --- a/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts +++ b/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts @@ -188,6 +188,10 @@ import { MalformedContentTypeWithoutBodyCommandInput, MalformedContentTypeWithoutBodyCommandOutput, } from "../commands/MalformedContentTypeWithoutBodyCommand"; +import { + MalformedContentTypeWithoutBodyEmptyInputCommandInput, + MalformedContentTypeWithoutBodyEmptyInputCommandOutput, +} from "../commands/MalformedContentTypeWithoutBodyEmptyInputCommand"; import { MalformedContentTypeWithPayloadCommandInput, MalformedContentTypeWithPayloadCommandOutput, @@ -299,6 +303,14 @@ import { } from "../commands/QueryParamsAsStringListMapCommand"; import { QueryPrecedenceCommandInput, QueryPrecedenceCommandOutput } from "../commands/QueryPrecedenceCommand"; import { RecursiveShapesCommandInput, RecursiveShapesCommandOutput } from "../commands/RecursiveShapesCommand"; +import { + ResponseCodeHttpFallbackCommandInput, + ResponseCodeHttpFallbackCommandOutput, +} from "../commands/ResponseCodeHttpFallbackCommand"; +import { + ResponseCodeRequiredCommandInput, + ResponseCodeRequiredCommandOutput, +} from "../commands/ResponseCodeRequiredCommand"; import { SimpleScalarPropertiesCommandInput, SimpleScalarPropertiesCommandOutput, @@ -1428,6 +1440,23 @@ export const se_MalformedContentTypeWithoutBodyCommand = async ( return b.build(); }; +/** + * serializeAws_restJson1MalformedContentTypeWithoutBodyEmptyInputCommand + */ +export const se_MalformedContentTypeWithoutBodyEmptyInputCommand = async ( + input: MalformedContentTypeWithoutBodyEmptyInputCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const b = rb(input, context); + const headers: any = map({}, isSerializableHeaderValue, { + [_he]: input[_he]!, + }); + b.bp("/MalformedContentTypeWithoutBodyEmptyInput"); + let body: any; + b.m("POST").h(headers).b(body); + return b.build(); +}; + /** * serializeAws_restJson1MalformedContentTypeWithPayloadCommand */ @@ -2271,6 +2300,36 @@ export const se_RecursiveShapesCommand = async ( return b.build(); }; +/** + * serializeAws_restJson1ResponseCodeHttpFallbackCommand + */ +export const se_ResponseCodeHttpFallbackCommand = async ( + input: ResponseCodeHttpFallbackCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const b = rb(input, context); + const headers: any = {}; + b.bp("/responseCodeHttpFallback"); + let body: any; + b.m("GET").h(headers).b(body); + return b.build(); +}; + +/** + * serializeAws_restJson1ResponseCodeRequiredCommand + */ +export const se_ResponseCodeRequiredCommand = async ( + input: ResponseCodeRequiredCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const b = rb(input, context); + const headers: any = {}; + b.bp("/responseCodeRequired"); + let body: any; + b.m("GET").h(headers).b(body); + return b.build(); +}; + /** * serializeAws_restJson1SimpleScalarPropertiesCommand */ @@ -3547,6 +3606,23 @@ export const de_MalformedContentTypeWithoutBodyCommand = async ( return contents; }; +/** + * deserializeAws_restJson1MalformedContentTypeWithoutBodyEmptyInputCommand + */ +export const de_MalformedContentTypeWithoutBodyEmptyInputCommand = 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), + }); + await collectBody(output.body, context); + return contents; +}; + /** * deserializeAws_restJson1MalformedContentTypeWithPayloadCommand */ @@ -4275,6 +4351,43 @@ export const de_RecursiveShapesCommand = async ( return contents; }; +/** + * deserializeAws_restJson1ResponseCodeHttpFallbackCommand + */ +export const de_ResponseCodeHttpFallbackCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + if (output.statusCode !== 201 && output.statusCode >= 300) { + return de_CommandError(output, context); + } + const contents: any = map({ + $metadata: deserializeMetadata(output), + }); + await collectBody(output.body, context); + return contents; +}; + +/** + * deserializeAws_restJson1ResponseCodeRequiredCommand + */ +export const de_ResponseCodeRequiredCommand = 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), + }); + map(contents, { + responseCode: [, output.statusCode], + }); + await collectBody(output.body, context); + return contents; +}; + /** * deserializeAws_restJson1SimpleScalarPropertiesCommand */ @@ -5371,6 +5484,7 @@ const _hSS = "headerStringSet"; const _hSe = "headerShort"; const _hTB = "headerTrueBool"; const _hTL = "headerTimestampList"; +const _he = "header"; const _i = "integerinheader"; const _iIH = "integerInHeader"; const _iIQ = "integerInQuery"; diff --git a/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts b/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts index 71ec51800e3d..5dcade9cce99 100644 --- a/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts +++ b/private/aws-protocoltests-restjson/test/functional/restjson1.spec.ts @@ -2804,8 +2804,8 @@ it("RestJsonHttpPrefixHeadersArePresent:Request", async () => { const command = new HttpPrefixHeadersCommand({ foo: "Foo", fooMap: { - Abc: "Abc value", - Def: "Def value", + abc: "Abc value", + def: "Def value", } as any, } as any); try { @@ -2876,7 +2876,7 @@ it("RestJsonHttpPrefixEmptyHeaders:Request", async () => { const command = new HttpPrefixHeadersCommand({ fooMap: { - Abc: "", + abc: "", } as any, } as any); try { diff --git a/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersClientCommand.ts b/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersClientCommand.ts index 042ab1b974bd..bdf951ef5073 100644 --- a/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersClientCommand.ts +++ b/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersClientCommand.ts @@ -26,7 +26,7 @@ export interface NullAndEmptyHeadersClientCommandInput extends NullAndEmptyHeade export interface NullAndEmptyHeadersClientCommandOutput extends NullAndEmptyHeadersIO, __MetadataBearer {} /** - * Null and empty headers are not sent over the wire. + * Null headers are not sent over the wire, empty headers are serialized to "" * @example * Use a bare-bones client and the command you need to make an API call. * ```javascript diff --git a/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersServerCommand.ts b/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersServerCommand.ts index 786cbd9bab53..f18fb76dd180 100644 --- a/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersServerCommand.ts +++ b/private/aws-protocoltests-restxml/src/commands/NullAndEmptyHeadersServerCommand.ts @@ -26,7 +26,7 @@ export interface NullAndEmptyHeadersServerCommandInput extends NullAndEmptyHeade export interface NullAndEmptyHeadersServerCommandOutput extends NullAndEmptyHeadersIO, __MetadataBearer {} /** - * Null and empty headers are not sent over the wire. + * Null headers are not sent over the wire, empty headers are serialized to "" * @example * Use a bare-bones client and the command you need to make an API call. * ```javascript diff --git a/private/aws-protocoltests-restxml/test/functional/restxml.spec.ts b/private/aws-protocoltests-restxml/test/functional/restxml.spec.ts index 356b2d6f8e62..36563b3c4dd4 100644 --- a/private/aws-protocoltests-restxml/test/functional/restxml.spec.ts +++ b/private/aws-protocoltests-restxml/test/functional/restxml.spec.ts @@ -2276,8 +2276,8 @@ it("HttpPrefixHeadersArePresent:Request", async () => { const command = new HttpPrefixHeadersCommand({ foo: "Foo", fooMap: { - Abc: "Abc value", - Def: "Def value", + abc: "Abc value", + def: "Def value", } as any, } as any); try { @@ -2348,7 +2348,7 @@ it("HttpPrefixEmptyHeaders:Request", async () => { const command = new HttpPrefixHeadersCommand({ fooMap: { - Abc: "", + abc: "", } as any, } as any); try { @@ -3708,7 +3708,7 @@ it.skip("NestedXmlMapWithXmlNameSerializes:Request", async () => { expect(r.body).toBeDefined(); const utf8Encoder = client.config.utf8Encoder; - const bodyString = ` + const bodyString = ` foo @@ -3737,7 +3737,7 @@ it.skip("NestedXmlMapWithXmlNameSerializes:Request", async () => { - + `; const unequalParts: any = compareEquivalentXmlBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); @@ -3756,7 +3756,7 @@ it("NestedXmlMapWithXmlNameDeserializes:Response", async () => { { "content-type": "application/xml", }, - ` + ` foo @@ -3785,7 +3785,7 @@ it("NestedXmlMapWithXmlNameDeserializes:Response", async () => { - + ` ), }); diff --git a/private/aws-protocoltests-smithy-rpcv2-cbor/test/functional/rpcv2cbor.spec.ts b/private/aws-protocoltests-smithy-rpcv2-cbor/test/functional/rpcv2cbor.spec.ts index cb2fb1599e3b..7e02faefe4dc 100644 --- a/private/aws-protocoltests-smithy-rpcv2-cbor/test/functional/rpcv2cbor.spec.ts +++ b/private/aws-protocoltests-smithy-rpcv2-cbor/test/functional/rpcv2cbor.spec.ts @@ -830,7 +830,7 @@ it.skip("RpcV2CborClientPopulatesDefaultValuesInInput:Request", async () => { expect(r.headers["smithy-protocol"]).toBe("rpc-v2-cbor"); expect(r.body).toBeDefined(); - const bodyString = `v2hkZWZhdWx0c79tZGVmYXVsdFN0cmluZ2JoaW5kZWZhdWx0Qm9vbGVhbvVrZGVmYXVsdExpc3Sf/3BkZWZhdWx0VGltZXN0YW1wwQBrZGVmYXVsdEJsb2JjYWJja2RlZmF1bHRCeXRlAWxkZWZhdWx0U2hvcnQBbmRlZmF1bHRJbnRlZ2VyCmtkZWZhdWx0TG9uZxhkbGRlZmF1bHRGbG9hdPo/gAAAbWRlZmF1bHREb3VibGX6P4AAAGpkZWZhdWx0TWFwv/9rZGVmYXVsdEVudW1jRk9PbmRlZmF1bHRJbnRFbnVtAWtlbXB0eVN0cmluZ2BsZmFsc2VCb29sZWFu9GllbXB0eUJsb2JgaHplcm9CeXRlAGl6ZXJvU2hvcnQAa3plcm9JbnRlZ2VyAGh6ZXJvTG9uZwBpemVyb0Zsb2F0+gAAAABqemVyb0RvdWJsZfoAAAAA//8=`; + const bodyString = `v2hkZWZhdWx0c79tZGVmYXVsdFN0cmluZ2JoaW5kZWZhdWx0Qm9vbGVhbvVrZGVmYXVsdExpc3Sf/3BkZWZhdWx0VGltZXN0YW1wwQBrZGVmYXVsdEJsb2JDYWJja2RlZmF1bHRCeXRlAWxkZWZhdWx0U2hvcnQBbmRlZmF1bHRJbnRlZ2VyCmtkZWZhdWx0TG9uZxhkbGRlZmF1bHRGbG9hdPo/gAAAbWRlZmF1bHREb3VibGX6P4AAAGpkZWZhdWx0TWFwv/9rZGVmYXVsdEVudW1jRk9PbmRlZmF1bHRJbnRFbnVtAWtlbXB0eVN0cmluZ2BsZmFsc2VCb29sZWFu9GllbXB0eUJsb2JAaHplcm9CeXRlAGl6ZXJvU2hvcnQAa3plcm9JbnRlZ2VyAGh6ZXJvTG9uZwBpemVyb0Zsb2F0+gAAAABqemVyb0RvdWJsZfoAAAAA//8`; const unequalParts: any = compareEquivalentCborBodies(bodyString, r.body); expect(unequalParts).toBeUndefined(); } diff --git a/private/aws-restjson-server/src/models/models_0.ts b/private/aws-restjson-server/src/models/models_0.ts index dcd9cb66bb13..9742474e9fdc 100644 --- a/private/aws-restjson-server/src/models/models_0.ts +++ b/private/aws-restjson-server/src/models/models_0.ts @@ -3355,6 +3355,38 @@ export namespace MalformedContentTypeWithGenericStringInput { }; } +/** + * @public + */ +export interface MalformedContentTypeWithoutBodyEmptyInputInput { + header?: string | undefined; +} + +export namespace MalformedContentTypeWithoutBodyEmptyInputInput { + const memberValidators: { + header?: __MultiConstraintValidator; + } = {}; + /** + * @internal + */ + export const validate = (obj: MalformedContentTypeWithoutBodyEmptyInputInput, path = ""): __ValidationFailure[] => { + function getMemberValidator( + member: T + ): NonNullable<(typeof memberValidators)[T]> { + if (memberValidators[member] === undefined) { + switch (member) { + case "header": { + memberValidators["header"] = new __NoOpValidator(); + break; + } + } + } + return memberValidators[member]!; + } + return [...getMemberValidator("header").validate(obj.header, `${path}/header`)]; + }; +} + /** * @public */ @@ -5546,6 +5578,62 @@ export namespace QueryPrecedenceInput { }; } +/** + * @public + */ +export interface ResponseCodeHttpFallbackInputOutput {} + +export namespace ResponseCodeHttpFallbackInputOutput { + const memberValidators: {} = {}; + /** + * @internal + */ + export const validate = (obj: ResponseCodeHttpFallbackInputOutput, path = ""): __ValidationFailure[] => { + function getMemberValidator( + member: T + ): NonNullable<(typeof memberValidators)[T]> { + if (memberValidators[member] === undefined) { + switch (member) { + } + } + return memberValidators[member]!; + } + return []; + }; +} + +/** + * @public + */ +export interface ResponseCodeRequiredOutput { + responseCode: number | undefined; +} + +export namespace ResponseCodeRequiredOutput { + const memberValidators: { + responseCode?: __MultiConstraintValidator; + } = {}; + /** + * @internal + */ + export const validate = (obj: ResponseCodeRequiredOutput, path = ""): __ValidationFailure[] => { + function getMemberValidator( + member: T + ): NonNullable<(typeof memberValidators)[T]> { + if (memberValidators[member] === undefined) { + switch (member) { + case "responseCode": { + memberValidators["responseCode"] = new __CompositeValidator([new __RequiredValidator()]); + break; + } + } + } + return memberValidators[member]!; + } + return [...getMemberValidator("responseCode").validate(obj.responseCode, `${path}/responseCode`)]; + }; +} + /** * @public */ diff --git a/private/aws-restjson-server/src/protocols/Aws_restJson1.ts b/private/aws-restjson-server/src/protocols/Aws_restJson1.ts index 2d1dbb58d2ea..ce079df7d7d9 100644 --- a/private/aws-restjson-server/src/protocols/Aws_restJson1.ts +++ b/private/aws-restjson-server/src/protocols/Aws_restJson1.ts @@ -213,6 +213,10 @@ import { MalformedContentTypeWithoutBodyServerInput, MalformedContentTypeWithoutBodyServerOutput, } from "../server/operations/MalformedContentTypeWithoutBody"; +import { + MalformedContentTypeWithoutBodyEmptyInputServerInput, + MalformedContentTypeWithoutBodyEmptyInputServerOutput, +} from "../server/operations/MalformedContentTypeWithoutBodyEmptyInput"; import { MalformedContentTypeWithPayloadServerInput, MalformedContentTypeWithPayloadServerOutput, @@ -324,6 +328,14 @@ import { } from "../server/operations/QueryParamsAsStringListMap"; import { QueryPrecedenceServerInput, QueryPrecedenceServerOutput } from "../server/operations/QueryPrecedence"; import { RecursiveShapesServerInput, RecursiveShapesServerOutput } from "../server/operations/RecursiveShapes"; +import { + ResponseCodeHttpFallbackServerInput, + ResponseCodeHttpFallbackServerOutput, +} from "../server/operations/ResponseCodeHttpFallback"; +import { + ResponseCodeRequiredServerInput, + ResponseCodeRequiredServerOutput, +} from "../server/operations/ResponseCodeRequired"; import { SimpleScalarPropertiesServerInput, SimpleScalarPropertiesServerOutput, @@ -2032,6 +2044,33 @@ export const deserializeMalformedContentTypeWithoutBodyRequest = async ( return contents; }; +export const deserializeMalformedContentTypeWithoutBodyEmptyInputRequest = async ( + output: __HttpRequest, + context: __SerdeContext +): Promise => { + const contentTypeHeaderKey: string | undefined = Object.keys(output.headers).find( + (key) => key.toLowerCase() === "content-type" + ); + if (contentTypeHeaderKey != null) { + const contentType = output.headers[contentTypeHeaderKey]; + if (contentType !== undefined && contentType !== "application/json") { + throw new __UnsupportedMediaTypeException(); + } + } + const acceptHeaderKey: string | undefined = Object.keys(output.headers).find((key) => key.toLowerCase() === "accept"); + if (acceptHeaderKey != null) { + const accept = output.headers[acceptHeaderKey]; + if (!__acceptMatches(accept, "application/json")) { + throw new __NotAcceptableException(); + } + } + const contents: any = map({ + [_h]: [, output.headers[_h]], + }); + await collectBody(output.body, context); + return contents; +}; + export const deserializeMalformedContentTypeWithPayloadRequest = async ( output: __HttpRequest, context: __SerdeContext @@ -3438,6 +3477,56 @@ export const deserializeRecursiveShapesRequest = async ( return contents; }; +export const deserializeResponseCodeHttpFallbackRequest = async ( + output: __HttpRequest, + context: __SerdeContext +): Promise => { + const contentTypeHeaderKey: string | undefined = Object.keys(output.headers).find( + (key) => key.toLowerCase() === "content-type" + ); + if (contentTypeHeaderKey != null) { + const contentType = output.headers[contentTypeHeaderKey]; + if (contentType !== undefined && contentType !== "application/json") { + throw new __UnsupportedMediaTypeException(); + } + } + const acceptHeaderKey: string | undefined = Object.keys(output.headers).find((key) => key.toLowerCase() === "accept"); + if (acceptHeaderKey != null) { + const accept = output.headers[acceptHeaderKey]; + if (!__acceptMatches(accept, "application/json")) { + throw new __NotAcceptableException(); + } + } + const contents: any = map({}); + await collectBody(output.body, context); + return contents; +}; + +export const deserializeResponseCodeRequiredRequest = async ( + output: __HttpRequest, + context: __SerdeContext +): Promise => { + const contentTypeHeaderKey: string | undefined = Object.keys(output.headers).find( + (key) => key.toLowerCase() === "content-type" + ); + if (contentTypeHeaderKey != null) { + const contentType = output.headers[contentTypeHeaderKey]; + if (contentType !== undefined) { + throw new __UnsupportedMediaTypeException(); + } + } + const acceptHeaderKey: string | undefined = Object.keys(output.headers).find((key) => key.toLowerCase() === "accept"); + if (acceptHeaderKey != null) { + const accept = output.headers[acceptHeaderKey]; + if (!__acceptMatches(accept, "application/json")) { + throw new __NotAcceptableException(); + } + } + const contents: any = map({}); + await collectBody(output.body, context); + return contents; +}; + export const deserializeSimpleScalarPropertiesRequest = async ( output: __HttpRequest, context: __SerdeContext @@ -5701,6 +5790,40 @@ export const serializeMalformedContentTypeWithoutBodyResponse = async ( }); }; +export const serializeMalformedContentTypeWithoutBodyEmptyInputResponse = async ( + input: MalformedContentTypeWithoutBodyEmptyInputServerOutput, + ctx: ServerSerdeContext +): Promise<__HttpResponse> => { + const context: __SerdeContext = { + ...ctx, + endpoint: () => + Promise.resolve({ + protocol: "", + hostname: "", + path: "", + }), + }; + const statusCode = 200; + let headers: any = map({}, isSerializableHeaderValue, {}); + let body: any; + if ( + body && + Object.keys(headers) + .map((str) => str.toLowerCase()) + .indexOf("content-length") === -1 + ) { + const length = calculateBodyLength(body); + if (length !== undefined) { + headers = { ...headers, "content-length": String(length) }; + } + } + return new __HttpResponse({ + headers, + body, + statusCode, + }); +}; + export const serializeMalformedContentTypeWithPayloadResponse = async ( input: MalformedContentTypeWithPayloadServerOutput, ctx: ServerSerdeContext @@ -7113,6 +7236,83 @@ export const serializeRecursiveShapesResponse = async ( }); }; +export const serializeResponseCodeHttpFallbackResponse = async ( + input: ResponseCodeHttpFallbackServerOutput, + ctx: ServerSerdeContext +): Promise<__HttpResponse> => { + const context: __SerdeContext = { + ...ctx, + endpoint: () => + Promise.resolve({ + protocol: "", + hostname: "", + path: "", + }), + }; + const statusCode = 201; + let headers: any = map({}, isSerializableHeaderValue, { + "content-type": "application/json", + }); + let body: any; + body = "{}"; + if ( + body && + Object.keys(headers) + .map((str) => str.toLowerCase()) + .indexOf("content-length") === -1 + ) { + const length = calculateBodyLength(body); + if (length !== undefined) { + headers = { ...headers, "content-length": String(length) }; + } + } + return new __HttpResponse({ + headers, + body, + statusCode, + }); +}; + +export const serializeResponseCodeRequiredResponse = async ( + input: ResponseCodeRequiredServerOutput, + ctx: ServerSerdeContext +): Promise<__HttpResponse> => { + const context: __SerdeContext = { + ...ctx, + endpoint: () => + Promise.resolve({ + protocol: "", + hostname: "", + path: "", + }), + }; + let statusCode = 200; + if (input.responseCode !== undefined) { + statusCode = input.responseCode; + } + let headers: any = map({}, isSerializableHeaderValue, { + "content-type": "application/json", + }); + let body: any; + body = "{}"; + if ( + body && + Object.keys(headers) + .map((str) => str.toLowerCase()) + .indexOf("content-length") === -1 + ) { + const length = calculateBodyLength(body); + if (length !== undefined) { + headers = { ...headers, "content-length": String(length) }; + } + } + return new __HttpResponse({ + headers, + body, + statusCode, + }); +}; + export const serializeSimpleScalarPropertiesResponse = async ( input: SimpleScalarPropertiesServerOutput, ctx: ServerSerdeContext @@ -9169,6 +9369,7 @@ const _f = "foo"; const _fIH = "floatInHeader"; const _fl = "floatinheader"; const _g = "greeting"; +const _h = "header"; const _hB = "headerByte"; const _hBL = "headerBooleanList"; const _hD = "headerDouble"; diff --git a/private/aws-restjson-server/src/server/RestJsonService.ts b/private/aws-restjson-server/src/server/RestJsonService.ts index 508bb86027b1..f4955d040b69 100644 --- a/private/aws-restjson-server/src/server/RestJsonService.ts +++ b/private/aws-restjson-server/src/server/RestJsonService.ts @@ -210,6 +210,11 @@ import { MalformedContentTypeWithoutBodySerializer, MalformedContentTypeWithoutBodyServerInput, } from "./operations/MalformedContentTypeWithoutBody"; +import { + MalformedContentTypeWithoutBodyEmptyInput, + MalformedContentTypeWithoutBodyEmptyInputSerializer, + MalformedContentTypeWithoutBodyEmptyInputServerInput, +} from "./operations/MalformedContentTypeWithoutBodyEmptyInput"; import { MalformedContentTypeWithPayload, MalformedContentTypeWithPayloadSerializer, @@ -361,6 +366,16 @@ import { } from "./operations/QueryParamsAsStringListMap"; import { QueryPrecedence, QueryPrecedenceSerializer, QueryPrecedenceServerInput } from "./operations/QueryPrecedence"; import { RecursiveShapes, RecursiveShapesSerializer, RecursiveShapesServerInput } from "./operations/RecursiveShapes"; +import { + ResponseCodeHttpFallback, + ResponseCodeHttpFallbackSerializer, + ResponseCodeHttpFallbackServerInput, +} from "./operations/ResponseCodeHttpFallback"; +import { + ResponseCodeRequired, + ResponseCodeRequiredSerializer, + ResponseCodeRequiredServerInput, +} from "./operations/ResponseCodeRequired"; import { SimpleScalarProperties, SimpleScalarPropertiesSerializer, @@ -469,6 +484,7 @@ export type RestJsonServiceOperations = | "MalformedContentTypeWithBody" | "MalformedContentTypeWithGenericString" | "MalformedContentTypeWithoutBody" + | "MalformedContentTypeWithoutBodyEmptyInput" | "MalformedContentTypeWithPayload" | "MalformedDouble" | "MalformedFloat" @@ -508,6 +524,8 @@ export type RestJsonServiceOperations = | "QueryParamsAsStringListMap" | "QueryPrecedence" | "RecursiveShapes" + | "ResponseCodeHttpFallback" + | "ResponseCodeRequired" | "SimpleScalarProperties" | "SparseJsonLists" | "SparseJsonMaps" @@ -571,6 +589,7 @@ export interface RestJsonService { MalformedContentTypeWithBody: MalformedContentTypeWithBody; MalformedContentTypeWithGenericString: MalformedContentTypeWithGenericString; MalformedContentTypeWithoutBody: MalformedContentTypeWithoutBody; + MalformedContentTypeWithoutBodyEmptyInput: MalformedContentTypeWithoutBodyEmptyInput; MalformedContentTypeWithPayload: MalformedContentTypeWithPayload; MalformedDouble: MalformedDouble; MalformedFloat: MalformedFloat; @@ -610,6 +629,8 @@ export interface RestJsonService { QueryParamsAsStringListMap: QueryParamsAsStringListMap; QueryPrecedence: QueryPrecedence; RecursiveShapes: RecursiveShapes; + ResponseCodeHttpFallback: ResponseCodeHttpFallback; + ResponseCodeRequired: ResponseCodeRequired; SimpleScalarProperties: SimpleScalarProperties; SparseJsonLists: SparseJsonLists; SparseJsonMaps: SparseJsonMaps; @@ -1280,6 +1301,18 @@ export class RestJsonServiceHandler implements __ServiceHandler implements __ServiceHandler( [], { service: "RestJson", operation: "MalformedContentTypeWithoutBody" } ), + new httpbinding.UriSpec<"RestJson", "MalformedContentTypeWithoutBodyEmptyInput">( + "POST", + [{ type: "path_literal", value: "MalformedContentTypeWithoutBodyEmptyInput" }], + [], + { service: "RestJson", operation: "MalformedContentTypeWithoutBodyEmptyInput" } + ), new httpbinding.UriSpec<"RestJson", "MalformedContentTypeWithPayload">( "POST", [{ type: "path_literal", value: "MalformedContentTypeWithPayload" }], @@ -2468,6 +2531,18 @@ export const getRestJsonServiceHandler = ( [], { service: "RestJson", operation: "RecursiveShapes" } ), + new httpbinding.UriSpec<"RestJson", "ResponseCodeHttpFallback">( + "GET", + [{ type: "path_literal", value: "responseCodeHttpFallback" }], + [], + { service: "RestJson", operation: "ResponseCodeHttpFallback" } + ), + new httpbinding.UriSpec<"RestJson", "ResponseCodeRequired">( + "GET", + [{ type: "path_literal", value: "responseCodeRequired" }], + [], + { service: "RestJson", operation: "ResponseCodeRequired" } + ), new httpbinding.UriSpec<"RestJson", "SimpleScalarProperties">( "PUT", [{ type: "path_literal", value: "SimpleScalarProperties" }], @@ -2655,6 +2730,8 @@ export const getRestJsonServiceHandler = ( return new MalformedContentTypeWithGenericStringSerializer(); case "MalformedContentTypeWithoutBody": return new MalformedContentTypeWithoutBodySerializer(); + case "MalformedContentTypeWithoutBodyEmptyInput": + return new MalformedContentTypeWithoutBodyEmptyInputSerializer(); case "MalformedContentTypeWithPayload": return new MalformedContentTypeWithPayloadSerializer(); case "MalformedDouble": @@ -2733,6 +2810,10 @@ export const getRestJsonServiceHandler = ( return new QueryPrecedenceSerializer(); case "RecursiveShapes": return new RecursiveShapesSerializer(); + case "ResponseCodeHttpFallback": + return new ResponseCodeHttpFallbackSerializer(); + case "ResponseCodeRequired": + return new ResponseCodeRequiredSerializer(); case "SimpleScalarProperties": return new SimpleScalarPropertiesSerializer(); case "SparseJsonLists": diff --git a/private/aws-restjson-server/src/server/operations/MalformedContentTypeWithoutBodyEmptyInput.ts b/private/aws-restjson-server/src/server/operations/MalformedContentTypeWithoutBodyEmptyInput.ts new file mode 100644 index 000000000000..737a431008d6 --- /dev/null +++ b/private/aws-restjson-server/src/server/operations/MalformedContentTypeWithoutBodyEmptyInput.ts @@ -0,0 +1,216 @@ +// smithy-typescript generated code +import { + httpbinding, + InternalFailureException as __InternalFailureException, + isFrameworkException as __isFrameworkException, + Mux as __Mux, + Operation as __Operation, + OperationInput as __OperationInput, + OperationOutput as __OperationOutput, + OperationSerializer as __OperationSerializer, + SerializationException as __SerializationException, + ServerSerdeContext as __ServerSerdeContext, + ServerSerdeContext, + ServiceException as __ServiceException, + ServiceHandler as __ServiceHandler, + SmithyFrameworkException as __SmithyFrameworkException, + ValidationCustomizer as __ValidationCustomizer, + ValidationFailure as __ValidationFailure, +} from "@aws-smithy/server-common"; +import { NodeHttpHandler, streamCollector } from "@smithy/node-http-handler"; +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; +import { fromBase64, toBase64 } from "@smithy/util-base64"; +import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; + +import { MalformedContentTypeWithoutBodyEmptyInputInput } from "../../models/models_0"; +import { + deserializeMalformedContentTypeWithoutBodyEmptyInputRequest, + serializeFrameworkException, + serializeMalformedContentTypeWithoutBodyEmptyInputResponse, +} from "../../protocols/Aws_restJson1"; +import { RestJsonService } from "../RestJsonService"; + +export type MalformedContentTypeWithoutBodyEmptyInput = __Operation< + MalformedContentTypeWithoutBodyEmptyInputServerInput, + MalformedContentTypeWithoutBodyEmptyInputServerOutput, + Context +>; + +export interface MalformedContentTypeWithoutBodyEmptyInputServerInput + extends MalformedContentTypeWithoutBodyEmptyInputInput {} +export namespace MalformedContentTypeWithoutBodyEmptyInputServerInput { + /** + * @internal + */ + export const validate: ( + obj: Parameters[0] + ) => __ValidationFailure[] = MalformedContentTypeWithoutBodyEmptyInputInput.validate; +} +export interface MalformedContentTypeWithoutBodyEmptyInputServerOutput {} + +export type MalformedContentTypeWithoutBodyEmptyInputErrors = never; + +export class MalformedContentTypeWithoutBodyEmptyInputSerializer + implements + __OperationSerializer< + RestJsonService, + "MalformedContentTypeWithoutBodyEmptyInput", + MalformedContentTypeWithoutBodyEmptyInputErrors + > +{ + serialize = serializeMalformedContentTypeWithoutBodyEmptyInputResponse; + deserialize = deserializeMalformedContentTypeWithoutBodyEmptyInputRequest; + + isOperationError(error: any): error is MalformedContentTypeWithoutBodyEmptyInputErrors { + return false; + } + + serializeError( + error: MalformedContentTypeWithoutBodyEmptyInputErrors, + ctx: ServerSerdeContext + ): Promise<__HttpResponse> { + throw error; + } +} + +export const getMalformedContentTypeWithoutBodyEmptyInputHandler = ( + operation: __Operation< + MalformedContentTypeWithoutBodyEmptyInputServerInput, + MalformedContentTypeWithoutBodyEmptyInputServerOutput, + Context + >, + customizer: __ValidationCustomizer<"MalformedContentTypeWithoutBodyEmptyInput"> +): __ServiceHandler => { + const mux = new httpbinding.HttpBindingMux<"RestJson", "MalformedContentTypeWithoutBodyEmptyInput">([ + new httpbinding.UriSpec<"RestJson", "MalformedContentTypeWithoutBodyEmptyInput">( + "POST", + [{ type: "path_literal", value: "MalformedContentTypeWithoutBodyEmptyInput" }], + [], + { service: "RestJson", operation: "MalformedContentTypeWithoutBodyEmptyInput" } + ), + ]); + return new MalformedContentTypeWithoutBodyEmptyInputHandler( + operation, + mux, + new MalformedContentTypeWithoutBodyEmptyInputSerializer(), + serializeFrameworkException, + customizer + ); +}; + +const serdeContextBase = { + base64Encoder: toBase64, + base64Decoder: fromBase64, + utf8Encoder: toUtf8, + utf8Decoder: fromUtf8, + streamCollector: streamCollector, + requestHandler: new NodeHttpHandler(), + disableHostPrefix: true, +}; +async function handle( + request: __HttpRequest, + context: Context, + operationName: O, + serializer: __OperationSerializer, + operation: __Operation<__OperationInput, __OperationOutput, Context>, + serializeFrameworkException: (e: __SmithyFrameworkException, ctx: __ServerSerdeContext) => Promise<__HttpResponse>, + validationFn: (input: __OperationInput) => __ValidationFailure[], + validationCustomizer: __ValidationCustomizer +): Promise<__HttpResponse> { + let input; + try { + input = await serializer.deserialize(request, { + endpoint: () => Promise.resolve(request), + ...serdeContextBase, + }); + } catch (error: unknown) { + if (__isFrameworkException(error)) { + return serializeFrameworkException(error, serdeContextBase); + } + return serializeFrameworkException(new __SerializationException(), serdeContextBase); + } + try { + const validationFailures = validationFn(input); + if (validationFailures && validationFailures.length > 0) { + const validationException = validationCustomizer({ operation: operationName }, validationFailures); + if (validationException) { + return serializer.serializeError(validationException, serdeContextBase); + } + } + const output = await operation(input, context); + return serializer.serialize(output, serdeContextBase); + } catch (error: unknown) { + if (serializer.isOperationError(error)) { + return serializer.serializeError(error, serdeContextBase); + } + console.log("Received an unexpected error", error); + return serializeFrameworkException(new __InternalFailureException(), serdeContextBase); + } +} +export class MalformedContentTypeWithoutBodyEmptyInputHandler implements __ServiceHandler { + private readonly operation: __Operation< + MalformedContentTypeWithoutBodyEmptyInputServerInput, + MalformedContentTypeWithoutBodyEmptyInputServerOutput, + Context + >; + private readonly mux: __Mux<"RestJson", "MalformedContentTypeWithoutBodyEmptyInput">; + private readonly serializer: __OperationSerializer< + RestJsonService, + "MalformedContentTypeWithoutBodyEmptyInput", + MalformedContentTypeWithoutBodyEmptyInputErrors + >; + private readonly serializeFrameworkException: ( + e: __SmithyFrameworkException, + ctx: __ServerSerdeContext + ) => Promise<__HttpResponse>; + private readonly validationCustomizer: __ValidationCustomizer<"MalformedContentTypeWithoutBodyEmptyInput">; + /** + * Construct a MalformedContentTypeWithoutBodyEmptyInput handler. + * @param operation The {@link __Operation} implementation that supplies the business logic for MalformedContentTypeWithoutBodyEmptyInput + * @param mux The {@link __Mux} that verifies which service and operation are being invoked by a given {@link __HttpRequest} + * @param serializer An {@link __OperationSerializer} for MalformedContentTypeWithoutBodyEmptyInput that + * handles deserialization of requests and serialization of responses + * @param serializeFrameworkException A function that can serialize {@link __SmithyFrameworkException}s + * @param validationCustomizer A {@link __ValidationCustomizer} for turning validation failures into {@link __SmithyFrameworkException}s + */ + constructor( + operation: __Operation< + MalformedContentTypeWithoutBodyEmptyInputServerInput, + MalformedContentTypeWithoutBodyEmptyInputServerOutput, + Context + >, + mux: __Mux<"RestJson", "MalformedContentTypeWithoutBodyEmptyInput">, + serializer: __OperationSerializer< + RestJsonService, + "MalformedContentTypeWithoutBodyEmptyInput", + MalformedContentTypeWithoutBodyEmptyInputErrors + >, + serializeFrameworkException: (e: __SmithyFrameworkException, ctx: __ServerSerdeContext) => Promise<__HttpResponse>, + validationCustomizer: __ValidationCustomizer<"MalformedContentTypeWithoutBodyEmptyInput"> + ) { + this.operation = operation; + this.mux = mux; + this.serializer = serializer; + this.serializeFrameworkException = serializeFrameworkException; + this.validationCustomizer = validationCustomizer; + } + async handle(request: __HttpRequest, context: Context): Promise<__HttpResponse> { + const target = this.mux.match(request); + if (target === undefined) { + console.log( + "Received a request that did not match aws.protocoltests.restjson#RestJson.MalformedContentTypeWithoutBodyEmptyInput. This indicates a misconfiguration." + ); + return this.serializeFrameworkException(new __InternalFailureException(), serdeContextBase); + } + return handle( + request, + context, + "MalformedContentTypeWithoutBodyEmptyInput", + this.serializer, + this.operation, + this.serializeFrameworkException, + MalformedContentTypeWithoutBodyEmptyInputServerInput.validate, + this.validationCustomizer + ); + } +} diff --git a/private/aws-restjson-server/src/server/operations/ResponseCodeHttpFallback.ts b/private/aws-restjson-server/src/server/operations/ResponseCodeHttpFallback.ts new file mode 100644 index 000000000000..d893a04d0738 --- /dev/null +++ b/private/aws-restjson-server/src/server/operations/ResponseCodeHttpFallback.ts @@ -0,0 +1,199 @@ +// smithy-typescript generated code +import { + httpbinding, + InternalFailureException as __InternalFailureException, + isFrameworkException as __isFrameworkException, + Mux as __Mux, + Operation as __Operation, + OperationInput as __OperationInput, + OperationOutput as __OperationOutput, + OperationSerializer as __OperationSerializer, + SerializationException as __SerializationException, + ServerSerdeContext as __ServerSerdeContext, + ServerSerdeContext, + ServiceException as __ServiceException, + ServiceHandler as __ServiceHandler, + SmithyFrameworkException as __SmithyFrameworkException, + ValidationCustomizer as __ValidationCustomizer, + ValidationFailure as __ValidationFailure, +} from "@aws-smithy/server-common"; +import { NodeHttpHandler, streamCollector } from "@smithy/node-http-handler"; +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; +import { fromBase64, toBase64 } from "@smithy/util-base64"; +import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; + +import { ResponseCodeHttpFallbackInputOutput } from "../../models/models_0"; +import { + deserializeResponseCodeHttpFallbackRequest, + serializeFrameworkException, + serializeResponseCodeHttpFallbackResponse, +} from "../../protocols/Aws_restJson1"; +import { RestJsonService } from "../RestJsonService"; + +export type ResponseCodeHttpFallback = __Operation< + ResponseCodeHttpFallbackServerInput, + ResponseCodeHttpFallbackServerOutput, + Context +>; + +export interface ResponseCodeHttpFallbackServerInput extends ResponseCodeHttpFallbackInputOutput {} +export namespace ResponseCodeHttpFallbackServerInput { + /** + * @internal + */ + export const validate: ( + obj: Parameters[0] + ) => __ValidationFailure[] = ResponseCodeHttpFallbackInputOutput.validate; +} +export interface ResponseCodeHttpFallbackServerOutput extends ResponseCodeHttpFallbackInputOutput {} + +export type ResponseCodeHttpFallbackErrors = never; + +export class ResponseCodeHttpFallbackSerializer + implements __OperationSerializer, "ResponseCodeHttpFallback", ResponseCodeHttpFallbackErrors> +{ + serialize = serializeResponseCodeHttpFallbackResponse; + deserialize = deserializeResponseCodeHttpFallbackRequest; + + isOperationError(error: any): error is ResponseCodeHttpFallbackErrors { + return false; + } + + serializeError(error: ResponseCodeHttpFallbackErrors, ctx: ServerSerdeContext): Promise<__HttpResponse> { + throw error; + } +} + +export const getResponseCodeHttpFallbackHandler = ( + operation: __Operation, + customizer: __ValidationCustomizer<"ResponseCodeHttpFallback"> +): __ServiceHandler => { + const mux = new httpbinding.HttpBindingMux<"RestJson", "ResponseCodeHttpFallback">([ + new httpbinding.UriSpec<"RestJson", "ResponseCodeHttpFallback">( + "GET", + [{ type: "path_literal", value: "responseCodeHttpFallback" }], + [], + { service: "RestJson", operation: "ResponseCodeHttpFallback" } + ), + ]); + return new ResponseCodeHttpFallbackHandler( + operation, + mux, + new ResponseCodeHttpFallbackSerializer(), + serializeFrameworkException, + customizer + ); +}; + +const serdeContextBase = { + base64Encoder: toBase64, + base64Decoder: fromBase64, + utf8Encoder: toUtf8, + utf8Decoder: fromUtf8, + streamCollector: streamCollector, + requestHandler: new NodeHttpHandler(), + disableHostPrefix: true, +}; +async function handle( + request: __HttpRequest, + context: Context, + operationName: O, + serializer: __OperationSerializer, + operation: __Operation<__OperationInput, __OperationOutput, Context>, + serializeFrameworkException: (e: __SmithyFrameworkException, ctx: __ServerSerdeContext) => Promise<__HttpResponse>, + validationFn: (input: __OperationInput) => __ValidationFailure[], + validationCustomizer: __ValidationCustomizer +): Promise<__HttpResponse> { + let input; + try { + input = await serializer.deserialize(request, { + endpoint: () => Promise.resolve(request), + ...serdeContextBase, + }); + } catch (error: unknown) { + if (__isFrameworkException(error)) { + return serializeFrameworkException(error, serdeContextBase); + } + return serializeFrameworkException(new __SerializationException(), serdeContextBase); + } + try { + const validationFailures = validationFn(input); + if (validationFailures && validationFailures.length > 0) { + const validationException = validationCustomizer({ operation: operationName }, validationFailures); + if (validationException) { + return serializer.serializeError(validationException, serdeContextBase); + } + } + const output = await operation(input, context); + return serializer.serialize(output, serdeContextBase); + } catch (error: unknown) { + if (serializer.isOperationError(error)) { + return serializer.serializeError(error, serdeContextBase); + } + console.log("Received an unexpected error", error); + return serializeFrameworkException(new __InternalFailureException(), serdeContextBase); + } +} +export class ResponseCodeHttpFallbackHandler implements __ServiceHandler { + private readonly operation: __Operation< + ResponseCodeHttpFallbackServerInput, + ResponseCodeHttpFallbackServerOutput, + Context + >; + private readonly mux: __Mux<"RestJson", "ResponseCodeHttpFallback">; + private readonly serializer: __OperationSerializer< + RestJsonService, + "ResponseCodeHttpFallback", + ResponseCodeHttpFallbackErrors + >; + private readonly serializeFrameworkException: ( + e: __SmithyFrameworkException, + ctx: __ServerSerdeContext + ) => Promise<__HttpResponse>; + private readonly validationCustomizer: __ValidationCustomizer<"ResponseCodeHttpFallback">; + /** + * Construct a ResponseCodeHttpFallback handler. + * @param operation The {@link __Operation} implementation that supplies the business logic for ResponseCodeHttpFallback + * @param mux The {@link __Mux} that verifies which service and operation are being invoked by a given {@link __HttpRequest} + * @param serializer An {@link __OperationSerializer} for ResponseCodeHttpFallback that + * handles deserialization of requests and serialization of responses + * @param serializeFrameworkException A function that can serialize {@link __SmithyFrameworkException}s + * @param validationCustomizer A {@link __ValidationCustomizer} for turning validation failures into {@link __SmithyFrameworkException}s + */ + constructor( + operation: __Operation, + mux: __Mux<"RestJson", "ResponseCodeHttpFallback">, + serializer: __OperationSerializer< + RestJsonService, + "ResponseCodeHttpFallback", + ResponseCodeHttpFallbackErrors + >, + serializeFrameworkException: (e: __SmithyFrameworkException, ctx: __ServerSerdeContext) => Promise<__HttpResponse>, + validationCustomizer: __ValidationCustomizer<"ResponseCodeHttpFallback"> + ) { + this.operation = operation; + this.mux = mux; + this.serializer = serializer; + this.serializeFrameworkException = serializeFrameworkException; + this.validationCustomizer = validationCustomizer; + } + async handle(request: __HttpRequest, context: Context): Promise<__HttpResponse> { + const target = this.mux.match(request); + if (target === undefined) { + console.log( + "Received a request that did not match aws.protocoltests.restjson#RestJson.ResponseCodeHttpFallback. This indicates a misconfiguration." + ); + return this.serializeFrameworkException(new __InternalFailureException(), serdeContextBase); + } + return handle( + request, + context, + "ResponseCodeHttpFallback", + this.serializer, + this.operation, + this.serializeFrameworkException, + ResponseCodeHttpFallbackServerInput.validate, + this.validationCustomizer + ); + } +} diff --git a/private/aws-restjson-server/src/server/operations/ResponseCodeRequired.ts b/private/aws-restjson-server/src/server/operations/ResponseCodeRequired.ts new file mode 100644 index 000000000000..3b1c8f3bf587 --- /dev/null +++ b/private/aws-restjson-server/src/server/operations/ResponseCodeRequired.ts @@ -0,0 +1,189 @@ +// smithy-typescript generated code +import { + httpbinding, + InternalFailureException as __InternalFailureException, + isFrameworkException as __isFrameworkException, + Mux as __Mux, + Operation as __Operation, + OperationInput as __OperationInput, + OperationOutput as __OperationOutput, + OperationSerializer as __OperationSerializer, + SerializationException as __SerializationException, + ServerSerdeContext as __ServerSerdeContext, + ServerSerdeContext, + ServiceException as __ServiceException, + ServiceHandler as __ServiceHandler, + SmithyFrameworkException as __SmithyFrameworkException, + ValidationCustomizer as __ValidationCustomizer, + ValidationFailure as __ValidationFailure, +} from "@aws-smithy/server-common"; +import { NodeHttpHandler, streamCollector } from "@smithy/node-http-handler"; +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; +import { fromBase64, toBase64 } from "@smithy/util-base64"; +import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; + +import { ResponseCodeRequiredOutput } from "../../models/models_0"; +import { + deserializeResponseCodeRequiredRequest, + serializeFrameworkException, + serializeResponseCodeRequiredResponse, +} from "../../protocols/Aws_restJson1"; +import { RestJsonService } from "../RestJsonService"; + +export type ResponseCodeRequired = __Operation< + ResponseCodeRequiredServerInput, + ResponseCodeRequiredServerOutput, + Context +>; + +export interface ResponseCodeRequiredServerInput {} +export namespace ResponseCodeRequiredServerInput { + /** + * @internal + */ + export const validate: () => __ValidationFailure[] = () => []; +} +export interface ResponseCodeRequiredServerOutput extends ResponseCodeRequiredOutput {} + +export type ResponseCodeRequiredErrors = never; + +export class ResponseCodeRequiredSerializer + implements __OperationSerializer, "ResponseCodeRequired", ResponseCodeRequiredErrors> +{ + serialize = serializeResponseCodeRequiredResponse; + deserialize = deserializeResponseCodeRequiredRequest; + + isOperationError(error: any): error is ResponseCodeRequiredErrors { + return false; + } + + serializeError(error: ResponseCodeRequiredErrors, ctx: ServerSerdeContext): Promise<__HttpResponse> { + throw error; + } +} + +export const getResponseCodeRequiredHandler = ( + operation: __Operation, + customizer: __ValidationCustomizer<"ResponseCodeRequired"> +): __ServiceHandler => { + const mux = new httpbinding.HttpBindingMux<"RestJson", "ResponseCodeRequired">([ + new httpbinding.UriSpec<"RestJson", "ResponseCodeRequired">( + "GET", + [{ type: "path_literal", value: "responseCodeRequired" }], + [], + { service: "RestJson", operation: "ResponseCodeRequired" } + ), + ]); + return new ResponseCodeRequiredHandler( + operation, + mux, + new ResponseCodeRequiredSerializer(), + serializeFrameworkException, + customizer + ); +}; + +const serdeContextBase = { + base64Encoder: toBase64, + base64Decoder: fromBase64, + utf8Encoder: toUtf8, + utf8Decoder: fromUtf8, + streamCollector: streamCollector, + requestHandler: new NodeHttpHandler(), + disableHostPrefix: true, +}; +async function handle( + request: __HttpRequest, + context: Context, + operationName: O, + serializer: __OperationSerializer, + operation: __Operation<__OperationInput, __OperationOutput, Context>, + serializeFrameworkException: (e: __SmithyFrameworkException, ctx: __ServerSerdeContext) => Promise<__HttpResponse>, + validationFn: (input: __OperationInput) => __ValidationFailure[], + validationCustomizer: __ValidationCustomizer +): Promise<__HttpResponse> { + let input; + try { + input = await serializer.deserialize(request, { + endpoint: () => Promise.resolve(request), + ...serdeContextBase, + }); + } catch (error: unknown) { + if (__isFrameworkException(error)) { + return serializeFrameworkException(error, serdeContextBase); + } + return serializeFrameworkException(new __SerializationException(), serdeContextBase); + } + try { + const validationFailures = validationFn(input); + if (validationFailures && validationFailures.length > 0) { + const validationException = validationCustomizer({ operation: operationName }, validationFailures); + if (validationException) { + return serializer.serializeError(validationException, serdeContextBase); + } + } + const output = await operation(input, context); + return serializer.serialize(output, serdeContextBase); + } catch (error: unknown) { + if (serializer.isOperationError(error)) { + return serializer.serializeError(error, serdeContextBase); + } + console.log("Received an unexpected error", error); + return serializeFrameworkException(new __InternalFailureException(), serdeContextBase); + } +} +export class ResponseCodeRequiredHandler implements __ServiceHandler { + private readonly operation: __Operation; + private readonly mux: __Mux<"RestJson", "ResponseCodeRequired">; + private readonly serializer: __OperationSerializer< + RestJsonService, + "ResponseCodeRequired", + ResponseCodeRequiredErrors + >; + private readonly serializeFrameworkException: ( + e: __SmithyFrameworkException, + ctx: __ServerSerdeContext + ) => Promise<__HttpResponse>; + private readonly validationCustomizer: __ValidationCustomizer<"ResponseCodeRequired">; + /** + * Construct a ResponseCodeRequired handler. + * @param operation The {@link __Operation} implementation that supplies the business logic for ResponseCodeRequired + * @param mux The {@link __Mux} that verifies which service and operation are being invoked by a given {@link __HttpRequest} + * @param serializer An {@link __OperationSerializer} for ResponseCodeRequired that + * handles deserialization of requests and serialization of responses + * @param serializeFrameworkException A function that can serialize {@link __SmithyFrameworkException}s + * @param validationCustomizer A {@link __ValidationCustomizer} for turning validation failures into {@link __SmithyFrameworkException}s + */ + constructor( + operation: __Operation, + mux: __Mux<"RestJson", "ResponseCodeRequired">, + serializer: __OperationSerializer, "ResponseCodeRequired", ResponseCodeRequiredErrors>, + serializeFrameworkException: (e: __SmithyFrameworkException, ctx: __ServerSerdeContext) => Promise<__HttpResponse>, + validationCustomizer: __ValidationCustomizer<"ResponseCodeRequired"> + ) { + this.operation = operation; + this.mux = mux; + this.serializer = serializer; + this.serializeFrameworkException = serializeFrameworkException; + this.validationCustomizer = validationCustomizer; + } + async handle(request: __HttpRequest, context: Context): Promise<__HttpResponse> { + const target = this.mux.match(request); + if (target === undefined) { + console.log( + "Received a request that did not match aws.protocoltests.restjson#RestJson.ResponseCodeRequired. This indicates a misconfiguration." + ); + return this.serializeFrameworkException(new __InternalFailureException(), serdeContextBase); + } + return handle( + request, + context, + "ResponseCodeRequired", + this.serializer, + this.operation, + this.serializeFrameworkException, + ResponseCodeRequiredServerInput.validate, + this.validationCustomizer + ); + } +} diff --git a/private/aws-restjson-server/src/server/operations/index.ts b/private/aws-restjson-server/src/server/operations/index.ts index a6617fb0da91..149769bc0e82 100644 --- a/private/aws-restjson-server/src/server/operations/index.ts +++ b/private/aws-restjson-server/src/server/operations/index.ts @@ -47,6 +47,7 @@ export * from "./MalformedContentTypeWithBody"; export * from "./MalformedContentTypeWithGenericString"; export * from "./MalformedContentTypeWithPayload"; export * from "./MalformedContentTypeWithoutBody"; +export * from "./MalformedContentTypeWithoutBodyEmptyInput"; export * from "./MalformedDouble"; export * from "./MalformedFloat"; export * from "./MalformedInteger"; @@ -85,6 +86,8 @@ export * from "./QueryIdempotencyTokenAutoFill"; export * from "./QueryParamsAsStringListMap"; export * from "./QueryPrecedence"; export * from "./RecursiveShapes"; +export * from "./ResponseCodeHttpFallback"; +export * from "./ResponseCodeRequired"; export * from "./SimpleScalarProperties"; export * from "./SparseJsonLists"; export * from "./SparseJsonMaps"; diff --git a/private/aws-restjson-server/test/functional/restjson1.spec.ts b/private/aws-restjson-server/test/functional/restjson1.spec.ts index dbdd5d79861b..dbcd43f43c73 100644 --- a/private/aws-restjson-server/test/functional/restjson1.spec.ts +++ b/private/aws-restjson-server/test/functional/restjson1.spec.ts @@ -124,6 +124,7 @@ import { MalformedBoolean } from "../../src/server/operations/MalformedBoolean"; import { MalformedByte } from "../../src/server/operations/MalformedByte"; import { MalformedContentTypeWithBody } from "../../src/server/operations/MalformedContentTypeWithBody"; import { MalformedContentTypeWithoutBody } from "../../src/server/operations/MalformedContentTypeWithoutBody"; +import { MalformedContentTypeWithoutBodyEmptyInput } from "../../src/server/operations/MalformedContentTypeWithoutBodyEmptyInput"; import { MalformedContentTypeWithPayload } from "../../src/server/operations/MalformedContentTypeWithPayload"; import { MalformedDouble } from "../../src/server/operations/MalformedDouble"; import { MalformedFloat } from "../../src/server/operations/MalformedFloat"; @@ -195,6 +196,14 @@ import { RecursiveShapesSerializer, RecursiveShapesServerOutput, } from "../../src/server/operations/RecursiveShapes"; +import { + ResponseCodeHttpFallbackSerializer, + ResponseCodeHttpFallbackServerOutput, +} from "../../src/server/operations/ResponseCodeHttpFallback"; +import { + ResponseCodeRequiredSerializer, + ResponseCodeRequiredServerOutput, +} from "../../src/server/operations/ResponseCodeRequired"; import { SimpleScalarProperties, SimpleScalarPropertiesSerializer, @@ -3289,8 +3298,8 @@ it("RestJsonHttpPrefixHeadersArePresent:ServerResponse", async () => { const response = { foo: "Foo", fooMap: { - Abc: "Abc value", - Def: "Def value", + abc: "Abc value", + def: "Def value", } as any, } as any; return Promise.resolve({ ...response, $metadata: {} }); @@ -3346,8 +3355,8 @@ it("HttpPrefixHeadersResponse:ServerResponse", async () => { HttpPrefixHeadersInResponse(input: any, ctx: {}): Promise { const response = { prefixHeaders: { - "X-Foo": "Foo", - Hello: "Hello", + "x-foo": "Foo", + hello: "Hello", } as any, } as any; return Promise.resolve({ ...response, $metadata: {} }); @@ -14560,6 +14569,44 @@ it("RestJsonWithoutBodyExpectsEmptyContentType:MalformedRequest", async () => { expect(r.headers["x-amzn-errortype"]).toBe("UnsupportedMediaTypeException"); }); +/** + * When there is no modeled body input, content type must not be set and the body must be empty. + */ +it.skip("RestJsonWithoutBodyEmptyInputExpectsEmptyContentType:MalformedRequest", async () => { + const testFunction = vi.fn(); + testFunction.mockImplementation(() => { + throw new Error("This request should have been rejected."); + }); + const testService: Partial> = { + MalformedContentTypeWithoutBodyEmptyInput: testFunction as MalformedContentTypeWithoutBodyEmptyInput<{}>, + }; + const handler = getRestJsonServiceHandler( + testService as RestJsonService<{}>, + (ctx: {}, failures: __ValidationFailure[]) => { + if (failures) { + throw failures; + } + return undefined; + } + ); + const request = new HttpRequest({ + method: "POST", + hostname: "foo.example.com", + path: "/MalformedContentTypeWithoutBodyEmptyInput", + query: {}, + headers: { + "content-type": "application/json", + }, + body: Readable.from(["{}"]), + }); + const r = await handler.handle(request, {}); + + expect(testFunction.mock.calls.length).toBe(0); + expect(r.statusCode).toBe(415); + expect(r.headers["x-amzn-errortype"]).toBeDefined(); + expect(r.headers["x-amzn-errortype"]).toBe("UnsupportedMediaTypeException"); +}); + /** * When there is a payload with a mediaType trait, the content type must match. */ @@ -27857,7 +27904,7 @@ it("RestJsonNoInputAndOutputWithJson:ServerResponse", async () => { }); /** - * Do not send null or empty headers + * Do not send null values, but do send empty strings and empty lists over the wire in headers */ it.skip("RestJsonNullAndEmptyHeaders:ServerResponse", async () => { class TestService implements Partial> { @@ -27905,8 +27952,11 @@ it.skip("RestJsonNullAndEmptyHeaders:ServerResponse", async () => { expect(r.statusCode).toBe(200); expect(r.headers["x-a"]).toBeUndefined(); - expect(r.headers["x-b"]).toBeUndefined(); - expect(r.headers["x-c"]).toBeUndefined(); + + expect(r.headers["x-b"]).toBeDefined(); + expect(r.headers["x-b"]).toBe(""); + expect(r.headers["x-c"]).toBeDefined(); + expect(r.headers["x-c"]).toBe(""); }); /** @@ -29122,6 +29172,117 @@ it("RestJsonRecursiveShapes:ServerResponse", async () => { expect(unequalParts).toBeUndefined(); }); +/** + * This test ensures that servers fall back to the code set + * by @http if @httpResponseCode is not set. + */ +it("RestJsonHttpResponseCodeNotSetFallsBackToHttpCode:ServerResponse", async () => { + class TestService implements Partial> { + ResponseCodeHttpFallback(input: any, ctx: {}): Promise { + const response = {} as any; + return Promise.resolve({ ...response, $metadata: {} }); + } + } + const service: any = new TestService(); + const testMux = new httpbinding.HttpBindingMux<"RestJson", keyof RestJsonService<{}>>([ + new httpbinding.UriSpec<"RestJson", "ResponseCodeHttpFallback">("POST", [], [], { + service: "RestJson", + operation: "ResponseCodeHttpFallback", + }), + ]); + class TestSerializer extends ResponseCodeHttpFallbackSerializer { + deserialize = (output: any, context: any): Promise => { + return Promise.resolve({}); + }; + } + const request = new HttpRequest({ method: "POST", hostname: "example.com" }); + const serFn: ( + op: RestJsonServiceOperations + ) => __OperationSerializer, RestJsonServiceOperations, __ServiceException> = (op) => { + return new TestSerializer(); + }; + const handler = new RestJsonServiceHandler( + service, + testMux, + serFn, + serializeFrameworkException, + (ctx: {}, f: __ValidationFailure[]) => { + if (f) { + throw f; + } + return undefined; + } + ); + const r = await handler.handle(request, {}); + + expect(r.statusCode).toBe(201); + + expect(r.headers["content-type"]).toBeDefined(); + expect(r.headers["content-type"]).toBe("application/json"); + + expect(r.body).toBeDefined(); + const utf8Encoder = __utf8Encoder; + const bodyString = `{}`; + const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); + expect(unequalParts).toBeUndefined(); +}); + +/** + * This test ensures that servers handle @httpResponseCode being @required. + */ +it("RestJsonHttpResponseCodeRequired:ServerResponse", async () => { + class TestService implements Partial> { + ResponseCodeRequired(input: any, ctx: {}): Promise { + const response = { + responseCode: 201, + } as any; + return Promise.resolve({ ...response, $metadata: {} }); + } + } + const service: any = new TestService(); + const testMux = new httpbinding.HttpBindingMux<"RestJson", keyof RestJsonService<{}>>([ + new httpbinding.UriSpec<"RestJson", "ResponseCodeRequired">("POST", [], [], { + service: "RestJson", + operation: "ResponseCodeRequired", + }), + ]); + class TestSerializer extends ResponseCodeRequiredSerializer { + deserialize = (output: any, context: any): Promise => { + return Promise.resolve({}); + }; + } + const request = new HttpRequest({ method: "POST", hostname: "example.com" }); + const serFn: ( + op: RestJsonServiceOperations + ) => __OperationSerializer, RestJsonServiceOperations, __ServiceException> = (op) => { + return new TestSerializer(); + }; + const handler = new RestJsonServiceHandler( + service, + testMux, + serFn, + serializeFrameworkException, + (ctx: {}, f: __ValidationFailure[]) => { + if (f) { + throw f; + } + return undefined; + } + ); + const r = await handler.handle(request, {}); + + expect(r.statusCode).toBe(201); + + expect(r.headers["content-type"]).toBeDefined(); + expect(r.headers["content-type"]).toBe("application/json"); + + expect(r.body).toBeDefined(); + const utf8Encoder = __utf8Encoder; + const bodyString = `{}`; + const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); + expect(unequalParts).toBeUndefined(); +}); + /** * Serializes simple scalar properties */ @@ -29410,16 +29571,16 @@ it("RestJsonSimpleScalarProperties:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"stringValue\": \"string\", - \"trueBooleanValue\": true, - \"falseBooleanValue\": false, - \"byteValue\": 1, - \"shortValue\": 2, - \"integerValue\": 3, - \"longValue\": 4, - \"floatValue\": 5.5, - \"DoubleDribble\": 6.5 - }`; + \"stringValue\": \"string\", + \"trueBooleanValue\": true, + \"falseBooleanValue\": false, + \"byteValue\": 1, + \"shortValue\": 2, + \"integerValue\": 3, + \"longValue\": 4, + \"floatValue\": 5.5, + \"DoubleDribble\": 6.5 + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -29533,9 +29694,9 @@ it("RestJsonSupportsNaNFloatInputs:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"floatValue\": \"NaN\", - \"DoubleDribble\": \"NaN\" - }`; + \"floatValue\": \"NaN\", + \"DoubleDribble\": \"NaN\" + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -29593,9 +29754,9 @@ it("RestJsonSupportsInfinityFloatInputs:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"floatValue\": \"Infinity\", - \"DoubleDribble\": \"Infinity\" - }`; + \"floatValue\": \"Infinity\", + \"DoubleDribble\": \"Infinity\" + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -29653,9 +29814,9 @@ it("RestJsonSupportsNegativeInfinityFloatInputs:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"floatValue\": \"-Infinity\", - \"DoubleDribble\": \"-Infinity\" - }`; + \"floatValue\": \"-Infinity\", + \"DoubleDribble\": \"-Infinity\" + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -29760,15 +29921,15 @@ it("RestJsonSparseListsSerializeNull:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"sparseStringList\": [ - null, - \"hi\" - ], - \"sparseShortList\": [ - null, - 2 - ] - }`; + \"sparseStringList\": [ + null, + \"hi\" + ], + \"sparseShortList\": [ + null, + 2 + ] + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -30090,15 +30251,15 @@ it("RestJsonSparseJsonMaps:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"sparseStructMap\": { - \"foo\": { - \"hi\": \"there\" - }, - \"baz\": { - \"hi\": \"bye\" - } - } - }`; + \"sparseStructMap\": { + \"foo\": { + \"hi\": \"there\" + }, + \"baz\": { + \"hi\": \"bye\" + } + } + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -30166,19 +30327,19 @@ it("RestJsonDeserializesSparseNullMapValues:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"sparseBooleanMap\": { - \"x\": null - }, - \"sparseNumberMap\": { - \"x\": null - }, - \"sparseStringMap\": { - \"x\": null - }, - \"sparseStructMap\": { - \"x\": null - } - }`; + \"sparseBooleanMap\": { + \"x\": null + }, + \"sparseNumberMap\": { + \"x\": null + }, + \"sparseStringMap\": { + \"x\": null + }, + \"sparseStructMap\": { + \"x\": null + } + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -30240,13 +30401,13 @@ it("RestJsonDeserializesZeroValuesInSparseMaps:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"sparseNumberMap\": { - \"x\": 0 - }, - \"sparseBooleanMap\": { - \"x\": false - } - }`; + \"sparseNumberMap\": { + \"x\": 0 + }, + \"sparseBooleanMap\": { + \"x\": false + } + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -30306,11 +30467,11 @@ it("RestJsonDeserializesSparseSetMap:ServerResponse", async () => { expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"sparseSetMap\": { - \"x\": [], - \"y\": [\"a\", \"b\"] - } - }`; + \"sparseSetMap\": { + \"x\": [], + \"y\": [\"a\", \"b\"] + } + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); @@ -30371,12 +30532,12 @@ it("RestJsonDeserializesSparseSetMapAndRetainsNull:ServerResponse", async () => expect(r.body).toBeDefined(); const utf8Encoder = __utf8Encoder; const bodyString = `{ - \"sparseSetMap\": { - \"x\": [], - \"y\": [\"a\", \"b\"], - \"z\": null - } - }`; + \"sparseSetMap\": { + \"x\": [], + \"y\": [\"a\", \"b\"], + \"z\": null + } + }`; const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); }); diff --git a/scripts/generate-clients/config.js b/scripts/generate-clients/config.js index 3183de50d062..a56714de9012 100644 --- a/scripts/generate-clients/config.js +++ b/scripts/generate-clients/config.js @@ -1,7 +1,7 @@ // Update this commit when taking up new changes from smithy-typescript. module.exports = { // Use full commit hash as we explicitly fetch it. - SMITHY_TS_COMMIT: "ef8d8253337bd98c5b4ce3d62ded633b4efddafa", + SMITHY_TS_COMMIT: "5aeb781faf8535a352161fbfaaf5f8013fd6a35d", }; if (module.exports.SMITHY_TS_COMMIT.length < 40) {