Skip to content

Commit 19a39f2

Browse files
Merge pull request #3 from smithy-lang/base-generation
Add base generation capability
2 parents 8450dc8 + 805b29d commit 19a39f2

File tree

18 files changed

+736
-40
lines changed

18 files changed

+736
-40
lines changed

config/checkstyle/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- Files must contain a copyright header, with or without a year. -->
2323
<module name="RegexpHeader">
2424
<property name="header"
25-
value="/\*\n \* Copyright( 20(23)|) Amazon\.com, Inc\. or its affiliates\. All Rights Reserved\.\n"/>
25+
value="/\*\n \* Copyright Amazon\.com, Inc\. or its affiliates\. All Rights Reserved\.\n"/>
2626
<property name="fileExtensions" value="java"/>
2727
</module>
2828

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
smithyVersion=1.33.0
2-
smithyGradleVersion=0.7.0
1+
smithyVersion=[1.39.1,2.0)
2+
smithyGradleVersion=0.8.0

smithy-docgen-core/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ ext {
2222
}
2323

2424
dependencies {
25-
api("software.amazon.smithy:smithy-build:$smithyVersion")
25+
implementation("software.amazon.smithy:smithy-build:$smithyVersion")
26+
implementation("software.amazon.smithy:smithy-model:$smithyVersion")
27+
implementation("software.amazon.smithy:smithy-utils:$smithyVersion")
28+
implementation("software.amazon.smithy:smithy-codegen-core:$smithyVersion")
2629
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.docgen.core;
7+
8+
import software.amazon.smithy.codegen.core.SymbolProvider;
9+
import software.amazon.smithy.codegen.core.directed.CreateContextDirective;
10+
import software.amazon.smithy.codegen.core.directed.CreateSymbolProviderDirective;
11+
import software.amazon.smithy.codegen.core.directed.DirectedCodegen;
12+
import software.amazon.smithy.codegen.core.directed.GenerateEnumDirective;
13+
import software.amazon.smithy.codegen.core.directed.GenerateErrorDirective;
14+
import software.amazon.smithy.codegen.core.directed.GenerateIntEnumDirective;
15+
import software.amazon.smithy.codegen.core.directed.GenerateResourceDirective;
16+
import software.amazon.smithy.codegen.core.directed.GenerateServiceDirective;
17+
import software.amazon.smithy.codegen.core.directed.GenerateStructureDirective;
18+
import software.amazon.smithy.codegen.core.directed.GenerateUnionDirective;
19+
import software.amazon.smithy.docgen.core.generators.ServiceGenerator;
20+
import software.amazon.smithy.utils.SmithyUnstableApi;
21+
22+
/**
23+
* The main entry points for documentation generation.
24+
*/
25+
@SmithyUnstableApi
26+
final class DirectedDocGen implements DirectedCodegen<DocGenerationContext, DocSettings, DocIntegration> {
27+
28+
@Override
29+
public SymbolProvider createSymbolProvider(CreateSymbolProviderDirective<DocSettings> directive) {
30+
return new DocSymbolProvider(directive.model(), directive.settings());
31+
}
32+
33+
@Override
34+
public DocGenerationContext createContext(CreateContextDirective<DocSettings, DocIntegration> directive) {
35+
return new DocGenerationContext(
36+
directive.model(),
37+
directive.settings(),
38+
directive.symbolProvider(),
39+
directive.fileManifest(),
40+
directive.integrations()
41+
);
42+
}
43+
44+
@Override
45+
public void generateService(GenerateServiceDirective<DocGenerationContext, DocSettings> directive) {
46+
new ServiceGenerator().accept(directive);
47+
}
48+
49+
@Override
50+
public void generateStructure(GenerateStructureDirective<DocGenerationContext, DocSettings> directive) {
51+
// no-op for now
52+
}
53+
54+
@Override
55+
public void generateError(GenerateErrorDirective<DocGenerationContext, DocSettings> directive) {
56+
// no-op for now
57+
}
58+
59+
@Override
60+
public void generateUnion(GenerateUnionDirective<DocGenerationContext, DocSettings> directive) {
61+
// no-op for now
62+
}
63+
64+
@Override
65+
public void generateEnumShape(GenerateEnumDirective<DocGenerationContext, DocSettings> directive) {
66+
// no-op for now
67+
}
68+
69+
@Override
70+
public void generateIntEnumShape(GenerateIntEnumDirective<DocGenerationContext, DocSettings> directive) {
71+
// no-op for now
72+
}
73+
74+
@Override
75+
public void generateResource(GenerateResourceDirective<DocGenerationContext, DocSettings> directive) {
76+
// no-op for now
77+
}
78+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.docgen.core;
7+
8+
import java.util.List;
9+
import software.amazon.smithy.build.FileManifest;
10+
import software.amazon.smithy.codegen.core.CodegenContext;
11+
import software.amazon.smithy.codegen.core.SymbolProvider;
12+
import software.amazon.smithy.codegen.core.WriterDelegator;
13+
import software.amazon.smithy.docgen.core.writers.DocWriter;
14+
import software.amazon.smithy.docgen.core.writers.MarkdownWriter;
15+
import software.amazon.smithy.model.Model;
16+
import software.amazon.smithy.utils.SmithyUnstableApi;
17+
18+
/**
19+
* Contextual information that is made available during most parts of documentation
20+
* generation.
21+
*/
22+
@SmithyUnstableApi
23+
public final class DocGenerationContext implements CodegenContext<DocSettings, DocWriter, DocIntegration> {
24+
private final Model model;
25+
private final DocSettings docSettings;
26+
private final SymbolProvider symbolProvider;
27+
private final FileManifest fileManifest;
28+
private final WriterDelegator<DocWriter> writerDelegator;
29+
private final List<DocIntegration> docIntegrations;
30+
31+
/**
32+
* Constructor.
33+
*
34+
* @param model The source model to generate for.
35+
* @param docSettings Settings to customize generation.
36+
* @param symbolProvider The symbol provider to use to turn shapes into symbols.
37+
* @param fileManifest The file manifest to write to.
38+
* @param docIntegrations A list of integrations to apply during generation.
39+
*/
40+
public DocGenerationContext(
41+
Model model,
42+
DocSettings docSettings,
43+
SymbolProvider symbolProvider,
44+
FileManifest fileManifest,
45+
List<DocIntegration> docIntegrations
46+
) {
47+
this.model = model;
48+
this.docSettings = docSettings;
49+
this.symbolProvider = symbolProvider;
50+
this.fileManifest = fileManifest;
51+
// TODO: pull the factory from the integrations
52+
this.writerDelegator = new WriterDelegator<>(fileManifest, symbolProvider, new MarkdownWriter.Factory());
53+
this.docIntegrations = docIntegrations;
54+
}
55+
56+
@Override
57+
public Model model() {
58+
return model;
59+
}
60+
61+
@Override
62+
public DocSettings settings() {
63+
return docSettings;
64+
}
65+
66+
@Override
67+
public SymbolProvider symbolProvider() {
68+
return symbolProvider;
69+
}
70+
71+
@Override
72+
public FileManifest fileManifest() {
73+
return fileManifest;
74+
}
75+
76+
@Override
77+
public WriterDelegator<DocWriter> writerDelegator() {
78+
return writerDelegator;
79+
}
80+
81+
@Override
82+
public List<DocIntegration> integrations() {
83+
return docIntegrations;
84+
}
85+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.docgen.core;
7+
8+
import software.amazon.smithy.codegen.core.SmithyIntegration;
9+
import software.amazon.smithy.docgen.core.writers.DocWriter;
10+
import software.amazon.smithy.utils.SmithyUnstableApi;
11+
12+
/**
13+
* Allows integrating additional functionality into the documentation generator.
14+
*
15+
* <p>{@code DocIntegration}s are loaded as a Java SPI. To make your integration
16+
* discoverable, add a file to {@code META-INF/services} named
17+
* {@code software.amazon.smithy.docgen.core.DocIntegration} where each line is
18+
* the fully-qualified class name of your integrations. Several tools, such as
19+
* {@code AutoService}, can do this for you.
20+
*/
21+
@SmithyUnstableApi
22+
public interface DocIntegration extends SmithyIntegration<DocSettings, DocWriter, DocGenerationContext> {
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.docgen.core;
7+
8+
import java.util.Objects;
9+
import software.amazon.smithy.model.node.ObjectNode;
10+
import software.amazon.smithy.model.shapes.ShapeId;
11+
import software.amazon.smithy.utils.SmithyUnstableApi;
12+
13+
/**
14+
* Settings for documentation generation. These can be set in the
15+
* {@code smithy-build.json} configuration for this plugin.
16+
*
17+
* @param service The shape id of the service to generate documentation for.
18+
*/
19+
@SmithyUnstableApi
20+
public record DocSettings(ShapeId service) {
21+
22+
public DocSettings {
23+
Objects.requireNonNull(service);
24+
}
25+
26+
/**
27+
* Load the settings from an {@code ObjectNode}.
28+
*
29+
* @param pluginSettings the {@code ObjectNode} to load settings from.
30+
* @return loaded settings based on the given node.
31+
*/
32+
public static DocSettings from(ObjectNode pluginSettings) {
33+
return new DocSettings(pluginSettings.expectStringMember("service").expectShapeId());
34+
}
35+
}

0 commit comments

Comments
 (0)