Skip to content

Conversation

@JordonPhillips
Copy link
Contributor

This updates smithy-docgen to pull examples from shared snippet files generated by other build plugins. It pulls these from both explicit configuration as well as from the projection-local shared space.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This makes `DefaultBuilderRef` public so that it can be sued for
nested collections outside of smithy-utils. Nested collections can
be quite tricky to handle properly, and having to re-write all the
safe borrowing code for them shouldn't be necessary.
This adds a shared file definition for sharing generated snippets for
things like the examples trait. These shared definitions will be
consumed by smithy-docgen when generating docs.
This updates smithy-docgen to load snippets from either shared snippet
files or explicitly configured snippet files. These are used to fill out
the examples from the examples trait.
@JordonPhillips JordonPhillips requested a review from a team as a code owner December 16, 2025 17:40
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@yasmewad yasmewad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is failing too.

* @return Returns a SnippetConfig based on the given file.
*/
public static SnippetConfig load(Path path) {
return fromNode(Node.parse(IoUtils.readUtf8File(path)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Do we need to add some failure checking here with a more elegant message in terms of what went wrong exactly, was it incorrect path, or the file had parsing errors? Or is it just handled in the fromNode and Node.parse

Comment on lines +157 to +163
LinkedHashMap<ShapeId, Map<ShapeId, List<Snippet>>> copy = new LinkedHashMap<>();
for (Map.Entry<ShapeId, Map<ShapeId, List<Snippet>>> entry : snippets.entrySet()) {
LinkedHashMap<ShapeId, List<Snippet>> serviceCopy = new LinkedHashMap<>();
for (Map.Entry<ShapeId, List<Snippet>> serviceEntry : entry.getValue().entrySet()) {
serviceCopy.put(serviceEntry.getKey(), new ArrayList<>(serviceEntry.getValue()));
}
copy.put(entry.getKey(), serviceCopy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the immutableWrapSnippetMap share same logic other than the last part. Let's move them out to a new method and use it instead?


@Test
public void roundTrips() throws Exception {
Node expected = Node.parse(getClass().getResource("snippet-config.json").openStream());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for my learning: Since we open this as a stream do we need to close the stream too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants