Skip to content

Commit

Permalink
chore(protocol_tests): updates for latest protocol tests (#1770)
Browse files Browse the repository at this point in the history
  • Loading branch information
kstich authored Dec 14, 2020
1 parent 62a6f5c commit e22d9ef
Show file tree
Hide file tree
Showing 77 changed files with 14,294 additions and 1,526 deletions.
4 changes: 2 additions & 2 deletions codegen/protocol-test-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import software.amazon.smithy.gradle.tasks.SmithyBuild

plugins {
id("software.amazon.smithy") version "0.5.1"
id("software.amazon.smithy") version "0.5.2"
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@
"cloudTrailEventSource": "REPLACE_WITH_EVENT_SOURCE"
},
"aws.auth#sigv4": {
"name": ""
"name": "groundstation"
},
"aws.protocols#restJson1": {},
"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>",
Expand Down
92 changes: 0 additions & 92 deletions codegen/sdk-codegen/aws-models/redshift-data.2019-12-20.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{
"smithy": "1.0",
"shapes": {
"aws.api#ArnNamespace": {
"type": "string",
"traits": {
"smithy.api#pattern": "^[a-z0-9.\\-]{1,63}$",
"smithy.api#private": {}
}
},
"com.amazonaws.redshiftdata#Blob": {
"type": "blob"
},
Expand Down Expand Up @@ -72,13 +65,6 @@
}
}
},
"aws.api#CloudFormationName": {
"type": "string",
"traits": {
"smithy.api#pattern": "^[A-Z][A-Za-z0-9]+$",
"smithy.api#private": {}
}
},
"com.amazonaws.redshiftdata#ColumnList": {
"type": "list",
"member": {
Expand Down Expand Up @@ -1263,15 +1249,6 @@
"com.amazonaws.redshiftdata#String": {
"type": "string"
},
"aws.protocols#StringList": {
"type": "list",
"member": {
"target": "smithy.api#String"
},
"traits": {
"smithy.api#private": {}
}
},
"com.amazonaws.redshiftdata#TableList": {
"type": "list",
"member": {
Expand Down Expand Up @@ -1323,77 +1300,8 @@
"smithy.api#httpError": 400
}
},
"aws.protocols#awsJson1_1": {
"type": "structure",
"members": {
"http": {
"target": "aws.protocols#StringList"
},
"eventStreamHttp": {
"target": "aws.protocols#StringList"
}
},
"traits": {
"smithy.api#documentation": "An RPC-based protocol that sends JSON payloads. This protocol does not use HTTP binding traits.",
"smithy.api#protocolDefinition": {
"traits": ["smithy.api#jsonName"]
},
"smithy.api#trait": {
"selector": "service"
}
}
},
"com.amazonaws.redshiftdata#bool": {
"type": "boolean"
},
"aws.api#service": {
"type": "structure",
"members": {
"sdkId": {
"target": "smithy.api#String",
"traits": {
"smithy.api#required": {}
}
},
"arnNamespace": {
"target": "aws.api#ArnNamespace"
},
"cloudFormationName": {
"target": "aws.api#CloudFormationName"
},
"cloudTrailEventSource": {
"target": "smithy.api#String"
}
},
"traits": {
"smithy.api#trait": {
"selector": "service"
}
}
},
"aws.auth#sigv4": {
"type": "structure",
"members": {
"name": {
"target": "smithy.api#String",
"traits": {
"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`.",
"smithy.api#externalDocumentation": {
"Reference": "https://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html"
},
"smithy.api#required": {}
}
}
},
"traits": {
"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.",
"smithy.api#externalDocumentation": {
"Reference": "https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html"
},
"smithy.api#trait": {
"selector": "service"
}
}
}
}
}
2 changes: 1 addition & 1 deletion codegen/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import software.amazon.smithy.model.node.Node
import software.amazon.smithy.gradle.tasks.SmithyBuild

plugins {
id("software.amazon.smithy") version "0.5.1"
id("software.amazon.smithy") version "0.5.2"
}

dependencies {
Expand Down
8 changes: 4 additions & 4 deletions codegen/smithy-aws-typescript-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {
}

group = "software.amazon.smithy"
version = "0.2.0"
version = "0.3.0"

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -33,9 +33,9 @@ tasks.withType<Test> {
}

dependencies {
api("software.amazon.smithy:smithy-aws-traits:1.0.5")
api("software.amazon.smithy:smithy-aws-iam-traits:1.0.5")
api("software.amazon.smithy:smithy-typescript-codegen:0.2.0")
api("software.amazon.smithy:smithy-aws-traits:[1.5.0, 2.0[")
api("software.amazon.smithy:smithy-aws-iam-traits:[1.5.0, 2.0[")
api("software.amazon.smithy:smithy-typescript-codegen:0.3.0")
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.0")
testCompile("org.junit.jupiter:junit-jupiter-params:5.4.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberSerVisitor;
import software.amazon.smithy.typescript.codegen.integration.HttpRpcProtocolGenerator;
import software.amazon.smithy.utils.IoUtils;

/**
* Handles general components across the AWS JSON protocols that have do not have
Expand Down Expand Up @@ -73,6 +74,10 @@ public void generateSharedComponents(GenerationContext context) {
super.generateSharedComponents(context);
AwsProtocolUtils.generateJsonParseBody(context);
AwsProtocolUtils.addItempotencyAutofillImport(context);

TypeScriptWriter writer = context.getWriter();
writer.addUseImports(getApplicationProtocol().getResponseType());
writer.write(IoUtils.readUtf8Resource(getClass(), "load-json-error-code-stub.ts"));
}

@Override
Expand Down Expand Up @@ -105,9 +110,9 @@ private DocumentMemberSerVisitor getMemberSerVisitor(GenerationContext context,
@Override
protected void writeErrorCodeParser(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();
// parsedOutput is in scope because HttpRpcProtocolGenerator.isErrorCodeInBody is true
writer.write("const errorTypeParts: String = parsedOutput.body[\"__type\"].split('#');");
writer.write("errorCode = (errorTypeParts[1] === undefined) ? errorTypeParts[0] : errorTypeParts[1];");

// Outsource error code parsing since it's complex for this protocol.
writer.write("errorCode = loadRestJsonErrorCode(output, parsedOutput.body);");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.traits.JsonNameTrait;
import software.amazon.smithy.model.traits.SparseTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
Expand Down Expand Up @@ -57,9 +58,18 @@ protected void deserializeCollection(GenerationContext context, CollectionShape
TypeScriptWriter writer = context.getWriter();
Shape target = context.getModel().expectShape(shape.getMember().getTarget());

// Dispatch to the output value provider for any additional handling.
writer.openBlock("return (output || []).map((entry: any) =>", ");", () -> {
writer.write(target.accept(getMemberVisitor("entry")));
// Filter out null entries if we don't have the sparse trait.
String potentialFilter = "";
if (!shape.hasTrait(SparseTrait.ID)) {
potentialFilter = ".filter((e: any) => e != null)";
}

writer.openBlock("return (output || [])$L.map((entry: any) => {", "});", potentialFilter, () -> {
// Short circuit null values from serialization.
writer.write("if (entry === null) { return null as any; }");

// Dispatch to the output value provider for any additional handling.
writer.write("return $L;", target.accept(getMemberVisitor("entry")));
});
}

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

// Get the right serialization for each entry in the map. Undefined
// outputs won't have this deserializer invoked.
writer.openBlock("return Object.entries(output).reduce((acc: $T, [key, value]: [$T, any]) => ({",
"}), {});",
writer.openBlock("return Object.entries(output).reduce((acc: $T, [key, value]: [$T, any]) => {",
"}, {});",
symbolProvider.toSymbol(shape),
symbolProvider.toSymbol(shape.getKey()),
() -> {
writer.write("...acc,");
// Dispatch to the output value provider for any additional handling.
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
writer.openBlock("if (value === null) {", "}", () -> {
// Handle the sparse trait by short circuiting null values
// from deserialization, and not including them if encountered
// when not sparse.
if (shape.hasTrait(SparseTrait.ID)) {
writer.write("return { ...acc, [key]: null as any }");
} else {
writer.write("return acc;");
}
});

writer.openBlock("return {", "};", () -> {
writer.write("...acc,");
// Dispatch to the output value provider for any additional handling.
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
});
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.traits.IdempotencyTokenTrait;
import software.amazon.smithy.model.traits.JsonNameTrait;
import software.amazon.smithy.model.traits.SparseTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
Expand Down Expand Up @@ -60,9 +61,19 @@ public void serializeCollection(GenerationContext context, CollectionShape shape
TypeScriptWriter writer = context.getWriter();
Shape target = context.getModel().expectShape(shape.getMember().getTarget());

writer.openBlock("return input.map(entry => ", ");", () ->
// Dispatch to the input value provider for any additional handling.
writer.write("$L", target.accept(getMemberVisitor("entry"))));
// Filter out null entries if we don't have the sparse trait.
String potentialFilter = "";
if (!shape.hasTrait(SparseTrait.ID)) {
potentialFilter = ".filter((e: any) => e != null)";
}

writer.openBlock("return input$L.map(entry => {", "});", potentialFilter, () -> {
// Short circuit null values from serialization.
writer.write("if (entry === null) { return null as any; }");

// Dispatch to the input value provider for any additional handling.
writer.write("return $L;", target.accept(getMemberVisitor("entry")));
});
}

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

// Get the right serialization for each entry in the map. Undefined
// inputs won't have this serializer invoked.
writer.openBlock("return Object.entries(input).reduce((acc: $T, [key, value]: [$T, any]) => ({",
"}), {});",
writer.openBlock("return Object.entries(input).reduce((acc: $T, [key, value]: [$T, any]) => {",
"}, {});",
symbolProvider.toSymbol(shape),
symbolProvider.toSymbol(shape.getKey()),
() -> {
writer.write("...acc,");
// Dispatch to the input value provider for any additional handling.
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
writer.openBlock("if (value === null) {", "}", () -> {
// Handle the sparse trait by short circuiting null values
// from serialization, and not including them if encountered
// when not sparse.
if (shape.hasTrait(SparseTrait.ID)) {
writer.write("return { ...acc, [key]: null as any }");
} else {
writer.write("return acc;");
}
});

writer.openBlock("return {", "};", () -> {
writer.write("...acc,");
// Dispatch to the input value provider for any additional handling.
writer.write("[key]: $L", target.accept(getMemberVisitor("value")));
});
}
);
}
Expand Down Expand Up @@ -116,7 +140,8 @@ public void serializeStructure(GenerationContext context, StructureShape shape)
if (memberShape.hasTrait(IdempotencyTokenTrait.class)) {
writer.write("'$L': $L ?? generateIdempotencyToken(),", locationName, valueProvider);
} else {
writer.write("...($L !== undefined && { $S: $L }),", inputLocation, locationName, valueProvider);
writer.write("...($1L !== undefined && $1L !== null && { $2S: $3L }),",
inputLocation, locationName, valueProvider);
}
});

Expand Down
Loading

0 comments on commit e22d9ef

Please sign in to comment.