From fbd405c186c12208e50e87defa0c939eb8415853 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 10 May 2021 20:21:07 +0000 Subject: [PATCH 1/5] chore(protocol_tests): add tests from smithy 1.7.1 release --- protocol_tests/aws-restxml/RestXmlProtocol.ts | 39 ++++++ .../aws-restxml/RestXmlProtocolClient.ts | 3 + .../commands/BodyWithXmlNameCommand.ts | 95 ++++++++++++++ .../aws-restxml/commands/XmlListsCommand.ts | 1 + protocol_tests/aws-restxml/index.ts | 1 + protocol_tests/aws-restxml/models/models_0.ts | 40 ++++-- .../aws-restxml/protocols/Aws_restXml.ts | 110 ++++++++++++++++ .../tests/functional/restxml.spec.ts | 124 ++++++++++++++++++ 8 files changed, 400 insertions(+), 13 deletions(-) create mode 100644 protocol_tests/aws-restxml/commands/BodyWithXmlNameCommand.ts diff --git a/protocol_tests/aws-restxml/RestXmlProtocol.ts b/protocol_tests/aws-restxml/RestXmlProtocol.ts index 5e1f9a19295a3..f9448af81049a 100644 --- a/protocol_tests/aws-restxml/RestXmlProtocol.ts +++ b/protocol_tests/aws-restxml/RestXmlProtocol.ts @@ -4,6 +4,11 @@ import { AllQueryStringTypesCommandInput, AllQueryStringTypesCommandOutput, } from "./commands/AllQueryStringTypesCommand"; +import { + BodyWithXmlNameCommand, + BodyWithXmlNameCommandInput, + BodyWithXmlNameCommandOutput, +} from "./commands/BodyWithXmlNameCommand"; import { ConstantAndVariableQueryStringCommand, ConstantAndVariableQueryStringCommandInput, @@ -272,6 +277,39 @@ export class RestXmlProtocol extends RestXmlProtocolClient { } } + /** + * The following example serializes a body that uses an XML name, + * changing the wrapper name. + */ + public bodyWithXmlName( + args: BodyWithXmlNameCommandInput, + options?: __HttpHandlerOptions + ): Promise; + public bodyWithXmlName( + args: BodyWithXmlNameCommandInput, + cb: (err: any, data?: BodyWithXmlNameCommandOutput) => void + ): void; + public bodyWithXmlName( + args: BodyWithXmlNameCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: BodyWithXmlNameCommandOutput) => void + ): void; + public bodyWithXmlName( + args: BodyWithXmlNameCommandInput, + optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: BodyWithXmlNameCommandOutput) => void), + cb?: (err: any, data?: BodyWithXmlNameCommandOutput) => void + ): Promise | void { + const command = new BodyWithXmlNameCommand(args); + if (typeof optionsOrCb === "function") { + this.send(command, optionsOrCb); + } else if (typeof cb === "function") { + if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`); + this.send(command, optionsOrCb || {}, cb); + } else { + return this.send(command, optionsOrCb); + } + } + /** * This example uses fixed query string params and variable query string params. * The fixed query string parameters and variable parameters must both be @@ -1678,6 +1716,7 @@ export class RestXmlProtocol extends RestXmlProtocolClient { * 6. Flattened XML lists with @xmlName. * 7. Flattened XML lists with @xmlNamespace. * 8. Lists of structures. + * 9. Flattened XML list of structures */ public xmlLists(args: XmlListsCommandInput, options?: __HttpHandlerOptions): Promise; public xmlLists(args: XmlListsCommandInput, cb: (err: any, data?: XmlListsCommandOutput) => void): void; diff --git a/protocol_tests/aws-restxml/RestXmlProtocolClient.ts b/protocol_tests/aws-restxml/RestXmlProtocolClient.ts index 962d76f154fd7..11c8de807ebc7 100644 --- a/protocol_tests/aws-restxml/RestXmlProtocolClient.ts +++ b/protocol_tests/aws-restxml/RestXmlProtocolClient.ts @@ -2,6 +2,7 @@ import { AllQueryStringTypesCommandInput, AllQueryStringTypesCommandOutput, } from "./commands/AllQueryStringTypesCommand"; +import { BodyWithXmlNameCommandInput, BodyWithXmlNameCommandOutput } from "./commands/BodyWithXmlNameCommand"; import { ConstantAndVariableQueryStringCommandInput, ConstantAndVariableQueryStringCommandOutput, @@ -176,6 +177,7 @@ import { export type ServiceInputTypes = | AllQueryStringTypesCommandInput + | BodyWithXmlNameCommandInput | ConstantAndVariableQueryStringCommandInput | ConstantQueryStringCommandInput | EmptyInputAndEmptyOutputCommandInput @@ -229,6 +231,7 @@ export type ServiceInputTypes = export type ServiceOutputTypes = | AllQueryStringTypesCommandOutput + | BodyWithXmlNameCommandOutput | ConstantAndVariableQueryStringCommandOutput | ConstantQueryStringCommandOutput | EmptyInputAndEmptyOutputCommandOutput diff --git a/protocol_tests/aws-restxml/commands/BodyWithXmlNameCommand.ts b/protocol_tests/aws-restxml/commands/BodyWithXmlNameCommand.ts new file mode 100644 index 0000000000000..8cf37a4c024cc --- /dev/null +++ b/protocol_tests/aws-restxml/commands/BodyWithXmlNameCommand.ts @@ -0,0 +1,95 @@ +import { RestXmlProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../RestXmlProtocolClient"; +import { BodyWithXmlNameInputOutput } from "../models/models_0"; +import { + deserializeAws_restXmlBodyWithXmlNameCommand, + serializeAws_restXmlBodyWithXmlNameCommand, +} from "../protocols/Aws_restXml"; +import { getSerdePlugin } from "@aws-sdk/middleware-serde"; +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http"; +import { Command as $Command } from "@aws-sdk/smithy-client"; +import { + FinalizeHandlerArguments, + Handler, + HandlerExecutionContext, + MiddlewareStack, + HttpHandlerOptions as __HttpHandlerOptions, + MetadataBearer as __MetadataBearer, + SerdeContext as __SerdeContext, +} from "@aws-sdk/types"; + +export interface BodyWithXmlNameCommandInput extends BodyWithXmlNameInputOutput {} +export interface BodyWithXmlNameCommandOutput extends BodyWithXmlNameInputOutput, __MetadataBearer {} + +/** + * The following example serializes a body that uses an XML name, + * changing the wrapper name. + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { RestXmlProtocolClient, BodyWithXmlNameCommand } from "@aws-sdk/aws-restxml"; // ES Modules import + * // const { RestXmlProtocolClient, BodyWithXmlNameCommand } = require("@aws-sdk/aws-restxml"); // CommonJS import + * const client = new RestXmlProtocolClient(config); + * const command = new BodyWithXmlNameCommand(input); + * const response = await client.send(command); + * ``` + * + * @see {@link BodyWithXmlNameCommandInput} for command's `input` shape. + * @see {@link BodyWithXmlNameCommandOutput} for command's `response` shape. + * @see {@link RestXmlProtocolClientResolvedConfig | config} for command's `input` shape. + * + */ +export class BodyWithXmlNameCommand extends $Command< + BodyWithXmlNameCommandInput, + BodyWithXmlNameCommandOutput, + RestXmlProtocolClientResolvedConfig +> { + // Start section: command_properties + // End section: command_properties + + constructor(readonly input: BodyWithXmlNameCommandInput) { + // Start section: command_constructor + super(); + // End section: command_constructor + } + + /** + * @internal + */ + resolveMiddleware( + clientStack: MiddlewareStack, + configuration: RestXmlProtocolClientResolvedConfig, + options?: __HttpHandlerOptions + ): Handler { + this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize)); + + const stack = clientStack.concat(this.middlewareStack); + + const { logger } = configuration; + const clientName = "RestXmlProtocolClient"; + const commandName = "BodyWithXmlNameCommand"; + const handlerExecutionContext: HandlerExecutionContext = { + logger, + clientName, + commandName, + inputFilterSensitiveLog: BodyWithXmlNameInputOutput.filterSensitiveLog, + outputFilterSensitiveLog: BodyWithXmlNameInputOutput.filterSensitiveLog, + }; + const { requestHandler } = configuration; + return stack.resolve( + (request: FinalizeHandlerArguments) => + requestHandler.handle(request.request as __HttpRequest, options || {}), + handlerExecutionContext + ); + } + + private serialize(input: BodyWithXmlNameCommandInput, context: __SerdeContext): Promise<__HttpRequest> { + return serializeAws_restXmlBodyWithXmlNameCommand(input, context); + } + + private deserialize(output: __HttpResponse, context: __SerdeContext): Promise { + return deserializeAws_restXmlBodyWithXmlNameCommand(output, context); + } + + // Start section: command_body_extra + // End section: command_body_extra +} diff --git a/protocol_tests/aws-restxml/commands/XmlListsCommand.ts b/protocol_tests/aws-restxml/commands/XmlListsCommand.ts index f31173bcfe22a..60b95c8ca64fe 100644 --- a/protocol_tests/aws-restxml/commands/XmlListsCommand.ts +++ b/protocol_tests/aws-restxml/commands/XmlListsCommand.ts @@ -29,6 +29,7 @@ export interface XmlListsCommandOutput extends XmlListsInputOutput, __MetadataBe * 6. Flattened XML lists with @xmlName. * 7. Flattened XML lists with @xmlNamespace. * 8. Lists of structures. + * 9. Flattened XML list of structures * @example * Use a bare-bones client and the command you need to make an API call. * ```javascript diff --git a/protocol_tests/aws-restxml/index.ts b/protocol_tests/aws-restxml/index.ts index eaab71f793582..74f3b499e98c0 100644 --- a/protocol_tests/aws-restxml/index.ts +++ b/protocol_tests/aws-restxml/index.ts @@ -1,6 +1,7 @@ export * from "./RestXmlProtocolClient"; export * from "./RestXmlProtocol"; export * from "./commands/AllQueryStringTypesCommand"; +export * from "./commands/BodyWithXmlNameCommand"; export * from "./commands/ConstantAndVariableQueryStringCommand"; export * from "./commands/ConstantQueryStringCommand"; export * from "./commands/EmptyInputAndEmptyOutputCommand"; diff --git a/protocol_tests/aws-restxml/models/models_0.ts b/protocol_tests/aws-restxml/models/models_0.ts index 50ad9d77562b0..d2ea4656f32c7 100644 --- a/protocol_tests/aws-restxml/models/models_0.ts +++ b/protocol_tests/aws-restxml/models/models_0.ts @@ -40,6 +40,32 @@ export namespace AllQueryStringTypesInput { }); } +export interface PayloadWithXmlName { + name?: string; +} + +export namespace PayloadWithXmlName { + /** + * @internal + */ + export const filterSensitiveLog = (obj: PayloadWithXmlName): any => ({ + ...obj, + }); +} + +export interface BodyWithXmlNameInputOutput { + nested?: PayloadWithXmlName; +} + +export namespace BodyWithXmlNameInputOutput { + /** + * @internal + */ + export const filterSensitiveLog = (obj: BodyWithXmlNameInputOutput): any => ({ + ...obj, + }); +} + export interface ComplexNestedErrorData { Foo?: string; } @@ -246,19 +272,6 @@ export namespace HttpPayloadTraitsWithMediaTypeInputOutput { }); } -export interface PayloadWithXmlName { - name?: string; -} - -export namespace PayloadWithXmlName { - /** - * @internal - */ - export const filterSensitiveLog = (obj: PayloadWithXmlName): any => ({ - ...obj, - }); -} - export interface HttpPayloadWithMemberXmlNameInputOutput { nested?: PayloadWithXmlName; } @@ -700,6 +713,7 @@ export interface XmlListsInputOutput { flattenedListWithMemberNamespace?: string[]; flattenedListWithNamespace?: string[]; structureList?: StructureListMember[]; + flattenedStructureList?: StructureListMember[]; } export namespace XmlListsInputOutput { diff --git a/protocol_tests/aws-restxml/protocols/Aws_restXml.ts b/protocol_tests/aws-restxml/protocols/Aws_restXml.ts index d4d9587c3a09b..9004ba9bdc208 100644 --- a/protocol_tests/aws-restxml/protocols/Aws_restXml.ts +++ b/protocol_tests/aws-restxml/protocols/Aws_restXml.ts @@ -2,6 +2,7 @@ import { AllQueryStringTypesCommandInput, AllQueryStringTypesCommandOutput, } from "../commands/AllQueryStringTypesCommand"; +import { BodyWithXmlNameCommandInput, BodyWithXmlNameCommandOutput } from "../commands/BodyWithXmlNameCommand"; import { ConstantAndVariableQueryStringCommandInput, ConstantAndVariableQueryStringCommandOutput, @@ -232,6 +233,34 @@ export const serializeAws_restXmlAllQueryStringTypesCommand = async ( }); }; +export const serializeAws_restXmlBodyWithXmlNameCommand = async ( + input: BodyWithXmlNameCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const headers: any = { + "content-type": "application/xml", + }; + let resolvedPath = "/BodyWithXmlName"; + let body: any; + body = ''; + const bodyNode = new __XmlNode("BodyWithXmlNameInputOutput"); + if (input.nested !== undefined) { + const node = serializeAws_restXmlPayloadWithXmlName(input.nested, context).withName("nested"); + bodyNode.addChildNode(node); + } + body += bodyNode.toString(); + const { hostname, protocol = "https", port } = await context.endpoint(); + return new __HttpRequest({ + protocol, + hostname, + port, + method: "PUT", + headers, + path: resolvedPath, + body, + }); +}; + export const serializeAws_restXmlConstantAndVariableQueryStringCommand = async ( input: ConstantAndVariableQueryStringCommandInput, context: __SerdeContext @@ -1568,6 +1597,13 @@ export const serializeAws_restXmlXmlEmptyListsCommand = async ( bodyNode.addChildNode(node); }); } + if (input.flattenedStructureList !== undefined) { + const nodes = serializeAws_restXmlStructureList(input.flattenedStructureList, context); + nodes.map((node: any) => { + node = node.withName("flattenedStructureList"); + bodyNode.addChildNode(node); + }); + } if (input.integerList !== undefined) { const nodes = serializeAws_restXmlIntegerList(input.integerList, context); const containerNode = new __XmlNode("integerList"); @@ -1812,6 +1848,13 @@ export const serializeAws_restXmlXmlListsCommand = async ( bodyNode.addChildNode(node); }); } + if (input.flattenedStructureList !== undefined) { + const nodes = serializeAws_restXmlStructureList(input.flattenedStructureList, context); + nodes.map((node: any) => { + node = node.withName("flattenedStructureList"); + bodyNode.addChildNode(node); + }); + } if (input.integerList !== undefined) { const nodes = serializeAws_restXmlIntegerList(input.integerList, context); const containerNode = new __XmlNode("integerList"); @@ -2093,6 +2136,53 @@ const deserializeAws_restXmlAllQueryStringTypesCommandError = async ( return Promise.reject(Object.assign(new Error(message), response)); }; +export const deserializeAws_restXmlBodyWithXmlNameCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + if (output.statusCode !== 200 && output.statusCode >= 300) { + return deserializeAws_restXmlBodyWithXmlNameCommandError(output, context); + } + const contents: BodyWithXmlNameCommandOutput = { + $metadata: deserializeMetadata(output), + nested: undefined, + }; + const data: any = await parseBody(output.body, context); + if (data["nested"] !== undefined) { + contents.nested = deserializeAws_restXmlPayloadWithXmlName(data["nested"], context); + } + return Promise.resolve(contents); +}; + +const deserializeAws_restXmlBodyWithXmlNameCommandError = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + const parsedOutput: any = { + ...output, + body: await parseBody(output.body, context), + }; + let response: __SmithyException & __MetadataBearer & { [key: string]: any }; + let errorCode: string = "UnknownError"; + errorCode = loadRestXmlErrorCode(output, parsedOutput.body); + switch (errorCode) { + default: + const parsedBody = parsedOutput.body; + errorCode = parsedBody.Error.code || parsedBody.Error.Code || errorCode; + response = { + ...parsedBody.Error, + name: `${errorCode}`, + message: parsedBody.Error.message || parsedBody.Error.Message || errorCode, + $fault: "client", + $metadata: deserializeMetadata(output), + } as any; + } + const message = response.message || response.Message || errorCode; + response.message = message; + delete response.Message; + return Promise.reject(Object.assign(new Error(message), response)); +}; + export const deserializeAws_restXmlConstantAndVariableQueryStringCommand = async ( output: __HttpResponse, context: __SerdeContext @@ -4116,6 +4206,7 @@ export const deserializeAws_restXmlXmlEmptyListsCommand = async ( flattenedList2: undefined, flattenedListWithMemberNamespace: undefined, flattenedListWithNamespace: undefined, + flattenedStructureList: undefined, integerList: undefined, nestedStringList: undefined, renamedListMembers: undefined, @@ -4176,6 +4267,15 @@ export const deserializeAws_restXmlXmlEmptyListsCommand = async ( context ); } + if (data.flattenedStructureList === "") { + contents.flattenedStructureList = []; + } + if (data["flattenedStructureList"] !== undefined) { + contents.flattenedStructureList = deserializeAws_restXmlStructureList( + __getArrayIfSingleItem(data["flattenedStructureList"]), + context + ); + } if (data.integerList === "") { contents.integerList = []; } @@ -4468,6 +4568,7 @@ export const deserializeAws_restXmlXmlListsCommand = async ( flattenedList2: undefined, flattenedListWithMemberNamespace: undefined, flattenedListWithNamespace: undefined, + flattenedStructureList: undefined, integerList: undefined, nestedStringList: undefined, renamedListMembers: undefined, @@ -4528,6 +4629,15 @@ export const deserializeAws_restXmlXmlListsCommand = async ( context ); } + if (data.flattenedStructureList === "") { + contents.flattenedStructureList = []; + } + if (data["flattenedStructureList"] !== undefined) { + contents.flattenedStructureList = deserializeAws_restXmlStructureList( + __getArrayIfSingleItem(data["flattenedStructureList"]), + context + ); + } if (data.integerList === "") { contents.integerList = []; } diff --git a/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts b/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts index 3f5567c4bd723..34a794d8ab968 100644 --- a/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts +++ b/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts @@ -1,5 +1,6 @@ import { RestXmlProtocolClient } from "../../RestXmlProtocolClient"; import { AllQueryStringTypesCommand } from "../../commands/AllQueryStringTypesCommand"; +import { BodyWithXmlNameCommand } from "../../commands/BodyWithXmlNameCommand"; import { ConstantAndVariableQueryStringCommand } from "../../commands/ConstantAndVariableQueryStringCommand"; import { ConstantQueryStringCommand } from "../../commands/ConstantQueryStringCommand"; import { EmptyInputAndEmptyOutputCommand } from "../../commands/EmptyInputAndEmptyOutputCommand"; @@ -320,6 +321,85 @@ it("RestXmlQueryStringMap:Request", async () => { } }); +/** + * Serializes a payload using a wrapper name based on the xmlName + */ +it("BodyWithXmlName:Request", async () => { + const client = new RestXmlProtocolClient({ + ...clientParams, + requestHandler: new RequestSerializationTestHandler(), + }); + + const command = new BodyWithXmlNameCommand({ + nested: { + name: "Phreddy", + } 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("PUT"); + expect(r.path).toBe("/BodyWithXmlName"); + expect(r.headers["content-length"]).toBeDefined(); + + expect(r.headers["content-type"]).toBeDefined(); + expect(r.headers["content-type"]).toBe("application/xml"); + + expect(r.body).toBeDefined(); + const utf8Encoder = client.config.utf8Encoder; + const bodyString = `Phreddy`; + const unequalParts: any = compareEquivalentXmlBodies(bodyString, r.body.toString()); + expect(unequalParts).toBeUndefined(); + } +}); + +/** + * Serializes a payload using a wrapper name based on the xmlName + */ +it("BodyWithXmlName:Response", async () => { + const client = new RestXmlProtocolClient({ + ...clientParams, + requestHandler: new ResponseDeserializationTestHandler( + true, + 200, + { + "content-type": "application/xml", + }, + `Phreddy` + ), + }); + + const params: any = {}; + const command = new BodyWithXmlNameCommand(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 = [ + { + nested: { + name: "Phreddy", + }, + }, + ][0]; + Object.keys(paramsToValidate).forEach((param) => { + expect(r[param]).toBeDefined(); + expect(equivalentContents(r[param], paramsToValidate[param])).toBe(true); + }); +}); + /** * Mixes constant and variable query string parameters */ @@ -4447,6 +4527,20 @@ it("XmlLists:Request", async () => { b: "4", } as any, ], + + flattenedStructureList: [ + { + a: "5", + + b: "6", + } as any, + + { + a: "7", + + b: "8", + } as any, + ], } as any); try { await client.send(command); @@ -4519,6 +4613,14 @@ it("XmlLists:Request", async () => { 4 + + 5 + 6 + + + 7 + 8 + `; const unequalParts: any = compareEquivalentXmlBodies(bodyString, r.body.toString()); @@ -4595,6 +4697,14 @@ it("XmlLists:Response", async () => { 4 + + 5 + 6 + + + 7 + 8 + ` ), @@ -4654,6 +4764,20 @@ it("XmlLists:Response", async () => { b: "4", }, ], + + flattenedStructureList: [ + { + a: "5", + + b: "6", + }, + + { + a: "7", + + b: "8", + }, + ], }, ][0]; Object.keys(paramsToValidate).forEach((param) => { From 1cdbade066f12f6a02b444bfdc65c9fc03a3cbcc Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 10 May 2021 21:12:18 +0000 Subject: [PATCH 2/5] fix(codegen): read xmlTrait from inputShape while naming wrapper --- .../smithy/aws/typescript/codegen/AwsRestXml.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java index 9807e18609542..011b024f4f43b 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java @@ -31,6 +31,7 @@ import software.amazon.smithy.model.shapes.UnionShape; import software.amazon.smithy.model.traits.StreamingTrait; import software.amazon.smithy.model.traits.TimestampFormatTrait.Format; +import software.amazon.smithy.model.traits.XmlNameTrait; import software.amazon.smithy.typescript.codegen.TypeScriptWriter; import software.amazon.smithy.typescript.codegen.integration.HttpBindingProtocolGenerator; import software.amazon.smithy.utils.SmithyInternalApi; @@ -164,13 +165,18 @@ protected void serializeInputDocument( writer.write("body = \"\";"); writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder"); - writer.write("const bodyNode = new __XmlNode($S);", inputShapeId.getName(serviceShape)); + + // Handle the @xmlName trait for the input shape. + StructureShape inputShape = context.getModel().expectShape(inputShapeId, StructureShape.class); + String nodeName = inputShape.getTrait(XmlNameTrait.class) + .map(XmlNameTrait::getValue) + .orElse(inputShapeId.getName(serviceShape)); + writer.write("const bodyNode = new __XmlNode($S);", nodeName); // Add @xmlNamespace value of the service to the root node, // fall back to one from the input shape. boolean serviceXmlns = AwsProtocolUtils.writeXmlNamespace(context, serviceShape, "bodyNode"); if (!serviceXmlns) { - StructureShape inputShape = context.getModel().expectShape(inputShapeId, StructureShape.class); AwsProtocolUtils.writeXmlNamespace(context, inputShape, "bodyNode"); } From efdb59055668eb1fb87c94b8d90efa30fa9a5d9d Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 10 May 2021 21:56:05 +0000 Subject: [PATCH 3/5] fix(aws-restxml): use xmlTrait from inputShape while naming wrapper --- protocol_tests/aws-restxml/protocols/Aws_restXml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol_tests/aws-restxml/protocols/Aws_restXml.ts b/protocol_tests/aws-restxml/protocols/Aws_restXml.ts index 9004ba9bdc208..e33fd948b4ad5 100644 --- a/protocol_tests/aws-restxml/protocols/Aws_restXml.ts +++ b/protocol_tests/aws-restxml/protocols/Aws_restXml.ts @@ -243,7 +243,7 @@ export const serializeAws_restXmlBodyWithXmlNameCommand = async ( let resolvedPath = "/BodyWithXmlName"; let body: any; body = ''; - const bodyNode = new __XmlNode("BodyWithXmlNameInputOutput"); + const bodyNode = new __XmlNode("Ahoy"); if (input.nested !== undefined) { const node = serializeAws_restXmlPayloadWithXmlName(input.nested, context).withName("nested"); bodyNode.addChildNode(node); From 341882982cd7864d59895ef8918df3226e005e0f Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 11 May 2021 16:55:54 +0000 Subject: [PATCH 4/5] fix(aws-restxml): pick up fix from smithy 1.7.2 Refs: https://github.com/awslabs/smithy/pull/795 --- protocol_tests/aws-restxml/tests/functional/restxml.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts b/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts index 34a794d8ab968..3860234e0e7b4 100644 --- a/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts +++ b/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts @@ -354,7 +354,7 @@ it("BodyWithXmlName:Request", async () => { expect(r.body).toBeDefined(); const utf8Encoder = client.config.utf8Encoder; - const bodyString = `Phreddy`; + const bodyString = `Phreddy`; const unequalParts: any = compareEquivalentXmlBodies(bodyString, r.body.toString()); expect(unequalParts).toBeUndefined(); } @@ -372,7 +372,7 @@ it("BodyWithXmlName:Response", async () => { { "content-type": "application/xml", }, - `Phreddy` + `Phreddy` ), }); From 2b6fcba2afed91ed41c143038f16127bd3facb74 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 11 May 2021 17:44:20 +0000 Subject: [PATCH 5/5] fix(codegen): checkstyle error in AwsRestXml.java --- .../amazon/smithy/aws/typescript/codegen/AwsRestXml.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java index 011b024f4f43b..a6111f3c2f3de 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java @@ -165,7 +165,7 @@ protected void serializeInputDocument( writer.write("body = \"\";"); writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder"); - + // Handle the @xmlName trait for the input shape. StructureShape inputShape = context.getModel().expectShape(inputShapeId, StructureShape.class); String nodeName = inputShape.getTrait(XmlNameTrait.class)