Skip to content

Commit b3c4421

Browse files
committed
feat(codegen): send x-amzn-query-mode header
1 parent 17b37b7 commit b3c4421

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
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-error": "true",
20902091
};
20912092
}
20922093

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
package software.amazon.smithy.aws.typescript.codegen;
1717

1818
import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait;
19+
import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait;
20+
import software.amazon.smithy.model.shapes.ServiceShape;
1921
import software.amazon.smithy.model.shapes.ShapeId;
22+
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
23+
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
24+
import software.amazon.smithy.typescript.codegen.integration.HttpRpcProtocolGenerator;
2025
import software.amazon.smithy.utils.SmithyInternalApi;
2126

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

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

Lines changed: 19 additions & 0 deletions
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-error": "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

Lines changed: 5 additions & 0 deletions
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-error": "true",
150+
""");
151+
}
147152
}
148153
);
149154
}

0 commit comments

Comments
 (0)