Skip to content

Commit

Permalink
rpcv2 cbor final merge PR (#2590)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Apr 1, 2024
1 parent 0fde27c commit 9990706
Show file tree
Hide file tree
Showing 59 changed files with 12,482 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .changelog/41575353444b40ffbf474f4155544f00.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "41575353-444b-40ff-bf47-4f4155544f00",
"type": "release",
"description": "New AWS service client module",
"modules": [
"internal/protocoltest/smithyrpcv2cbor"
]
}
1 change: 1 addition & 0 deletions codegen/protocol-test-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ plugins {

dependencies {
implementation("software.amazon.smithy:smithy-cli:$smithyVersion")
implementation("software.amazon.smithy:smithy-protocol-tests:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
implementation(project(":smithy-aws-go-codegen"))
}
Expand Down
16 changes: 16 additions & 0 deletions codegen/protocol-test-codegen/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxmlwithnamespace"
}
}
},
"smithy-rpcv2-cbor": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"]
}
}
],
"plugins": {
"go-codegen": {
"service": "smithy.protocoltests.rpcv2Cbor#RpcV2Protocol",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/smithyrpcv2cbor"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package software.amazon.smithy.aws.go.codegen;

import java.util.List;
import software.amazon.smithy.aws.go.codegen.protocol.AwsRpc2CborProtocolGenerator;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.go.codegen.integration.HttpProtocolUtils;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator;
Expand Down Expand Up @@ -38,7 +39,8 @@ public List<ProtocolGenerator> getProtocolGenerators() {
new AwsJsonRpc1_1(),
new AwsRestXml(),
new AwsQuery(),
new Ec2Query()
new Ec2Query(),
new AwsRpc2CborProtocolGenerator()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ private static String getEventMessageExceptionDeserializerName(
return getSerDeName(toShapeId, serviceShape, protocolName, "_deserializeEventMessageException");
}

private static String getEventStreamExceptionDeserializerName(
public static String getEventStreamExceptionDeserializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
Expand All @@ -1501,7 +1501,7 @@ private static String getEventStreamMessageDeserializerName(
return getSerDeName(toShapeId, serviceShape, protocolName, "_deserializeEventMessage");
}

private static String getEventStreamDeserializerName(
public static String getEventStreamDeserializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
Expand Down Expand Up @@ -1611,7 +1611,7 @@ public static void generateEventMessageExceptionDeserializer(
}).write("");
}

private static String getEventStreamSerializerName(
public static String getEventStreamSerializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
Expand Down Expand Up @@ -1775,15 +1775,15 @@ public static void generateEventMessageRequestDeserializer(
}).write("");
}

private static String getEventStreamMessageRequestSerializerName(
public static String getEventStreamMessageRequestSerializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
) {
return getSerDeName(toShapeId, serviceShape, protocolName, "_serializeEventMessageRequest");
}

private static String getEventStreamMessageResponseDeserializerName(
public static String getEventStreamMessageResponseDeserializerName(
ToShapeId toShapeId, ServiceShape serviceShape, String protocolName
) {
return getSerDeName(toShapeId, serviceShape, protocolName, "_deserializeEventMessageResponse");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* Utility methods for generating AWS protocols.
*/
final class AwsProtocolUtils {
public final class AwsProtocolUtils {
private AwsProtocolUtils() {
}

Expand All @@ -47,7 +47,7 @@ private AwsProtocolUtils() {
*
* @param context The generation context.
*/
static void generateHttpProtocolTests(GenerationContext context) {
public static void generateHttpProtocolTests(GenerationContext context) {
Set<HttpProtocolUnitTestGenerator.ConfigValue> configValues = new TreeSet<>(SetUtils.of(
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(AddAwsConfigFields.REGION_CONFIG_NAME)
Expand Down Expand Up @@ -107,6 +107,17 @@ static void generateHttpProtocolTests(GenerationContext context) {

// skip request compression tests, not yet implemented in the SDK
Set<HttpProtocolUnitTestGenerator.SkipTest> inputSkipTests = new TreeSet<>(SetUtils.of(
// CBOR default value serialization (SHOULD)
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#OperationWithDefaults"))
.addTestName("RpcV2CborClientPopulatesDefaultValuesInInput")
.addTestName("RpcV2CborClientSkipsTopLevelDefaultValuesInInput")
.addTestName("RpcV2CborClientUsesExplicitlyProvidedMemberValuesOverDefaults")
.addTestName("RpcV2CborClientUsesExplicitlyProvidedValuesInTopLevel")
.addTestName("RpcV2CborClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional")
.build(),

HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restxml#RestXml"))
.operation(ShapeId.from("aws.protocoltests.restxml#HttpPayloadWithUnion"))
Expand All @@ -131,6 +142,14 @@ static void generateHttpProtocolTests(GenerationContext context) {
));

Set<HttpProtocolUnitTestGenerator.SkipTest> outputSkipTests = new TreeSet<>(SetUtils.of(
// CBOR default value deserialization (SHOULD)
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#OperationWithDefaults"))
.addTestName("RpcV2CborClientPopulatesDefaultsValuesWhenMissingInResponse")
.addTestName("RpcV2CborClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse")
.build(),

// REST-JSON optional (SHOULD) test cases
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.go.codegen.customization;

import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.model.Model;

/**
* Backfills the AWS service trait onto smithy-namespaced protocol tests. Long-term these protocol tests should live in
* smithy-go instead but they're currently stuck here due to conflated codegen nonsense.
*/
public class BackfillProtocolTestServiceTrait implements GoIntegration {
@Override
public byte getOrder() {
return -128;
}

@Override
public Model preprocessModel(Model model, GoSettings settings) {
var service = settings.getService(model);
if (!service.getId().getNamespace().startsWith("smithy.protocoltests")) {
return model;
}

return model.toBuilder()
.addShape(
service.toBuilder()
.addTrait(
ServiceTrait.builder()
.sdkId("")
.arnNamespace("")
.cloudFormationName("")
.cloudTrailEventSource("")
.endpointPrefix("")
.build()
)
.build()
)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.go.codegen.protocol;

import static software.amazon.smithy.go.codegen.protocol.ProtocolUtil.hasEventStream;

import software.amazon.smithy.aws.go.codegen.AwsEventStreamUtils;
import software.amazon.smithy.aws.go.codegen.AwsFnProvider;
import software.amazon.smithy.aws.go.codegen.AwsProtocolUtils;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionGenerator;
import software.amazon.smithy.go.codegen.protocol.rpc2.cbor.Rpc2CborProtocolGenerator;
import software.amazon.smithy.model.knowledge.TopDownIndex;

/**
* Extension of the smithy-borne Rpc2CborProtocolGenerator to do protocol tests and event streams since that's currently
* a 2000+ line dumpster fire in this repo.
*/
public final class AwsRpc2CborProtocolGenerator extends Rpc2CborProtocolGenerator {
@Override
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
public void generateEventStreamComponents(GenerationContext context) {
// This automagically wires up ALL the framing logic for both directions of streams. All we have to do is fill
// in the serde elsewhere (it's different signatures than normal request/response), see:
// * CborEventStreamSerializer
// * CborEventStreamDeserializer
AwsEventStreamUtils.generateEventStreamComponents(context);
}

@Override
public void generateEndpointResolution(GenerationContext context) {
new EndpointResolutionGenerator(new AwsFnProvider()).generate(context);
}

@Override
public void generateSharedSerializerComponents(GenerationContext ctx) {
super.generateSharedSerializerComponents(ctx);

var model = ctx.getModel();
var streamSerializers = TopDownIndex.of(model).getContainedOperations(ctx.getService()).stream()
.filter(it -> hasEventStream(model, model.expectShape(it.getOutputShape())))
.map(it -> (GoWriter.Writable) new CborEventStreamSerializer(ctx, it))
.toList();
ctx.getWriter().get().write(GoWriter.ChainWritable.of(streamSerializers).compose());
}

@Override
public void generateSharedDeserializerComponents(GenerationContext ctx) {
super.generateSharedDeserializerComponents(ctx);

var model = ctx.getModel();
var streamDeserializers = TopDownIndex.of(model).getContainedOperations(ctx.getService()).stream()
.filter(it -> hasEventStream(model, model.expectShape(it.getOutputShape())))
.map(it -> (GoWriter.Writable) new CborEventStreamDeserializer(ctx, it))
.toList();
ctx.getWriter().get().write(GoWriter.ChainWritable.of(streamDeserializers).compose());
}
}
Loading

0 comments on commit 9990706

Please sign in to comment.