Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aws library functions for endpoint rules engine and fix partition generation #2110

Merged
merged 8 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
renamed upstream file
  • Loading branch information
isaiahvita committed May 3, 2023
commit 1cb0faed81979040e6fcd6d712bdf7eba07d5ecf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.smithy.go.codegen.endpoints.EndpointRulesEngineGenerator;
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionV2Generator;
import software.amazon.smithy.go.codegen.endpoints.FnGenerator;

/**
Expand Down Expand Up @@ -194,17 +194,15 @@ public String getErrorCode(ServiceShape service, StructureShape errorShape) {
protected void generateEventStreamSerializers(
GenerationContext context,
UnionShape eventUnion,
Set<EventStreamInfo> eventStreamInfos
) {
Set<EventStreamInfo> eventStreamInfos) {
throw new CodegenException("event streams not supported with AWS QUERY protocol.");
}

@Override
protected void generateEventStreamDeserializers(
GenerationContext context,
UnionShape eventUnion,
Set<EventStreamInfo> eventStreamInfos
) {
Set<EventStreamInfo> eventStreamInfos) {
throw new CodegenException("event streams not supported with AWS QUERY protocol.");
}

Expand All @@ -214,8 +212,8 @@ public void generateEventStreamComponents(GenerationContext context) {
}

@Override
public void generateEndpointRulesEngine(GenerationContext context) {
var generator = new EndpointRulesEngineGenerator(new AwsFnProvider());
public void generateEndpointResolutionV2(GenerationContext context) {
var generator = new EndpointResolutionV2Generator(new AwsFnProvider());
generator.generate(context);
}

Expand All @@ -224,5 +222,4 @@ protected void writeOperationSerializerMiddlewareEventStreamSetup(GenerationCont
throw new CodegenException("event streams not supported with AWS QUERY protocol.");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.smithy.model.traits.EventHeaderTrait;
import software.amazon.smithy.model.traits.EventPayloadTrait;
import software.amazon.smithy.go.codegen.endpoints.EndpointRulesEngineGenerator;
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionV2Generator;
import software.amazon.smithy.go.codegen.endpoints.FnGenerator;


/**
* Handles generating the aws.rest-json protocol for services.
*
Expand Down Expand Up @@ -82,7 +81,8 @@ protected void writeDefaultHeaders(GenerationContext context, OperationShape ope
protected void serializeInputDocument(GenerationContext context, OperationShape operation) {
GoWriter writer = context.getWriter().get();

// Stub synthetic inputs mean there never was an input modeled, always serialize empty JSON object
// Stub synthetic inputs mean there never was an input modeled, always serialize
// empty JSON object
// as place holder.
if (CodegenUtils.isStubSynthetic(ProtocolUtils.expectInput(context.getModel(), operation))) {
writer.addUseImports(SmithyGoDependency.STRINGS);
Expand Down Expand Up @@ -212,8 +212,7 @@ protected void writeOperationSerializerMiddlewareEventStreamSetup(GenerationCont
protected void generateEventStreamSerializers(
GenerationContext context,
UnionShape eventUnion,
Set<EventStreamInfo> eventStreamInfos
) {
Set<EventStreamInfo> eventStreamInfos) {
Model model = context.getModel();

AwsEventStreamUtils.generateEventStreamSerializer(context, eventUnion);
Expand Down Expand Up @@ -279,8 +278,7 @@ protected void generateEventStreamSerializers(
protected void generateEventStreamDeserializers(
GenerationContext context,
UnionShape eventUnion,
Set<EventStreamInfo> eventStreamInfos
) {
Set<EventStreamInfo> eventStreamInfos) {
var model = context.getModel();

AwsEventStreamUtils.generateEventStreamDeserializer(context, eventUnion);
Expand Down Expand Up @@ -317,7 +315,7 @@ protected void generateEventStreamDeserializers(
payloadTarget, ctx.getService(), getProtocolName());
var ctxWriter = ctx.getWriter().get();
ctxWriter.openBlock("if err := $L(&$L, shape); err != nil {", "}", functionName, operand,
() -> handleDecodeError(ctxWriter))
() -> handleDecodeError(ctxWriter))
.write("return nil");
});

Expand Down Expand Up @@ -350,7 +348,7 @@ protected void generateEventStreamDeserializers(
AwsProtocolUtils.initializeJsonEventMessageDeserializer(ctx, "nil,");
var ctxWriter = ctx.getWriter().get();
ctxWriter.openBlock("if err := $L(&$L, shape); err != nil {", "}", functionName, operand,
() -> handleDecodeError(ctxWriter, "nil,"))
() -> handleDecodeError(ctxWriter, "nil,"))
.write("return v, nil");
});
var initialMessageMembers = streamInfo.getInitialMessageMembers()
Expand All @@ -364,8 +362,8 @@ protected void generateEventStreamDeserializers(
}

@Override
public void generateEndpointRulesEngine(GenerationContext context) {
var generator = new EndpointRulesEngineGenerator(new AwsFnProvider());
public void generateEndpointResolutionV2(GenerationContext context) {
var generator = new EndpointResolutionV2Generator(new AwsFnProvider());
generator.generate(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@
import software.amazon.smithy.model.traits.StreamingTrait;
import software.amazon.smithy.model.traits.TimestampFormatTrait;
import software.amazon.smithy.model.traits.XmlNamespaceTrait;
import software.amazon.smithy.go.codegen.endpoints.EndpointRulesEngineGenerator;
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionV2Generator;
import software.amazon.smithy.go.codegen.endpoints.FnGenerator;


/**
* Handles general components across the AWS JSON protocols that have HTTP bindings.
* Handles general components across the AWS JSON protocols that have HTTP
* bindings.
* It handles reading and writing from document bodies, including generating any
* functions needed for performing serde.
*
* @see <a href="https://smithy.io/2.0/spec/http-bindings.html">Smithy HTTP protocol bindings.</a>
* @see <a href="https://smithy.io/2.0/spec/http-bindings.html">Smithy HTTP
* protocol bindings.</a>
*/
abstract class RestJsonProtocolGenerator extends HttpBindingProtocolGenerator {
private final Set<ShapeId> generatedDocumentBodyShapeSerializers = new HashSet<>();
Expand All @@ -90,8 +91,7 @@ protected TimestampFormatTrait.Format getDocumentTimestampFormat() {
@Override
protected void generateOperationDocumentSerializer(
GenerationContext context,
OperationShape operation
) {
OperationShape operation) {
Model model = context.getModel();
HttpBindingIndex bindingIndex = HttpBindingIndex.of(model);
Set<MemberShape> documentBindings = bindingIndex.getRequestBindings(operation, HttpBinding.Location.DOCUMENT)
Expand All @@ -111,21 +111,17 @@ protected void generateOperationDocumentSerializer(
.build());
}


@Override
public void generateEndpointRulesEngine(GenerationContext context) {
var generator = new EndpointRulesEngineGenerator(new AwsFnProvider());
public void generateEndpointResolutionV2(GenerationContext context) {
var generator = new EndpointResolutionV2Generator(new AwsFnProvider());
generator.generate(context);
}



@Override
protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
GenerationContext context,
MemberShape memberShape,
String operand
) {
String operand) {
GoWriter writer = context.getWriter().get();
Model model = context.getModel();
Shape payloadShape = model.expectShape(memberShape.getTarget());
Expand Down Expand Up @@ -165,7 +161,8 @@ protected void writeMiddlewarePayloadAsDocumentSerializerDelegator(
}

/**
* Retruns the MediaType for the payload shape derived from the MediaTypeTrait, shape type, or document content type.
* Retruns the MediaType for the payload shape derived from the MediaTypeTrait,
* shape type, or document content type.
*
* @param payloadShape shape bound to the payload.
* @return string for media type.
Expand All @@ -192,8 +189,7 @@ private String getPayloadShapeMediaType(Shape payloadShape) {
protected void writeMiddlewareDocumentSerializerDelegator(
GenerationContext context,
OperationShape operation,
GoStackStepMiddlewareGenerator generator
) {
GoStackStepMiddlewareGenerator generator) {
GoWriter writer = context.getWriter().get();
writer.addUseImports(SmithyGoDependency.SMITHY);
writer.addUseImports(SmithyGoDependency.SMITHY_JSON);
Expand Down Expand Up @@ -238,8 +234,7 @@ protected void generateDocumentBodyShapeSerializers(GenerationContext context, S
protected void writeMiddlewareDocumentDeserializerDelegator(
GenerationContext context,
OperationShape operation,
GoStackStepMiddlewareGenerator generator
) {
GoStackStepMiddlewareGenerator generator) {
Model model = context.getModel();
GoWriter writer = context.getWriter().get();
Shape targetShape = ProtocolUtils.expectOutput(model, operation);
Expand All @@ -256,13 +251,15 @@ protected void writeMiddlewareDocumentDeserializerDelegator(

Shape payloadShape = model.expectShape(memberShape.getTarget());

// if target shape is of type String or type Blob, then delegate deserializers for explicit payload shapes
// if target shape is of type String or type Blob, then delegate deserializers
// for explicit payload shapes
if (payloadShape.isStringShape() || payloadShape.isBlobShape()) {
writeMiddlewarePayloadBindingDeserializerDelegator(writer, context.getService(), targetShape,
payloadShape);
return;
}
// for other payload target types we should deserialize using the appropriate document deserializer
// for other payload target types we should deserialize using the appropriate
// document deserializer
targetShape = payloadShape;
operand += "." + context.getSymbolProvider().toMemberName(memberShape);
}
Expand All @@ -285,10 +282,10 @@ protected void writeMiddlewareDocumentDeserializerDelegator(
writeMiddlewareDocumentBindingDeserializerDelegator(context, writer, targetShape, operand);
}

// Writes middleware that delegates to deserializers for shapes that have explicit payload.
// Writes middleware that delegates to deserializers for shapes that have
// explicit payload.
private void writeMiddlewarePayloadBindingDeserializerDelegator(
GoWriter writer, ServiceShape service, Shape outputShape, Shape payloadShape
) {
GoWriter writer, ServiceShape service, Shape outputShape, Shape payloadShape) {
String deserFuncName = ProtocolGenerator.getDocumentDeserializerFunctionName(outputShape, service,
getProtocolName());

Expand All @@ -305,13 +302,13 @@ private void writeMiddlewarePayloadBindingDeserializerDelegator(
});
}

// Write middleware that delegates to deserializers for shapes that have implicit payload and deserializer
// Write middleware that delegates to deserializers for shapes that have
// implicit payload and deserializer
private void writeMiddlewareDocumentBindingDeserializerDelegator(
GenerationContext context,
GoWriter writer,
Shape shape,
String operand
) {
String operand) {
String functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());

Expand All @@ -331,8 +328,7 @@ private void writeMiddlewareDocumentBindingDeserializerDelegator(
@Override
protected void generateOperationDocumentDeserializer(
GenerationContext context,
OperationShape operation
) {
OperationShape operation) {
Model model = context.getModel();
HttpBindingIndex bindingIndex = HttpBindingIndex.of(model);
Set<MemberShape> documentBindings = bindingIndex.getResponseBindings(operation, HttpBinding.Location.DOCUMENT)
Expand Down Expand Up @@ -424,8 +420,7 @@ protected void generateDocumentBodyShapeDeserializers(GenerationContext context,
private void writePayloadBindingDeserializer(
GenerationContext context,
Shape shape,
Predicate<MemberShape> filterMemberShapes
) {
Predicate<MemberShape> filterMemberShapes) {
var writer = context.getWriter().get();
var symbolProvider = context.getSymbolProvider();
var shapeSymbol = symbolProvider.toSymbol(shape);
Expand Down Expand Up @@ -537,8 +532,7 @@ protected void writeOperationSerializerMiddlewareEventStreamSetup(GenerationCont
protected void generateEventStreamSerializers(
GenerationContext context,
UnionShape eventUnion,
Set<EventStreamInfo> eventStreamInfos
) {
Set<EventStreamInfo> eventStreamInfos) {
Model model = context.getModel();

AwsEventStreamUtils.generateEventStreamSerializer(context, eventUnion);
Expand Down Expand Up @@ -586,8 +580,7 @@ protected void generateEventStreamSerializers(
protected void generateEventStreamDeserializers(
GenerationContext context,
UnionShape eventUnion,
Set<EventStreamInfo> eventStreamInfos
) {
Set<EventStreamInfo> eventStreamInfos) {
var model = context.getModel();

AwsEventStreamUtils.generateEventStreamDeserializer(context, eventUnion);
Expand Down
Loading