Skip to content

Commit a90bc87

Browse files
authored
chore(protocol_tests): add tests from smithy 1.7.2 release (#2374)
1 parent 9a0c2b7 commit a90bc87

File tree

9 files changed

+408
-15
lines changed

9 files changed

+408
-15
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import software.amazon.smithy.model.shapes.UnionShape;
3232
import software.amazon.smithy.model.traits.StreamingTrait;
3333
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
34+
import software.amazon.smithy.model.traits.XmlNameTrait;
3435
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
3536
import software.amazon.smithy.typescript.codegen.integration.HttpBindingProtocolGenerator;
3637
import software.amazon.smithy.utils.SmithyInternalApi;
@@ -164,13 +165,18 @@ protected void serializeInputDocument(
164165
writer.write("body = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\";");
165166

166167
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");
167-
writer.write("const bodyNode = new __XmlNode($S);", inputShapeId.getName(serviceShape));
168+
169+
// Handle the @xmlName trait for the input shape.
170+
StructureShape inputShape = context.getModel().expectShape(inputShapeId, StructureShape.class);
171+
String nodeName = inputShape.getTrait(XmlNameTrait.class)
172+
.map(XmlNameTrait::getValue)
173+
.orElse(inputShapeId.getName(serviceShape));
174+
writer.write("const bodyNode = new __XmlNode($S);", nodeName);
168175

169176
// Add @xmlNamespace value of the service to the root node,
170177
// fall back to one from the input shape.
171178
boolean serviceXmlns = AwsProtocolUtils.writeXmlNamespace(context, serviceShape, "bodyNode");
172179
if (!serviceXmlns) {
173-
StructureShape inputShape = context.getModel().expectShape(inputShapeId, StructureShape.class);
174180
AwsProtocolUtils.writeXmlNamespace(context, inputShape, "bodyNode");
175181
}
176182

protocol_tests/aws-restxml/RestXmlProtocol.ts

+39
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import {
44
AllQueryStringTypesCommandInput,
55
AllQueryStringTypesCommandOutput,
66
} from "./commands/AllQueryStringTypesCommand";
7+
import {
8+
BodyWithXmlNameCommand,
9+
BodyWithXmlNameCommandInput,
10+
BodyWithXmlNameCommandOutput,
11+
} from "./commands/BodyWithXmlNameCommand";
712
import {
813
ConstantAndVariableQueryStringCommand,
914
ConstantAndVariableQueryStringCommandInput,
@@ -272,6 +277,39 @@ export class RestXmlProtocol extends RestXmlProtocolClient {
272277
}
273278
}
274279

280+
/**
281+
* The following example serializes a body that uses an XML name,
282+
* changing the wrapper name.
283+
*/
284+
public bodyWithXmlName(
285+
args: BodyWithXmlNameCommandInput,
286+
options?: __HttpHandlerOptions
287+
): Promise<BodyWithXmlNameCommandOutput>;
288+
public bodyWithXmlName(
289+
args: BodyWithXmlNameCommandInput,
290+
cb: (err: any, data?: BodyWithXmlNameCommandOutput) => void
291+
): void;
292+
public bodyWithXmlName(
293+
args: BodyWithXmlNameCommandInput,
294+
options: __HttpHandlerOptions,
295+
cb: (err: any, data?: BodyWithXmlNameCommandOutput) => void
296+
): void;
297+
public bodyWithXmlName(
298+
args: BodyWithXmlNameCommandInput,
299+
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: BodyWithXmlNameCommandOutput) => void),
300+
cb?: (err: any, data?: BodyWithXmlNameCommandOutput) => void
301+
): Promise<BodyWithXmlNameCommandOutput> | void {
302+
const command = new BodyWithXmlNameCommand(args);
303+
if (typeof optionsOrCb === "function") {
304+
this.send(command, optionsOrCb);
305+
} else if (typeof cb === "function") {
306+
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
307+
this.send(command, optionsOrCb || {}, cb);
308+
} else {
309+
return this.send(command, optionsOrCb);
310+
}
311+
}
312+
275313
/**
276314
* This example uses fixed query string params and variable query string params.
277315
* The fixed query string parameters and variable parameters must both be
@@ -1678,6 +1716,7 @@ export class RestXmlProtocol extends RestXmlProtocolClient {
16781716
* 6. Flattened XML lists with @xmlName.
16791717
* 7. Flattened XML lists with @xmlNamespace.
16801718
* 8. Lists of structures.
1719+
* 9. Flattened XML list of structures
16811720
*/
16821721
public xmlLists(args: XmlListsCommandInput, options?: __HttpHandlerOptions): Promise<XmlListsCommandOutput>;
16831722
public xmlLists(args: XmlListsCommandInput, cb: (err: any, data?: XmlListsCommandOutput) => void): void;

protocol_tests/aws-restxml/RestXmlProtocolClient.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AllQueryStringTypesCommandInput,
33
AllQueryStringTypesCommandOutput,
44
} from "./commands/AllQueryStringTypesCommand";
5+
import { BodyWithXmlNameCommandInput, BodyWithXmlNameCommandOutput } from "./commands/BodyWithXmlNameCommand";
56
import {
67
ConstantAndVariableQueryStringCommandInput,
78
ConstantAndVariableQueryStringCommandOutput,
@@ -176,6 +177,7 @@ import {
176177

177178
export type ServiceInputTypes =
178179
| AllQueryStringTypesCommandInput
180+
| BodyWithXmlNameCommandInput
179181
| ConstantAndVariableQueryStringCommandInput
180182
| ConstantQueryStringCommandInput
181183
| EmptyInputAndEmptyOutputCommandInput
@@ -229,6 +231,7 @@ export type ServiceInputTypes =
229231

230232
export type ServiceOutputTypes =
231233
| AllQueryStringTypesCommandOutput
234+
| BodyWithXmlNameCommandOutput
232235
| ConstantAndVariableQueryStringCommandOutput
233236
| ConstantQueryStringCommandOutput
234237
| EmptyInputAndEmptyOutputCommandOutput
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { RestXmlProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../RestXmlProtocolClient";
2+
import { BodyWithXmlNameInputOutput } from "../models/models_0";
3+
import {
4+
deserializeAws_restXmlBodyWithXmlNameCommand,
5+
serializeAws_restXmlBodyWithXmlNameCommand,
6+
} from "../protocols/Aws_restXml";
7+
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
8+
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
9+
import { Command as $Command } from "@aws-sdk/smithy-client";
10+
import {
11+
FinalizeHandlerArguments,
12+
Handler,
13+
HandlerExecutionContext,
14+
MiddlewareStack,
15+
HttpHandlerOptions as __HttpHandlerOptions,
16+
MetadataBearer as __MetadataBearer,
17+
SerdeContext as __SerdeContext,
18+
} from "@aws-sdk/types";
19+
20+
export interface BodyWithXmlNameCommandInput extends BodyWithXmlNameInputOutput {}
21+
export interface BodyWithXmlNameCommandOutput extends BodyWithXmlNameInputOutput, __MetadataBearer {}
22+
23+
/**
24+
* The following example serializes a body that uses an XML name,
25+
* changing the wrapper name.
26+
* @example
27+
* Use a bare-bones client and the command you need to make an API call.
28+
* ```javascript
29+
* import { RestXmlProtocolClient, BodyWithXmlNameCommand } from "@aws-sdk/aws-restxml"; // ES Modules import
30+
* // const { RestXmlProtocolClient, BodyWithXmlNameCommand } = require("@aws-sdk/aws-restxml"); // CommonJS import
31+
* const client = new RestXmlProtocolClient(config);
32+
* const command = new BodyWithXmlNameCommand(input);
33+
* const response = await client.send(command);
34+
* ```
35+
*
36+
* @see {@link BodyWithXmlNameCommandInput} for command's `input` shape.
37+
* @see {@link BodyWithXmlNameCommandOutput} for command's `response` shape.
38+
* @see {@link RestXmlProtocolClientResolvedConfig | config} for command's `input` shape.
39+
*
40+
*/
41+
export class BodyWithXmlNameCommand extends $Command<
42+
BodyWithXmlNameCommandInput,
43+
BodyWithXmlNameCommandOutput,
44+
RestXmlProtocolClientResolvedConfig
45+
> {
46+
// Start section: command_properties
47+
// End section: command_properties
48+
49+
constructor(readonly input: BodyWithXmlNameCommandInput) {
50+
// Start section: command_constructor
51+
super();
52+
// End section: command_constructor
53+
}
54+
55+
/**
56+
* @internal
57+
*/
58+
resolveMiddleware(
59+
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
60+
configuration: RestXmlProtocolClientResolvedConfig,
61+
options?: __HttpHandlerOptions
62+
): Handler<BodyWithXmlNameCommandInput, BodyWithXmlNameCommandOutput> {
63+
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
64+
65+
const stack = clientStack.concat(this.middlewareStack);
66+
67+
const { logger } = configuration;
68+
const clientName = "RestXmlProtocolClient";
69+
const commandName = "BodyWithXmlNameCommand";
70+
const handlerExecutionContext: HandlerExecutionContext = {
71+
logger,
72+
clientName,
73+
commandName,
74+
inputFilterSensitiveLog: BodyWithXmlNameInputOutput.filterSensitiveLog,
75+
outputFilterSensitiveLog: BodyWithXmlNameInputOutput.filterSensitiveLog,
76+
};
77+
const { requestHandler } = configuration;
78+
return stack.resolve(
79+
(request: FinalizeHandlerArguments<any>) =>
80+
requestHandler.handle(request.request as __HttpRequest, options || {}),
81+
handlerExecutionContext
82+
);
83+
}
84+
85+
private serialize(input: BodyWithXmlNameCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
86+
return serializeAws_restXmlBodyWithXmlNameCommand(input, context);
87+
}
88+
89+
private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<BodyWithXmlNameCommandOutput> {
90+
return deserializeAws_restXmlBodyWithXmlNameCommand(output, context);
91+
}
92+
93+
// Start section: command_body_extra
94+
// End section: command_body_extra
95+
}

protocol_tests/aws-restxml/commands/XmlListsCommand.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface XmlListsCommandOutput extends XmlListsInputOutput, __MetadataBe
2929
* 6. Flattened XML lists with @xmlName.
3030
* 7. Flattened XML lists with @xmlNamespace.
3131
* 8. Lists of structures.
32+
* 9. Flattened XML list of structures
3233
* @example
3334
* Use a bare-bones client and the command you need to make an API call.
3435
* ```javascript

protocol_tests/aws-restxml/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from "./RestXmlProtocolClient";
22
export * from "./RestXmlProtocol";
33
export * from "./commands/AllQueryStringTypesCommand";
4+
export * from "./commands/BodyWithXmlNameCommand";
45
export * from "./commands/ConstantAndVariableQueryStringCommand";
56
export * from "./commands/ConstantQueryStringCommand";
67
export * from "./commands/EmptyInputAndEmptyOutputCommand";

protocol_tests/aws-restxml/models/models_0.ts

+27-13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ export namespace AllQueryStringTypesInput {
4040
});
4141
}
4242

43+
export interface PayloadWithXmlName {
44+
name?: string;
45+
}
46+
47+
export namespace PayloadWithXmlName {
48+
/**
49+
* @internal
50+
*/
51+
export const filterSensitiveLog = (obj: PayloadWithXmlName): any => ({
52+
...obj,
53+
});
54+
}
55+
56+
export interface BodyWithXmlNameInputOutput {
57+
nested?: PayloadWithXmlName;
58+
}
59+
60+
export namespace BodyWithXmlNameInputOutput {
61+
/**
62+
* @internal
63+
*/
64+
export const filterSensitiveLog = (obj: BodyWithXmlNameInputOutput): any => ({
65+
...obj,
66+
});
67+
}
68+
4369
export interface ComplexNestedErrorData {
4470
Foo?: string;
4571
}
@@ -246,19 +272,6 @@ export namespace HttpPayloadTraitsWithMediaTypeInputOutput {
246272
});
247273
}
248274

249-
export interface PayloadWithXmlName {
250-
name?: string;
251-
}
252-
253-
export namespace PayloadWithXmlName {
254-
/**
255-
* @internal
256-
*/
257-
export const filterSensitiveLog = (obj: PayloadWithXmlName): any => ({
258-
...obj,
259-
});
260-
}
261-
262275
export interface HttpPayloadWithMemberXmlNameInputOutput {
263276
nested?: PayloadWithXmlName;
264277
}
@@ -700,6 +713,7 @@ export interface XmlListsInputOutput {
700713
flattenedListWithMemberNamespace?: string[];
701714
flattenedListWithNamespace?: string[];
702715
structureList?: StructureListMember[];
716+
flattenedStructureList?: StructureListMember[];
703717
}
704718

705719
export namespace XmlListsInputOutput {

0 commit comments

Comments
 (0)