Skip to content

Commit 7fa4974

Browse files
Add documentation and cleanup visiblity
1 parent 2f8fa9e commit 7fa4974

File tree

10 files changed

+89
-6
lines changed

10 files changed

+89
-6
lines changed

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DirectedDocGen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
import software.amazon.smithy.codegen.core.directed.GenerateStructureDirective;
1818
import software.amazon.smithy.codegen.core.directed.GenerateUnionDirective;
1919
import software.amazon.smithy.docgen.core.generators.ServiceGenerator;
20+
import software.amazon.smithy.utils.SmithyUnstableApi;
2021

21-
public class DirectedDocGen implements DirectedCodegen<DocGenerationContext, DocSettings, DocIntegration> {
22+
/**
23+
* The main entry points for documentation generation.
24+
*/
25+
@SmithyUnstableApi
26+
final class DirectedDocGen implements DirectedCodegen<DocGenerationContext, DocSettings, DocIntegration> {
2227

2328
@Override
2429
public SymbolProvider createSymbolProvider(CreateSymbolProviderDirective<DocSettings> directive) {

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocGenerationContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
import software.amazon.smithy.docgen.core.writers.DocWriter;
1414
import software.amazon.smithy.docgen.core.writers.MarkdownWriter;
1515
import software.amazon.smithy.model.Model;
16+
import software.amazon.smithy.utils.SmithyUnstableApi;
1617

18+
/**
19+
* Contextual information that is made available during most parts of documentation
20+
* generation.
21+
*/
22+
@SmithyUnstableApi
1723
public final class DocGenerationContext implements CodegenContext<DocSettings, DocWriter, DocIntegration> {
1824
private final Model model;
1925
private final DocSettings docSettings;

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocIntegration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
import software.amazon.smithy.codegen.core.SmithyIntegration;
99
import software.amazon.smithy.docgen.core.writers.DocWriter;
10+
import software.amazon.smithy.utils.SmithyUnstableApi;
1011

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
1122
public interface DocIntegration extends SmithyIntegration<DocSettings, DocWriter, DocGenerationContext> {
1223
}

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocSettings.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@
88
import java.util.Objects;
99
import software.amazon.smithy.model.node.ObjectNode;
1010
import software.amazon.smithy.model.shapes.ShapeId;
11+
import software.amazon.smithy.utils.SmithyUnstableApi;
1112

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
1220
public record DocSettings(ShapeId service) {
1321

1422
public DocSettings {
1523
Objects.requireNonNull(service);
1624
}
1725

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+
*/
1832
public static DocSettings from(ObjectNode pluginSettings) {
1933
return new DocSettings(pluginSettings.expectStringMember("service").expectShapeId());
2034
}

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocSymbolProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*
5252
*/
5353
@SmithyUnstableApi
54-
public class DocSymbolProvider extends ShapeVisitor.Default<Symbol> implements SymbolProvider {
54+
public final class DocSymbolProvider extends ShapeVisitor.Default<Symbol> implements SymbolProvider {
5555

5656
/**
5757
* The name for a shape symbol's named property containing the shape the symbol

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/SmithyDocPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import software.amazon.smithy.build.SmithyBuildPlugin;
1212
import software.amazon.smithy.codegen.core.directed.CodegenDirector;
1313
import software.amazon.smithy.docgen.core.writers.DocWriter;
14+
import software.amazon.smithy.utils.SmithyInternalApi;
1415

1516
/**
1617
* Generates API documentation from a Smithy model.
1718
*/
19+
@SmithyInternalApi
1820
public final class SmithyDocPlugin implements SmithyBuildPlugin {
1921

2022
private static final Logger LOGGER = Logger.getLogger(SmithyDocPlugin.class.getName());

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/generators/ServiceGenerator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import software.amazon.smithy.docgen.core.DocGenerationContext;
1111
import software.amazon.smithy.docgen.core.DocSettings;
1212
import software.amazon.smithy.model.shapes.ServiceShape;
13-
import software.amazon.smithy.model.traits.TitleTrait;
13+
import software.amazon.smithy.utils.SmithyInternalApi;
1414

15-
public final class ServiceGenerator
16-
implements Consumer<GenerateServiceDirective<DocGenerationContext, DocSettings>> {
15+
/**
16+
* Generates the top-level documentation for a service.
17+
*/
18+
@SmithyInternalApi
19+
public final class ServiceGenerator implements Consumer<GenerateServiceDirective<DocGenerationContext, DocSettings>> {
1720

1821
@Override
1922
public void accept(GenerateServiceDirective<DocGenerationContext, DocSettings> directive) {

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/writers/DocImportContainer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
import software.amazon.smithy.codegen.core.ImportContainer;
99
import software.amazon.smithy.codegen.core.Symbol;
10+
import software.amazon.smithy.utils.SmithyUnstableApi;
1011

12+
/**
13+
* A No-Op import container.
14+
*/
15+
@SmithyUnstableApi
1116
public class DocImportContainer implements ImportContainer {
1217
@Override
1318
public void importSymbol(Symbol symbol, String s) {

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/writers/DocWriter.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,52 @@
77

88
import software.amazon.smithy.codegen.core.SymbolWriter;
99
import software.amazon.smithy.model.shapes.Shape;
10+
import software.amazon.smithy.utils.SmithyUnstableApi;
1011

12+
/**
13+
* A {@code SymbolWriter} provides abstract methods that will be used during
14+
* documentation generation. This allows for other formats to be swapped out
15+
* without much difficulty.
16+
*/
17+
@SmithyUnstableApi
1118
public abstract class DocWriter extends SymbolWriter<DocWriter, DocImportContainer> {
1219
public DocWriter(DocImportContainer importContainer) {
1320
super(importContainer);
1421
}
1522

23+
/**
24+
* Writes out the content of the shape's
25+
* <a href="https://smithy.io/2.0/spec/documentation-traits.html#smithy-api-documentation-trait">
26+
* documentation trait</a>, if present.
27+
*
28+
* <p>Smithy's documentation trait is in the
29+
* <a href="https://spec.commonmark.org">CommonMark</a> format, so writers
30+
* for formats that aren't based on CommonMark will need to convert the value to
31+
* their format. This includes raw HTML, which CommonMark allows.
32+
*
33+
* <p>If the shape doesn't have a documentation trait, the writer MAY write out
34+
* default documentation.
35+
*
36+
* @param shape The shape whose documentation should be written.
37+
* @return returns the writer.
38+
*/
1639
public abstract DocWriter writeShapeDocs(Shape shape);
1740

41+
/**
42+
* Writes a heading with the given content.
43+
*
44+
* <p>{@link #closeHeading} will be called to enable cleaning up any resources or
45+
* context this method creates.
46+
*
47+
* @param content A string to use as the heading content.
48+
* @return returns the writer.
49+
*/
1850
public abstract DocWriter openHeading(String content);
1951

52+
/**
53+
* Closes the current heading, cleaning any context created for the current level.
54+
*
55+
* @return returns the writer.
56+
*/
2057
public abstract DocWriter closeHeading();
2158
}

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/writers/MarkdownWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import software.amazon.smithy.utils.StringUtils;
1313

1414
public final class MarkdownWriter extends DocWriter {
15-
private static int MAX_HEADING_DEPTH = 6;
15+
private static int MAX_HEADING_DEPTH = 5;
1616

1717
private int headerLevel = 0;
1818

0 commit comments

Comments
 (0)