Skip to content

Commit e22d9ef

Browse files
authored
chore(protocol_tests): updates for latest protocol tests (#1770)
1 parent 62a6f5c commit e22d9ef

File tree

77 files changed

+14294
-1526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+14294
-1526
lines changed

codegen/protocol-test-codegen/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import software.amazon.smithy.gradle.tasks.SmithyBuild
1717

1818
plugins {
19-
id("software.amazon.smithy") version "0.5.1"
19+
id("software.amazon.smithy") version "0.5.2"
2020
}
2121

2222
dependencies {
23-
implementation("software.amazon.smithy:smithy-aws-protocol-tests:1.0.5")
23+
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.5.0, 2.0[")
2424
compile(project(":smithy-aws-typescript-codegen"))
2525
}
2626

codegen/sdk-codegen/aws-models/groundstation.2019-05-23.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@
19201920
"cloudTrailEventSource": "REPLACE_WITH_EVENT_SOURCE"
19211921
},
19221922
"aws.auth#sigv4": {
1923-
"name": ""
1923+
"name": "groundstation"
19241924
},
19251925
"aws.protocols#restJson1": {},
19261926
"smithy.api#documentation": "<p>Welcome to the AWS Ground Station API Reference. AWS Ground Station is a fully managed service that\n enables you to control satellite communications, downlink and process satellite data, and\n scale your satellite operations efficiently and cost-effectively without having\n to build or manage your own ground station infrastructure.</p>",

codegen/sdk-codegen/aws-models/redshift-data.2019-12-20.json

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
{
22
"smithy": "1.0",
33
"shapes": {
4-
"aws.api#ArnNamespace": {
5-
"type": "string",
6-
"traits": {
7-
"smithy.api#pattern": "^[a-z0-9.\\-]{1,63}$",
8-
"smithy.api#private": {}
9-
}
10-
},
114
"com.amazonaws.redshiftdata#Blob": {
125
"type": "blob"
136
},
@@ -72,13 +65,6 @@
7265
}
7366
}
7467
},
75-
"aws.api#CloudFormationName": {
76-
"type": "string",
77-
"traits": {
78-
"smithy.api#pattern": "^[A-Z][A-Za-z0-9]+$",
79-
"smithy.api#private": {}
80-
}
81-
},
8268
"com.amazonaws.redshiftdata#ColumnList": {
8369
"type": "list",
8470
"member": {
@@ -1263,15 +1249,6 @@
12631249
"com.amazonaws.redshiftdata#String": {
12641250
"type": "string"
12651251
},
1266-
"aws.protocols#StringList": {
1267-
"type": "list",
1268-
"member": {
1269-
"target": "smithy.api#String"
1270-
},
1271-
"traits": {
1272-
"smithy.api#private": {}
1273-
}
1274-
},
12751252
"com.amazonaws.redshiftdata#TableList": {
12761253
"type": "list",
12771254
"member": {
@@ -1323,77 +1300,8 @@
13231300
"smithy.api#httpError": 400
13241301
}
13251302
},
1326-
"aws.protocols#awsJson1_1": {
1327-
"type": "structure",
1328-
"members": {
1329-
"http": {
1330-
"target": "aws.protocols#StringList"
1331-
},
1332-
"eventStreamHttp": {
1333-
"target": "aws.protocols#StringList"
1334-
}
1335-
},
1336-
"traits": {
1337-
"smithy.api#documentation": "An RPC-based protocol that sends JSON payloads. This protocol does not use HTTP binding traits.",
1338-
"smithy.api#protocolDefinition": {
1339-
"traits": ["smithy.api#jsonName"]
1340-
},
1341-
"smithy.api#trait": {
1342-
"selector": "service"
1343-
}
1344-
}
1345-
},
13461303
"com.amazonaws.redshiftdata#bool": {
13471304
"type": "boolean"
1348-
},
1349-
"aws.api#service": {
1350-
"type": "structure",
1351-
"members": {
1352-
"sdkId": {
1353-
"target": "smithy.api#String",
1354-
"traits": {
1355-
"smithy.api#required": {}
1356-
}
1357-
},
1358-
"arnNamespace": {
1359-
"target": "aws.api#ArnNamespace"
1360-
},
1361-
"cloudFormationName": {
1362-
"target": "aws.api#CloudFormationName"
1363-
},
1364-
"cloudTrailEventSource": {
1365-
"target": "smithy.api#String"
1366-
}
1367-
},
1368-
"traits": {
1369-
"smithy.api#trait": {
1370-
"selector": "service"
1371-
}
1372-
}
1373-
},
1374-
"aws.auth#sigv4": {
1375-
"type": "structure",
1376-
"members": {
1377-
"name": {
1378-
"target": "smithy.api#String",
1379-
"traits": {
1380-
"smithy.api#documentation": "The signature version 4 service signing name to use in the credential scope when signing requests. This value SHOULD match the `arnNamespace` property of the `aws.api#service-trait`.",
1381-
"smithy.api#externalDocumentation": {
1382-
"Reference": "https://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html"
1383-
},
1384-
"smithy.api#required": {}
1385-
}
1386-
}
1387-
},
1388-
"traits": {
1389-
"smithy.api#documentation": "Signature Version 4 is the process to add authentication information to AWS requests sent by HTTP. For security, most requests to AWS must be signed with an access key, which consists of an access key ID and secret access key. These two keys are commonly referred to as your security credentials.",
1390-
"smithy.api#externalDocumentation": {
1391-
"Reference": "https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html"
1392-
},
1393-
"smithy.api#trait": {
1394-
"selector": "service"
1395-
}
1396-
}
13971305
}
13981306
}
13991307
}

codegen/sdk-codegen/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import software.amazon.smithy.model.node.Node
1717
import software.amazon.smithy.gradle.tasks.SmithyBuild
1818

1919
plugins {
20-
id("software.amazon.smithy") version "0.5.1"
20+
id("software.amazon.smithy") version "0.5.2"
2121
}
2222

2323
dependencies {

codegen/smithy-aws-typescript-codegen/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ plugins {
2121
}
2222

2323
group = "software.amazon.smithy"
24-
version = "0.2.0"
24+
version = "0.3.0"
2525

2626
java {
2727
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -33,9 +33,9 @@ tasks.withType<Test> {
3333
}
3434

3535
dependencies {
36-
api("software.amazon.smithy:smithy-aws-traits:1.0.5")
37-
api("software.amazon.smithy:smithy-aws-iam-traits:1.0.5")
38-
api("software.amazon.smithy:smithy-typescript-codegen:0.2.0")
36+
api("software.amazon.smithy:smithy-aws-traits:[1.5.0, 2.0[")
37+
api("software.amazon.smithy:smithy-aws-iam-traits:[1.5.0, 2.0[")
38+
api("software.amazon.smithy:smithy-typescript-codegen:0.3.0")
3939
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.0")
4040
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.0")
4141
testCompile("org.junit.jupiter:junit-jupiter-params:5.4.0")

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
2525
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberSerVisitor;
2626
import software.amazon.smithy.typescript.codegen.integration.HttpRpcProtocolGenerator;
27+
import software.amazon.smithy.utils.IoUtils;
2728

2829
/**
2930
* Handles general components across the AWS JSON protocols that have do not have
@@ -73,6 +74,10 @@ public void generateSharedComponents(GenerationContext context) {
7374
super.generateSharedComponents(context);
7475
AwsProtocolUtils.generateJsonParseBody(context);
7576
AwsProtocolUtils.addItempotencyAutofillImport(context);
77+
78+
TypeScriptWriter writer = context.getWriter();
79+
writer.addUseImports(getApplicationProtocol().getResponseType());
80+
writer.write(IoUtils.readUtf8Resource(getClass(), "load-json-error-code-stub.ts"));
7681
}
7782

7883
@Override
@@ -105,9 +110,9 @@ private DocumentMemberSerVisitor getMemberSerVisitor(GenerationContext context,
105110
@Override
106111
protected void writeErrorCodeParser(GenerationContext context) {
107112
TypeScriptWriter writer = context.getWriter();
108-
// parsedOutput is in scope because HttpRpcProtocolGenerator.isErrorCodeInBody is true
109-
writer.write("const errorTypeParts: String = parsedOutput.body[\"__type\"].split('#');");
110-
writer.write("errorCode = (errorTypeParts[1] === undefined) ? errorTypeParts[0] : errorTypeParts[1];");
113+
114+
// Outsource error code parsing since it's complex for this protocol.
115+
writer.write("errorCode = loadRestJsonErrorCode(output, parsedOutput.body);");
111116
}
112117

113118
@Override

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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import software.amazon.smithy.model.shapes.StructureShape;
2828
import software.amazon.smithy.model.shapes.UnionShape;
2929
import software.amazon.smithy.model.traits.JsonNameTrait;
30+
import software.amazon.smithy.model.traits.SparseTrait;
3031
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
3132
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
3233
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
@@ -57,9 +58,18 @@ protected void deserializeCollection(GenerationContext context, CollectionShape
5758
TypeScriptWriter writer = context.getWriter();
5859
Shape target = context.getModel().expectShape(shape.getMember().getTarget());
5960

60-
// Dispatch to the output value provider for any additional handling.
61-
writer.openBlock("return (output || []).map((entry: any) =>", ");", () -> {
62-
writer.write(target.accept(getMemberVisitor("entry")));
61+
// Filter out null entries if we don't have the sparse trait.
62+
String potentialFilter = "";
63+
if (!shape.hasTrait(SparseTrait.ID)) {
64+
potentialFilter = ".filter((e: any) => e != null)";
65+
}
66+
67+
writer.openBlock("return (output || [])$L.map((entry: any) => {", "});", potentialFilter, () -> {
68+
// Short circuit null values from serialization.
69+
writer.write("if (entry === null) { return null as any; }");
70+
71+
// Dispatch to the output value provider for any additional handling.
72+
writer.write("return $L;", target.accept(getMemberVisitor("entry")));
6373
});
6474
}
6575

@@ -78,14 +88,27 @@ protected void deserializeMap(GenerationContext context, MapShape shape) {
7888

7989
// Get the right serialization for each entry in the map. Undefined
8090
// outputs won't have this deserializer invoked.
81-
writer.openBlock("return Object.entries(output).reduce((acc: $T, [key, value]: [$T, any]) => ({",
82-
"}), {});",
91+
writer.openBlock("return Object.entries(output).reduce((acc: $T, [key, value]: [$T, any]) => {",
92+
"}, {});",
8393
symbolProvider.toSymbol(shape),
8494
symbolProvider.toSymbol(shape.getKey()),
8595
() -> {
86-
writer.write("...acc,");
87-
// Dispatch to the output value provider for any additional handling.
88-
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
96+
writer.openBlock("if (value === null) {", "}", () -> {
97+
// Handle the sparse trait by short circuiting null values
98+
// from deserialization, and not including them if encountered
99+
// when not sparse.
100+
if (shape.hasTrait(SparseTrait.ID)) {
101+
writer.write("return { ...acc, [key]: null as any }");
102+
} else {
103+
writer.write("return acc;");
104+
}
105+
});
106+
107+
writer.openBlock("return {", "};", () -> {
108+
writer.write("...acc,");
109+
// Dispatch to the output value provider for any additional handling.
110+
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
111+
});
89112
}
90113
);
91114
}

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import software.amazon.smithy.model.shapes.UnionShape;
2929
import software.amazon.smithy.model.traits.IdempotencyTokenTrait;
3030
import software.amazon.smithy.model.traits.JsonNameTrait;
31+
import software.amazon.smithy.model.traits.SparseTrait;
3132
import software.amazon.smithy.model.traits.TimestampFormatTrait;
3233
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
3334
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
@@ -60,9 +61,19 @@ public void serializeCollection(GenerationContext context, CollectionShape shape
6061
TypeScriptWriter writer = context.getWriter();
6162
Shape target = context.getModel().expectShape(shape.getMember().getTarget());
6263

63-
writer.openBlock("return input.map(entry => ", ");", () ->
64-
// Dispatch to the input value provider for any additional handling.
65-
writer.write("$L", target.accept(getMemberVisitor("entry"))));
64+
// Filter out null entries if we don't have the sparse trait.
65+
String potentialFilter = "";
66+
if (!shape.hasTrait(SparseTrait.ID)) {
67+
potentialFilter = ".filter((e: any) => e != null)";
68+
}
69+
70+
writer.openBlock("return input$L.map(entry => {", "});", potentialFilter, () -> {
71+
// Short circuit null values from serialization.
72+
writer.write("if (entry === null) { return null as any; }");
73+
74+
// Dispatch to the input value provider for any additional handling.
75+
writer.write("return $L;", target.accept(getMemberVisitor("entry")));
76+
});
6677
}
6778

6879
@Override
@@ -80,14 +91,27 @@ public void serializeMap(GenerationContext context, MapShape shape) {
8091

8192
// Get the right serialization for each entry in the map. Undefined
8293
// inputs won't have this serializer invoked.
83-
writer.openBlock("return Object.entries(input).reduce((acc: $T, [key, value]: [$T, any]) => ({",
84-
"}), {});",
94+
writer.openBlock("return Object.entries(input).reduce((acc: $T, [key, value]: [$T, any]) => {",
95+
"}, {});",
8596
symbolProvider.toSymbol(shape),
8697
symbolProvider.toSymbol(shape.getKey()),
8798
() -> {
88-
writer.write("...acc,");
89-
// Dispatch to the input value provider for any additional handling.
90-
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
99+
writer.openBlock("if (value === null) {", "}", () -> {
100+
// Handle the sparse trait by short circuiting null values
101+
// from serialization, and not including them if encountered
102+
// when not sparse.
103+
if (shape.hasTrait(SparseTrait.ID)) {
104+
writer.write("return { ...acc, [key]: null as any }");
105+
} else {
106+
writer.write("return acc;");
107+
}
108+
});
109+
110+
writer.openBlock("return {", "};", () -> {
111+
writer.write("...acc,");
112+
// Dispatch to the input value provider for any additional handling.
113+
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
114+
});
91115
}
92116
);
93117
}
@@ -116,7 +140,8 @@ public void serializeStructure(GenerationContext context, StructureShape shape)
116140
if (memberShape.hasTrait(IdempotencyTokenTrait.class)) {
117141
writer.write("'$L': $L ?? generateIdempotencyToken(),", locationName, valueProvider);
118142
} else {
119-
writer.write("...($L !== undefined && { $S: $L }),", inputLocation, locationName, valueProvider);
143+
writer.write("...($1L !== undefined && $1L !== null && { $2S: $3L }),",
144+
inputLocation, locationName, valueProvider);
120145
}
121146
});
122147

0 commit comments

Comments
 (0)