Skip to content

Commit

Permalink
General Cleanup and Upgrade to Smithy 1.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Nov 11, 2021
1 parent 06e5fdf commit 680aa20
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion codegen/protocol-test-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {
}

dependencies {
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.13.1,1.14.0[")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.14.0,1.15.0[")
implementation(project(":smithy-aws-go-codegen"))
}

Expand Down
6 changes: 3 additions & 3 deletions codegen/smithy-aws-go-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ tasks.withType<Test> {
}

dependencies {
api("software.amazon.smithy:smithy-aws-traits:[1.13.1,2.0.0[")
api("software.amazon.smithy:smithy-aws-iam-traits:[1.13.1,2.0.0[")
api("software.amazon.smithy:smithy-aws-cloudformation-traits:[1.13.1,2.0.0[")
api("software.amazon.smithy:smithy-aws-traits:[1.14.0,2.0.0[")
api("software.amazon.smithy:smithy-aws-iam-traits:[1.14.0,2.0.0[")
api("software.amazon.smithy:smithy-aws-cloudformation-traits:[1.14.0,2.0.0[")
api("software.amazon.smithy.go:smithy-go-codegen:0.1.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.4.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestResponseGenerator;
import software.amazon.smithy.go.codegen.integration.IdempotencyTokenMiddlewareGenerator;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator.GenerationContext;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.utils.SetUtils;

Expand Down Expand Up @@ -207,6 +208,13 @@ static void generateHttpProtocolTests(GenerationContext context) {
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#EmptyInputAndEmptyOutput"))
.addTestName("AwsJson10EmptyInputAndEmptyOutput")
.build(),

// HTTP Payload Values that are unset vs set by the customer and how content-type should be handled.
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#TestPayloadBlob"))
.addTestName("RestJsonHttpWithEmptyBlobPayload")
.build()
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.traits.EnumTrait;
Expand Down Expand Up @@ -107,8 +108,7 @@ protected void generateOperationDocumentSerializer(
protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
GenerationContext context,
MemberShape memberShape,
String operand,
Consumer<GoWriter> setStream
String operand
) {
GoWriter writer = context.getWriter().get();
Model model = context.getModel();
Expand All @@ -123,6 +123,8 @@ protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
payloadShape, context.getService(), context.getProtocolName());
}

writeSetPayloadShapeHeader(writer, payloadShape);

GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
memberShape, operand, (s) -> {
writer.addUseImports(SmithyGoDependency.SMITHY_JSON);
Expand All @@ -133,14 +135,14 @@ protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
return out, metadata, &smithy.SerializationError{Err: err}
}
payload := bytes.NewReader(jsonEncoder.Bytes())""", functionName, s);
setStream.accept(writer);
if (payloadShape.isStructureShape()) {
writeSetStream(writer, "payload");
if (payloadShape.getType() == ShapeType.STRUCTURE) {
writer.openBlock("} else {", "", () -> {
writer.write("""
jsonEncoder := smithyjson.NewEncoder()
jsonEncoder.Value.Object().Close()
payload := bytes.NewReader(jsonEncoder.Bytes())""");
setStream.accept(writer);
writeSetStream(writer, "payload");
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ private void initalizeXmlEncoder(
protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
GenerationContext context,
MemberShape memberShape,
String operand,
Consumer<GoWriter> setStream
String operand
) {
GoWriter writer = context.getWriter().get();
Model model = context.getModel();
Shape payloadShape = model.expectShape(memberShape.getTarget());

GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
memberShape, operand, (s) -> {
writeSetPayloadShapeHeader(writer, payloadShape);

writer.addUseImports(SmithyGoDependency.SMITHY_XML);
writer.addUseImports(SmithyGoDependency.BYTES);
writer.write("xmlEncoder := smithyxml.NewEncoder(bytes.NewBuffer(nil))");
Expand All @@ -180,7 +181,7 @@ protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
});
writer.write("payload := bytes.NewReader(xmlEncoder.Bytes())");
setStream.accept(writer);
writeSetStream(writer, "payload");
});
}

Expand Down

0 comments on commit 680aa20

Please sign in to comment.