Skip to content

Commit

Permalink
awsquerycompat
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Jun 19, 2024
1 parent e8dd17a commit 72bca8b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions smithy-typescript-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
api("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
api("software.amazon.smithy:smithy-rules-engine:$smithyVersion")
api("software.amazon.smithy:smithy-waiters:$smithyVersion")
api("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ private static boolean filterProtocolTests(
return true;
}

// TODO(cbor): verify the test is declared correctly.
// TODO(cbor): enable this test when upgrading to a Smithy version
// TODO(cbor): in which it is fixed.
if (testCase.getId().equals("RpcV2CborDeserializesDenseSetMapAndSkipsNull")) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.Set;
import java.util.TreeSet;
import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.codegen.core.SymbolReference;
Expand Down Expand Up @@ -137,6 +138,20 @@ public void generateSharedComponents(GenerationContext context) {
writeSharedRequestHeaders(context);
writer.write("");

if (context.getService().hasTrait(AwsQueryCompatibleTrait.class)) {
writer.addImport("HeaderBag", "__HeaderBag", TypeScriptDependency.SMITHY_TYPES);
writer.write("""
const populateBodyWithQueryCompatibility = (parsedOutput: any, headers: __HeaderBag) => {
const queryErrorHeader = headers["x-amzn-query-error"];
if (parsedOutput.body !== undefined && queryErrorHeader != null) {
const codeAndType = queryErrorHeader.split(";");
parsedOutput.body.Code = codeAndType[0];
parsedOutput.body.Type = codeAndType[1];
}
};
""");
}

writer.write(
context.getStringStore().flushVariableDeclarationCode()
);
Expand Down Expand Up @@ -269,9 +284,13 @@ protected void serializeInputDocument(GenerationContext generationContext,
protected void writeErrorCodeParser(GenerationContext generationContext) {
TypeScriptWriter writer = generationContext.getWriter();

// TODO(cbor) handle Query-Compatible
// TODO(cbor) either by accepting a function from downstream
// TODO(cbor) or natively here.
if (generationContext.getService().hasTrait(AwsQueryCompatibleTrait.class)) {
// Populate parsedOutput.body with 'Code' and 'Type' fields
// "x-amzn-query-error" header is available when AwsQueryCompatibleTrait is applied to a service
// The header value contains query error Code and Type joined by ';'
// E.g. "MalformedInput;Sender" or "InternalFailure;Receiver"
writer.write("populateBodyWithQueryCompatibility(parsedOutput, output.headers);");
}

writer.addSubPathImport(
"loadSmithyRpcV2CborErrorCode", null,
Expand Down

0 comments on commit 72bca8b

Please sign in to comment.