-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codegen): add Smithy RPCv2 CBOR protocol as an option
- Loading branch information
Showing
13 changed files
with
1,134 additions
and
2,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...degen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsSmithyRpcV2Cbor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptDependency; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.typescript.codegen.protocols.cbor.SmithyRpcV2Cbor; | ||
|
||
/** | ||
* Extension of the Smithy RPCv2 CBOR protocol generator, adding | ||
* AWSQuery compatibility. | ||
*/ | ||
public final class AwsSmithyRpcV2Cbor extends SmithyRpcV2Cbor { | ||
@Override | ||
public void generateSharedComponents(GenerationContext context) { | ||
super.generateSharedComponents(context); | ||
if (context.getService().hasTrait(AwsQueryCompatibleTrait.class)) { | ||
TypeScriptWriter writer = context.getWriter(); | ||
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]; | ||
} | ||
}; | ||
"""); | ||
} | ||
} | ||
|
||
@Override | ||
protected void writeErrorCodeParser(GenerationContext generationContext) { | ||
super.writeErrorCodeParser(generationContext); | ||
TypeScriptWriter writer = generationContext.getWriter(); | ||
|
||
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);"); | ||
} | ||
} | ||
} |
198 changes: 87 additions & 111 deletions
198
private/aws-protocoltests-ec2/test/functional/ec2query.spec.ts
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.