Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(protocol_tests): add tests from smithy 1.7.2 release #2374

Merged
merged 5 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,13 +165,18 @@ protected void serializeInputDocument(
writer.write("body = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\";");

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");
}

Expand Down
39 changes: 39 additions & 0 deletions protocol_tests/aws-restxml/RestXmlProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import {
AllQueryStringTypesCommandInput,
AllQueryStringTypesCommandOutput,
} from "./commands/AllQueryStringTypesCommand";
import {
BodyWithXmlNameCommand,
BodyWithXmlNameCommandInput,
BodyWithXmlNameCommandOutput,
} from "./commands/BodyWithXmlNameCommand";
import {
ConstantAndVariableQueryStringCommand,
ConstantAndVariableQueryStringCommandInput,
Expand Down Expand Up @@ -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<BodyWithXmlNameCommandOutput>;
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<BodyWithXmlNameCommandOutput> | 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
Expand Down Expand Up @@ -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<XmlListsCommandOutput>;
public xmlLists(args: XmlListsCommandInput, cb: (err: any, data?: XmlListsCommandOutput) => void): void;
Expand Down
3 changes: 3 additions & 0 deletions protocol_tests/aws-restxml/RestXmlProtocolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AllQueryStringTypesCommandInput,
AllQueryStringTypesCommandOutput,
} from "./commands/AllQueryStringTypesCommand";
import { BodyWithXmlNameCommandInput, BodyWithXmlNameCommandOutput } from "./commands/BodyWithXmlNameCommand";
import {
ConstantAndVariableQueryStringCommandInput,
ConstantAndVariableQueryStringCommandOutput,
Expand Down Expand Up @@ -176,6 +177,7 @@ import {

export type ServiceInputTypes =
| AllQueryStringTypesCommandInput
| BodyWithXmlNameCommandInput
| ConstantAndVariableQueryStringCommandInput
| ConstantQueryStringCommandInput
| EmptyInputAndEmptyOutputCommandInput
Expand Down Expand Up @@ -229,6 +231,7 @@ export type ServiceInputTypes =

export type ServiceOutputTypes =
| AllQueryStringTypesCommandOutput
| BodyWithXmlNameCommandOutput
| ConstantAndVariableQueryStringCommandOutput
| ConstantQueryStringCommandOutput
| EmptyInputAndEmptyOutputCommandOutput
Expand Down
95 changes: 95 additions & 0 deletions protocol_tests/aws-restxml/commands/BodyWithXmlNameCommand.ts
Original file line number Diff line number Diff line change
@@ -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<ServiceInputTypes, ServiceOutputTypes>,
configuration: RestXmlProtocolClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<BodyWithXmlNameCommandInput, BodyWithXmlNameCommandOutput> {
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<any>) =>
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<BodyWithXmlNameCommandOutput> {
return deserializeAws_restXmlBodyWithXmlNameCommand(output, context);
}

// Start section: command_body_extra
// End section: command_body_extra
}
1 change: 1 addition & 0 deletions protocol_tests/aws-restxml/commands/XmlListsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions protocol_tests/aws-restxml/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
40 changes: 27 additions & 13 deletions protocol_tests/aws-restxml/models/models_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -700,6 +713,7 @@ export interface XmlListsInputOutput {
flattenedListWithMemberNamespace?: string[];
flattenedListWithNamespace?: string[];
structureList?: StructureListMember[];
flattenedStructureList?: StructureListMember[];
}

export namespace XmlListsInputOutput {
Expand Down
Loading