-
Notifications
You must be signed in to change notification settings - Fork 970
Add code example links to individual method documentation in API refs guide #6626
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: master
Are you sure you want to change the base?
Add code example links to individual method documentation in API refs guide #6626
Conversation
codegen/src/main/java/software/amazon/awssdk/codegen/internal/DocumentationUtils.java
Outdated
Show resolved
Hide resolved
codegen/src/main/java/software/amazon/awssdk/codegen/internal/DocumentationUtils.java
Outdated
Show resolved
Hide resolved
| * @param operationName the name of the operation to find an example for | ||
| * @return a '@see also' HTML link to the code example, or empty string if no example found | ||
| */ | ||
| public static String createLinkToCodeExample(Metadata metadata, String operationName) { |
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.
Can we add some codegen tests? we can create a mock example.json file
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.
Any updates?
| return String.format("<a href=\"%s\" target=\"_top\">Code Example</a>", url); | ||
| } | ||
|
|
||
| return ""; |
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.
Should we just use null to indicate there's no example, so here, we'd return Optional.empty()?
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.
Hmm, we're not using null here. we're returning an empty string ("") right, so based on the check we have in OperationDocProvider.java, it wont show example when its empty string.
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.
Right, I was suggesting using null to denote lack of example instead of empty string
codegen/src/main/java/software/amazon/awssdk/codegen/internal/DocumentationUtils.java
Outdated
Show resolved
Hide resolved
codegen/src/main/java/software/amazon/awssdk/codegen/internal/DocumentationUtils.java
Outdated
Show resolved
Hide resolved
|
| docBuilder.see(crosslink); | ||
| } | ||
|
|
||
| String exampleMetaPath = "software/amazon/awssdk/codegen/example-meta.json"; |
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.
Can we create a constant?
| javadoc.append("<p>The following code examples show how to use this service with the AWS SDK for Java v2:</p>") | ||
| .append("\n"); | ||
|
|
||
| Map<String, String> categoryMapping = new java.util.LinkedHashMap<>(); |
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.
Can we initialize this map in ctor?
| return String.format("<a href=\"%s\" target=\"_top\">Code Example</a>", url); | ||
| } | ||
|
|
||
| return ""; |
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.
Right, I was suggesting using null to denote lack of example instead of empty string
| /** | ||
| * Emits the package-info.java for the base service package. Includes the service | ||
| * level documentation. | ||
| */ |
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.
Can we update javadoc?
| StringBuilder result = new StringBuilder(); | ||
| String[] lines = codeExamplesJavadoc.split("\n"); | ||
| for (String line : lines) { | ||
| if (!line.trim().isEmpty()) { | ||
| result.append(line); | ||
| if (!line.equals(lines[lines.length - 1])) { | ||
| result.append(System.lineSeparator()).append(" * "); | ||
| } | ||
| } | ||
| } |
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.
It's not straighforward what this block is trying to do. Can we create a separate method with documentation?
|
|
||
|
|
||
| private String generateCodeExamplesJavadoc(List<DocumentationUtils.ExampleData> examples) { | ||
| Map<String, List<DocumentationUtils.ExampleData>> categorizedExamples = new java.util.LinkedHashMap<>(); |
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.
Let's replace qualified name with import. new java.util.LinkedHashMap<>(); -> new LinkedHashMap<>())
Can be shortened to the following:
Map<String, List<DocumentationUtils.ExampleData>> categorizedExamples =
examples.stream().collect(Collectors.groupingBy(DocumentationUtils.ExampleData::getCategory,
LinkedHashMap::new,
Collectors.toList()));| for (Map.Entry<String, String> entry : categoryMapping.entrySet()) { | ||
| String category = entry.getKey(); | ||
| String displayName = entry.getValue(); | ||
| List<DocumentationUtils.ExampleData> categoryExamples = categorizedExamples.get(category); | ||
| if (categoryExamples != null && !categoryExamples.isEmpty()) { | ||
| appendCategorySection(javadoc, displayName, categoryExamples); | ||
| } | ||
| } | ||
|
|
||
| for (Map.Entry<String, List<DocumentationUtils.ExampleData>> entry : categorizedExamples.entrySet()) { | ||
| String category = entry.getKey(); | ||
| if (!categoryMapping.containsKey(category)) { | ||
| List<DocumentationUtils.ExampleData> categoryExamples = entry.getValue(); | ||
| if (!categoryExamples.isEmpty()) { | ||
| appendCategorySection(javadoc, category, categoryExamples); | ||
| } | ||
| } | ||
| } |
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.
It's not very straighforward what those two loop do. Can we create separat methods with descriptive method names (ideally with javadocs).
| private static Map<String, JsonNode> serviceNodeCache; | ||
| private static Map<String, String> normalizedServiceKeyMap; |
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.
Doesn't seem thread safe. Suggesting creating a class instead of using static util methods for the new functionalities.


Add code examples near the individual method documentation in Java SDK API Refs guide
Motivation and Context
Enhance the Java SDK API Refs documentation to include code examples.
Modifications
Added
createLinkToCodeExamplemethod toDocumentationUtils.javato generate code example links from example-meta.jsonUpdated
OperationDocProvider.javawhich is in codegen and responsible for generating Javadoc documentation for individual operation methods to include "Code Example" links in method @see sections, appearing after AWS API Documentation linksTesting
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License