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

Smithy Document Shape Support #310

Merged
merged 3 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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