-
Notifications
You must be signed in to change notification settings - Fork 239
Update smithy-docgen to consume shared snippet files to render examples #2894
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
base: main
Are you sure you want to change the base?
Conversation
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.
.changes/next-release/feature-3c70351cce599e85b810d4418fee8e5ca661436e.json
Show resolved
Hide resolved
.changes/next-release/feature-df6f8fb30971b29b76010e7143df11affcb9618f.json
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
0976ed9 to
dfc75de
Compare
yasmewad
left a comment
There was a problem hiding this 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))); |
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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?
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.