Skip to content

Commit

Permalink
Upgrade to Smithy 1.14.0 (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail authored Nov 11, 2021
1 parent f349b7e commit 0b6e601
Show file tree
Hide file tree
Showing 385 changed files with 72,854 additions and 7,626 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.6.0,1.10.0[")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.14.0,1.15.0[")
implementation(project(":smithy-aws-go-codegen"))
}

Expand Down
2 changes: 1 addition & 1 deletion codegen/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlin.streams.toList

buildscript {
dependencies {
"classpath"("software.amazon.smithy:smithy-aws-traits:[1.5.1,2.0.0[")
"classpath"("software.amazon.smithy:smithy-aws-traits:[1.13.1,2.0.0[")
}
}

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.5.1,2.0.0[")
api("software.amazon.smithy:smithy-aws-iam-traits:[1.6.1,2.0.0[")
api("software.amazon.smithy:smithy-aws-cloudformation-traits:[1.8.0,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 @@ -56,7 +57,7 @@ static void generateHttpProtocolTests(GenerationContext context) {
writer.addUseImports(AwsGoDependency.AWS_CORE);
writer.openBlock("$L(func(region string, options $L) (e aws.Endpoint, err error) {", "}),",
EndpointGenerator.RESOLVER_FUNC_NAME, EndpointGenerator.RESOLVER_OPTIONS, () -> {
writer.write("e.URL = url");
writer.write("e.URL = serverURL");
writer.write("e.SigningRegion = \"us-west-2\"");
writer.write("return e, err");
});
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 @@ -24,11 +24,13 @@
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.go.codegen.GoStackStepMiddlewareGenerator;
import software.amazon.smithy.go.codegen.GoValueAccessUtils;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.SmithyGoDependency;
import software.amazon.smithy.go.codegen.SyntheticClone;
Expand All @@ -45,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 All @@ -54,6 +57,7 @@
import software.amazon.smithy.model.traits.MediaTypeTrait;
import software.amazon.smithy.model.traits.StreamingTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait;
import software.amazon.smithy.model.traits.XmlNamespaceTrait;

/**
* Handles general components across the AWS JSON protocols that have HTTP bindings.
Expand Down Expand Up @@ -119,15 +123,29 @@ protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
payloadShape, context.getService(), context.getProtocolName());
}

writer.addUseImports(SmithyGoDependency.SMITHY_JSON);
writer.write("jsonEncoder := smithyjson.NewEncoder()");
writer.openBlock("if err := $L($L, jsonEncoder.Value); err != nil {", "}", functionName,
operand, () -> {
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
writeSetPayloadShapeHeader(writer, payloadShape);

GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
memberShape, operand, (s) -> {
writer.addUseImports(SmithyGoDependency.SMITHY_JSON);
writer.addUseImports(SmithyGoDependency.BYTES);
writer.write("""
jsonEncoder := smithyjson.NewEncoder()
if err := $L($L, jsonEncoder.Value); err != nil {
return out, metadata, &smithy.SerializationError{Err: err}
}
payload := bytes.NewReader(jsonEncoder.Bytes())""", functionName, s);
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())""");
writeSetStream(writer, "payload");
});
}
});

writer.addUseImports(SmithyGoDependency.BYTES);
writer.write("payload := bytes.NewReader(jsonEncoder.Bytes())");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.TreeSet;
import java.util.function.Predicate;
Expand All @@ -19,6 +20,7 @@
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.go.codegen.GoStackStepMiddlewareGenerator;
import software.amazon.smithy.go.codegen.GoValueAccessUtils;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.SmithyGoDependency;
import software.amazon.smithy.go.codegen.SymbolUtils;
Expand Down Expand Up @@ -114,7 +116,7 @@ protected void writeMiddlewareDocumentSerializerDelegator(
writer.insertTrailingNewline();

writer.openBlock("if request, err = request.SetStream(bytes.NewReader(xmlEncoder.Bytes())); "
+ "err != nil {", "}", () -> {
+ "err != nil {", "}", () -> {
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
});
}
Expand Down Expand Up @@ -152,28 +154,35 @@ protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
Model model = context.getModel();
Shape payloadShape = model.expectShape(memberShape.getTarget());

writer.addUseImports(SmithyGoDependency.SMITHY_XML);
writer.addUseImports(SmithyGoDependency.BYTES);
writer.write("xmlEncoder := smithyxml.NewEncoder(bytes.NewBuffer(nil))");
GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
memberShape, operand, (s) -> {
writeSetPayloadShapeHeader(writer, payloadShape);

generatePayloadAsDocumentXMLStartElement(context, memberShape, "payloadRoot", operand);
writer.addUseImports(SmithyGoDependency.SMITHY_XML);
writer.addUseImports(SmithyGoDependency.BYTES);
writer.write("xmlEncoder := smithyxml.NewEncoder(bytes.NewBuffer(nil))");

// check if service shape is bound by xmlNameSpace Trait
Optional<XmlNamespaceTrait> xmlNamespaceTrait = context.getService().getTrait(XmlNamespaceTrait.class);
if (xmlNamespaceTrait.isPresent()) {
XmlNamespaceTrait namespace = xmlNamespaceTrait.get();
writer.write("payloadRoot.Attr = append(payloadRoot.Attr, smithyxml.NewNamespaceAttribute($S, $S))",
namespace.getPrefix().isPresent() ? namespace.getPrefix().get() : "", namespace.getUri()
);
}
generatePayloadAsDocumentXMLStartElement(context, memberShape, "payloadRoot", s);

String functionName = ProtocolGenerator.getDocumentSerializerFunctionName(
payloadShape, context.getService(), getProtocolName());
writer.openBlock("if err := $L($L, xmlEncoder.RootElement(payloadRoot)); err != nil {", "}", functionName,
operand, () -> {
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
// check if service shape is bound by xmlNameSpace Trait
Optional<XmlNamespaceTrait> xmlNamespaceTrait = context.getService()
.getTrait(XmlNamespaceTrait.class);
if (xmlNamespaceTrait.isPresent()) {
XmlNamespaceTrait namespace = xmlNamespaceTrait.get();
writer.write("payloadRoot.Attr = append(payloadRoot.Attr, smithyxml.NewNamespaceAttribute($S, $S))",
namespace.getPrefix().isPresent() ? namespace.getPrefix().get() : "", namespace.getUri()
);
}

String functionName = ProtocolGenerator.getDocumentSerializerFunctionName(
payloadShape, context.getService(), getProtocolName());
writer.openBlock("if err := $L($L, xmlEncoder.RootElement(payloadRoot)); err != nil {", "}", functionName,
s, () -> {
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
});
writer.write("payload := bytes.NewReader(xmlEncoder.Bytes())");
writeSetStream(writer, "payload");
});
writer.write("payload := bytes.NewReader(xmlEncoder.Bytes())");
}

@Override
Expand Down Expand Up @@ -490,7 +499,7 @@ protected void generateEventStreamSerializers(

var hasBindings = targetShape.members().stream()
.filter(ms -> ms.getTrait(EventHeaderTrait.class).isPresent()
|| ms.getTrait(EventPayloadTrait.class).isPresent())
|| ms.getTrait(EventPayloadTrait.class).isPresent())
.findAny();
if (hasBindings.isPresent()) {
var payload = targetShape.members().stream()
Expand Down Expand Up @@ -609,7 +618,7 @@ protected void generateEventStreamDeserializers(

var hasBindings = targetShape.members().stream()
.filter(ms -> ms.getTrait(EventHeaderTrait.class).isPresent()
|| ms.getTrait(EventPayloadTrait.class).isPresent())
|| ms.getTrait(EventPayloadTrait.class).isPresent())
.findAny();
if (hasBindings.isPresent()) {
var payload = targetShape.members().stream()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b6e601

Please sign in to comment.