Skip to content

Commit

Permalink
Add Smithy Document Shape Support (#310)
Browse files Browse the repository at this point in the history
Adds support for Smithy Document shapes and supporting types for protocols to implement support.

AWS Protocol Support: aws/aws-sdk-go-v2#1320
  • Loading branch information
skmcgrail authored Jul 29, 2021
1 parent 5c681d5 commit d3a155d
Show file tree
Hide file tree
Showing 35 changed files with 3,336 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ final class CodegenVisitor extends ShapeVisitor.Default<Void> {
private final ProtocolGenerator protocolGenerator;
private final ApplicationProtocol applicationProtocol;
private final List<RuntimeClientPlugin> runtimePlugins = new ArrayList<>();
private final ProtocolDocumentGenerator protocolDocumentGenerator;

CodegenVisitor(PluginContext context) {
// Load all integrations.
Expand Down Expand Up @@ -125,6 +126,8 @@ final class CodegenVisitor extends ShapeVisitor.Default<Void> {
: protocolGenerator.getApplicationProtocol();

writers = new GoDelegator(settings, model, fileManifest, symbolProvider);

protocolDocumentGenerator = new ProtocolDocumentGenerator(settings, model, writers);
}

private static ProtocolGenerator resolveProtocolGenerator(
Expand Down Expand Up @@ -164,6 +167,9 @@ void execute() {
shape.accept(this);
}

// Generate any required types and functions need to support protocol documents.
protocolDocumentGenerator.generateDocumentSupport();

// Generate a struct to handle unknown tags in unions
List<UnionShape> unions = serviceShapes.stream()
.map(Shape::asUnionShape)
Expand All @@ -182,35 +188,36 @@ void execute() {

if (protocolGenerator != null) {
LOGGER.info("Generating serde for protocol " + protocolGenerator.getProtocol() + " on " + service.getId());
ProtocolGenerator.GenerationContext context = new ProtocolGenerator.GenerationContext();
context.setProtocolName(protocolGenerator.getProtocolName());
context.setIntegrations(integrations);
context.setModel(model);
context.setService(service);
context.setSettings(settings);
context.setSymbolProvider(symbolProvider);
context.setDelegator(writers);
ProtocolGenerator.GenerationContext.Builder contextBuilder = ProtocolGenerator.GenerationContext.builder()
.protocolName(protocolGenerator.getProtocolName())
.integrations(integrations)
.model(model)
.service(service)
.settings(settings)
.symbolProvider(symbolProvider)
.delegator(writers);

LOGGER.info("Generating serde for protocol " + protocolGenerator.getProtocol()
+ " on " + service.getId());
writers.useFileWriter("serializers.go", settings.getModuleName(), writer -> {
context.setWriter(writer);
ProtocolGenerator.GenerationContext context = contextBuilder.writer(writer).build();
protocolGenerator.generateRequestSerializers(context);
protocolGenerator.generateSharedSerializerComponents(context);
});

writers.useFileWriter("deserializers.go", settings.getModuleName(), writer -> {
context.setWriter(writer);
ProtocolGenerator.GenerationContext context = contextBuilder.writer(writer).build();
protocolGenerator.generateResponseDeserializers(context);
protocolGenerator.generateSharedDeserializerComponents(context);
});

LOGGER.info("Generating protocol " + protocolGenerator.getProtocol()
+ " unit tests for " + service.getId());
writers.useFileWriter("protocol_test.go", settings.getModuleName(), writer -> {
context.setWriter(writer);
protocolGenerator.generateProtocolTests(context);
protocolGenerator.generateProtocolTests(contextBuilder.writer(writer).build());
});

protocolDocumentGenerator.generateInternalDocumentTypes(protocolGenerator, contextBuilder.build());
}

LOGGER.fine("Flushing go writers");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ public GoWriter writePackageDocs(String docs) {
return this;
}

/**
* Writes the doc to the Go package docs that are written prior to the go package statement. This does not perform
* line wrapping and the provided formatting must be valid Go doc.
*
* @param docs documentation to write to package doc.
* @return writer
*/
public GoWriter writeRawPackageDocs(String docs) {
writeDocs(packageDocs, () -> {
packageDocs.write(docs);
});
return this;
}

/**
* Writes shape documentation comments if docs are present.
*
Expand Down
Loading

0 comments on commit d3a155d

Please sign in to comment.