Skip to content

Commit 925e731

Browse files
authored
feat(codegen): send x-amzn-query-mode header (#6651)
1 parent 4e2f525 commit 925e731

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

clients/client-sqs/src/protocols/Aws_json1_0.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,7 @@ function sharedHeaders(operation: string): __HeaderBag {
20872087
return {
20882088
"content-type": "application/x-amz-json-1.0",
20892089
"x-amz-target": `AmazonSQS.${operation}`,
2090+
"x-amzn-query-mode": "true",
20902091
};
20912092
}
20922093

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

+21
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
package software.amazon.smithy.aws.typescript.codegen;
1717

1818
import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait;
19+
import software.amazon.smithy.model.shapes.ServiceShape;
1920
import software.amazon.smithy.model.shapes.ShapeId;
21+
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
22+
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
2023
import software.amazon.smithy.utils.SmithyInternalApi;
2124

2225
/**
@@ -43,4 +46,22 @@ public ShapeId getProtocol() {
4346
public String getName() {
4447
return "aws.json-1.1";
4548
}
49+
50+
/**
51+
* This override exists because the "x-amzn-query-error" header is only
52+
* sent in AwsJsonRpc1_0.
53+
*/
54+
@Override
55+
protected void writeSharedRequestHeaders(GenerationContext context) {
56+
ServiceShape serviceShape = context.getService();
57+
TypeScriptWriter writer = context.getWriter();
58+
writer.addImport("HeaderBag", "__HeaderBag", TypeScriptDependency.SMITHY_TYPES);
59+
String targetHeader = serviceShape.getId().getName(serviceShape) + ".${operation}";
60+
writer.openBlock("function sharedHeaders(operation: string): __HeaderBag { return {", "}};",
61+
() -> {
62+
writer.write("'content-type': $S,", getDocumentContentType());
63+
writer.write("'x-amz-target': `$L`,", targetHeader);
64+
}
65+
);
66+
}
4667
}

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

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait;
99
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
1010
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
11+
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator;
1112
import software.amazon.smithy.typescript.codegen.protocols.cbor.SmithyRpcV2Cbor;
1213

1314
/**
@@ -34,6 +35,24 @@ public void generateSharedComponents(GenerationContext context) {
3435
}
3536
}
3637

38+
@Override
39+
protected void writeSharedRequestHeaders(ProtocolGenerator.GenerationContext context) {
40+
TypeScriptWriter writer = context.getWriter();
41+
writer.addImport("HeaderBag", "__HeaderBag", TypeScriptDependency.SMITHY_TYPES);
42+
writer.openBlock("const SHARED_HEADERS: __HeaderBag = {", "};", () -> {
43+
writer.write("'content-type': $S,", getDocumentContentType());
44+
writer.write("""
45+
"smithy-protocol": "rpc-v2-cbor",
46+
"accept": "application/cbor",
47+
""");
48+
if (context.getService().hasTrait(AwsQueryCompatibleTrait.class)) {
49+
writer.write("""
50+
"x-amzn-query-mode": "true",
51+
""");
52+
}
53+
});
54+
}
55+
3756
@Override
3857
protected void writeErrorCodeParser(GenerationContext generationContext) {
3958
super.writeErrorCodeParser(generationContext);

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

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ protected void writeSharedRequestHeaders(GenerationContext context) {
144144
// AWS JSON RPC protocols use a combination of the service and operation shape names,
145145
// separated by a '.' character, for the target header.
146146
writer.write("'x-amz-target': `$L`,", targetHeader);
147+
if (serviceShape.hasTrait(AwsQueryCompatibleTrait.class)) {
148+
writer.write("""
149+
"x-amzn-query-mode": "true",
150+
""");
151+
}
147152
}
148153
);
149154
}

packages/middleware-sdk-sqs/src/middleware-sdk-sqs.integ.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { requireRequestsFrom } from "../../../private/aws-util-test/src";
99

1010
const sqsModel: any = require("../../../codegen/sdk-codegen/aws-models/sqs.json");
1111
const useAwsQuery = !!sqsModel.shapes["com.amazonaws.sqs#AmazonSQS"].traits["aws.protocols#awsQuery"];
12+
const isAwsQueryCompatible =
13+
!!sqsModel.shapes["com.amazonaws.sqs#AmazonSQS"].traits["aws.protocols#awsQueryCompatible"];
1214

1315
let hashError = "";
1416
const md5 = (str: string) =>
@@ -319,6 +321,28 @@ describe("middleware-sdk-sqs", () => {
319321
});
320322
});
321323

324+
it("should send the x-amzn-query-mode header when in awsQueryCompatible mode", async () => {
325+
const client = new SQS({
326+
region: "us-west-2",
327+
credentials: mockCredentials,
328+
logger,
329+
});
330+
331+
requireRequestsFrom(client).toMatch({
332+
hostname: "abc.com",
333+
protocol: "https:",
334+
path: "/",
335+
headers: {
336+
"x-amzn-query-mode": "true",
337+
},
338+
});
339+
340+
await client.sendMessage({
341+
QueueUrl: "https://abc.com/123/MyQueue",
342+
MessageBody: "hello",
343+
});
344+
});
345+
322346
describe("queue-url", () => {
323347
it("should override resolved endpoint by default", async () => {
324348
const client = new SQS({

0 commit comments

Comments
 (0)