Skip to content

Commit eb496f8

Browse files
Add service interceptors
1 parent f5ce486 commit eb496f8

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,35 @@
99
import software.amazon.smithy.codegen.core.directed.GenerateServiceDirective;
1010
import software.amazon.smithy.docgen.core.DocGenerationContext;
1111
import software.amazon.smithy.docgen.core.DocSettings;
12+
import software.amazon.smithy.docgen.core.sections.ServiceDetailsSection;
13+
import software.amazon.smithy.docgen.core.sections.ServiceSection;
1214
import software.amazon.smithy.model.shapes.ServiceShape;
1315
import software.amazon.smithy.utils.SmithyInternalApi;
1416

1517
/**
16-
* Generates the top-level documentation for a service.
18+
* Generates top-level documentation for the service.
19+
*
20+
* <p>The output of this can be customized in a number of ways. To add details to
21+
* or re-write particular sections, register an interceptor with
22+
* {@link software.amazon.smithy.docgen.core.DocIntegration#interceptors}. The following
23+
* sections are guaranteed to be present:
24+
*
25+
* <ul>
26+
* <li>{@link ServiceDetailsSection}: Enables adding in additional details that are
27+
* inserted after the service's modeled documentation.
28+
* <li>{@link ServiceSection}: Enables re-writing or overwriting the entire page,
29+
* including changes made in other sections.
30+
* </ul>
31+
*
32+
* <p>To change the intermediate format (e.g. from markdown to restructured text),
33+
* a new {@link software.amazon.smithy.docgen.core.DocFormat} needs to be introduced
34+
* via {@link software.amazon.smithy.docgen.core.DocIntegration#docFormats}.
35+
*
36+
* <p>To change the filename or title, implement
37+
* {@link software.amazon.smithy.docgen.core.DocIntegration#decorateSymbolProvider}
38+
* and modify the generated symbol's definition file. See
39+
* {@link software.amazon.smithy.docgen.core.DocSymbolProvider} for details on other
40+
* symbol-driven configuration options.
1741
*/
1842
@SmithyInternalApi
1943
public final class ServiceGenerator implements Consumer<GenerateServiceDirective<DocGenerationContext, DocSettings>> {
@@ -24,10 +48,12 @@ public void accept(GenerateServiceDirective<DocGenerationContext, DocSettings> d
2448
var serviceSymbol = directive.symbolProvider().toSymbol(serviceShape);
2549

2650
directive.context().writerDelegator().useShapeWriter(serviceShape, writer -> {
51+
writer.pushState(new ServiceSection(directive.service(), directive.context()));
2752
writer.openHeading(serviceSymbol.getName());
2853
writer.writeShapeDocs(serviceShape);
29-
54+
writer.injectSection(new ServiceDetailsSection(directive.service(), directive.context()));
3055
writer.closeHeading();
56+
writer.popState();
3157
});
3258
}
3359

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.sections;
7+
8+
import software.amazon.smithy.docgen.core.DocGenerationContext;
9+
import software.amazon.smithy.model.shapes.ServiceShape;
10+
import software.amazon.smithy.utils.CodeSection;
11+
import software.amazon.smithy.utils.SmithyUnstableApi;
12+
13+
/**
14+
* Injects details after the model-defined service documentation.
15+
*
16+
* <p>To overwrite the whole service page, instead intercept the {@link ServiceSection}.
17+
*
18+
* @param service The service shape being generated.
19+
* @param context The context used to generate documentation.
20+
*/
21+
@SmithyUnstableApi
22+
public record ServiceDetailsSection(ServiceShape service, DocGenerationContext context) implements CodeSection {
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.sections;
7+
8+
import software.amazon.smithy.docgen.core.DocGenerationContext;
9+
import software.amazon.smithy.model.shapes.ServiceShape;
10+
import software.amazon.smithy.utils.CodeSection;
11+
import software.amazon.smithy.utils.SmithyUnstableApi;
12+
13+
/**
14+
* Generates the entire Service detail page.
15+
*
16+
* <p>This enables overwriting the entire page. To simply add details after the
17+
* service's trait-defined documentation, instead intercept
18+
* {@link ServiceDetailsSection}.
19+
*
20+
* @param service The service shape being generated.
21+
* @param context The context used to generate documentation.
22+
*/
23+
@SmithyUnstableApi
24+
public record ServiceSection(ServiceShape service, DocGenerationContext context) implements CodeSection {
25+
}

0 commit comments

Comments
 (0)