Skip to content

Commit

Permalink
feat: add table of links to Client Overviews (#210)
Browse files Browse the repository at this point in the history
* feat: add table of links to Client Overviews

* use ifPresent

* fix lint
  • Loading branch information
alicejli authored Oct 10, 2023
1 parent 270775c commit 6145bbe
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,17 @@ static <T extends Element> void populateItemFields(
item.setStatus(lookup.extractStatus(element));
item.setContent(lookup.extractContent(element));
}

/** Does not include syntax contents for Client classes as they are not useful */
static <T extends Element> void populateItemFieldsForClients(
MetadataFileItem item, BaseLookup<T> lookup, T element) {
String name = lookup.extractName(element);
item.setName(name);
item.setNameWithType(lookup.extractNameWithType(element));
item.setFullName(lookup.extractFullName(element));
item.setType(lookup.extractType(element));
item.setJavaType(lookup.extractJavaType(element));
item.setSummary(lookup.extractSummary(element));
item.setStatus(lookup.extractStatus(element));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import static com.microsoft.build.BuilderUtil.LANGS;
import static com.microsoft.build.BuilderUtil.populateItemFields;
import static com.microsoft.build.BuilderUtil.populateItemFieldsForClients;

import com.google.docfx.doclet.RepoMetadata;
import com.microsoft.lookup.ClassItemsLookup;
import com.microsoft.lookup.ClassLookup;
import com.microsoft.lookup.PackageLookup;
Expand Down Expand Up @@ -63,11 +65,12 @@ class ClassBuilder {
this.referenceBuilder = referenceBuilder;
}

List<TocItem> buildFilesForPackage(PackageElement pkg, List<MetadataFile> classMetadataFiles) {
List<TocItem> buildFilesForPackage(
PackageElement pkg, List<MetadataFile> classMetadataFiles, RepoMetadata repoMetadata) {
if (packageLookup.isApiVersionPackage(pkg) && containsAtLeastOneClient(pkg)) {
// API Version package organization is a nested list organized by GAPIC concepts
ApiVersionPackageToc apiVersionPackageToc = new ApiVersionPackageToc();
buildFilesForApiVersionPackage(pkg, apiVersionPackageToc, classMetadataFiles);
buildFilesForApiVersionPackage(pkg, apiVersionPackageToc, classMetadataFiles, repoMetadata);
return apiVersionPackageToc.toList();

} else if (packageLookup.isApiVersionStubPackage(pkg)) {
Expand All @@ -86,7 +89,8 @@ List<TocItem> buildFilesForPackage(PackageElement pkg, List<MetadataFile> classM
private void buildFilesForApiVersionPackage(
Element element,
ApiVersionPackageToc apiVersionPackageToc,
List<MetadataFile> classMetadataFiles) {
List<MetadataFile> classMetadataFiles,
RepoMetadata repoMetadata) {
for (TypeElement classElement : elementUtil.extractSortedElements(element)) {
String uid = classLookup.extractUid(classElement);
String name = classLookup.extractTocName(classElement);
Expand Down Expand Up @@ -119,8 +123,14 @@ private void buildFilesForApiVersionPackage(
apiVersionPackageToc.addUncategorized(tocItem);
}

classMetadataFiles.add(buildClassYmlFile(classElement));
buildFilesForApiVersionPackage(classElement, apiVersionPackageToc, classMetadataFiles);
// Client classes have custom overview
if (isClient(classElement)) {
classMetadataFiles.add(buildClientClassYmlFile(classElement, repoMetadata));
} else {
classMetadataFiles.add(buildClassYmlFile(classElement));
}
buildFilesForApiVersionPackage(
classElement, apiVersionPackageToc, classMetadataFiles, repoMetadata);
}
}

Expand Down Expand Up @@ -191,6 +201,19 @@ void buildFilesForStandardPackage(
}
}

private MetadataFile buildClientClassYmlFile(
TypeElement classElement, RepoMetadata repoMetadata) {
String fileName = classLookup.extractHref(classElement);
MetadataFile classMetadataFile = new MetadataFile(outputPath, fileName);
addClientClassInfo(classElement, classMetadataFile, repoMetadata);
addConstructorsInfo(classElement, classMetadataFile);
addMethodsInfo(classElement, classMetadataFile);
addFieldsInfo(classElement, classMetadataFile);
referenceBuilder.addReferencesInfo(classElement, classMetadataFile);
applyPostProcessing(classMetadataFile);
return classMetadataFile;
}

private MetadataFile buildClassYmlFile(TypeElement classElement) {
String fileName = classLookup.extractHref(classElement);
MetadataFile classMetadataFile = new MetadataFile(outputPath, fileName);
Expand All @@ -203,6 +226,65 @@ private MetadataFile buildClassYmlFile(TypeElement classElement) {
return classMetadataFile;
}

// Does not set Inherited Methods or Inheritance as that information for Client classes is
// superfluous
// Sets updated Client summary with table of links
private void addClientClassInfo(
TypeElement classElement, MetadataFile classMetadataFile, RepoMetadata repoMetadata) {
MetadataFileItem classItem = new MetadataFileItem(LANGS, classLookup.extractUid(classElement));
classItem.setId(classLookup.extractId(classElement));
classItem.setParent(classLookup.extractParent(classElement));
addChildren(classElement, classItem.getChildren());
populateItemFieldsForClients(classItem, classLookup, classElement);
classItem.setPackageName(classLookup.extractPackageName(classElement));
classItem.setTypeParameters(classLookup.extractTypeParameters(classElement));
classItem.setInheritance(classLookup.extractSuperclass(classElement));
String summary = classLookup.extractSummary(classElement);
String summaryTable = createClientOverviewTable(classElement, repoMetadata);
classItem.setSummary(summaryTable + summary);
classItem.setStatus(classLookup.extractStatus(classElement));
classMetadataFile.getItems().add(classItem);
}

private String createClientOverviewTable(TypeElement classElement, RepoMetadata repoMetadata) {
String clientURI = classLookup.extractUid(classElement).replaceAll("\\.", "/");
String githubSourceLink =
repoMetadata.getGithubLink()
+ "/"
+ repoMetadata.getArtifactId()
+ "/src/main/java/"
+ clientURI
+ ".java";
StringBuilder tableBuilder = new StringBuilder();
tableBuilder
.append("<table>")
.append("<tr>")
.append("<td><a href=\"")
.append(githubSourceLink)
.append("\">GitHub Repository</a></td>")
.append("<td><a href=\"")
.append(repoMetadata.getProductDocumentationUri())
.append("\">Product Reference</a></td>");
repoMetadata
.getRestDocumentationUri()
.ifPresent(
restDocumentationURI ->
tableBuilder
.append("<td><a href=\"")
.append(restDocumentationURI)
.append("\">REST Documentation</a></td>"));
repoMetadata
.getRpcDocumentationUri()
.ifPresent(
rpcDocumentationURI ->
tableBuilder
.append("<td><a href=\"")
.append(rpcDocumentationURI)
.append("\">RPC Documentation</a></td>"));
tableBuilder.append("</tr></table>\n\n");
return tableBuilder.toString();
}

private void addClassInfo(TypeElement classElement, MetadataFile classMetadataFile) {
MetadataFileItem classItem = new MetadataFileItem(LANGS, classLookup.extractUid(classElement));
classItem.setId(classLookup.extractId(classElement));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public PackageOverviewFile(
.append(" <tr>\n")
.append(" <td><a href=\"")
.append(githubSourcePackageLink)
.append("\">Github repository</a></td>\n");
.append("\">GitHub Repository</a></td>\n");

// If RPC documentation URI exists, add to the package overview table
if (repoMetadata.getRpcDocumentationUri().isPresent()) {
Expand Down Expand Up @@ -219,30 +219,38 @@ public PackageOverviewFile(
.anyMatch(packageChildSummary -> "Settings".equals(packageChildSummary.getType()));
if (containsSettingsClasses) {
this.SETTINGS_TABLE_HEADER = "## Settings Classes\n";
this.SETTINGS_TABLE_BLURB =
"Settings classes can be used to configure credentials, endpoints, and retry settings for a Client.\n";
if (packageLookup.isApiVersionStubPackage(this.packageElement)) {
this.SETTINGS_TABLE_BLURB =
"Settings classes can be used to configure credentials, endpoints, and retry settings for a Stub.\n";
} else {
this.SETTINGS_TABLE_BLURB =
"Settings classes can be used to configure credentials, endpoints, and retry settings for a Client.\n";
}

this.SETTINGS_TABLE =
createHtmlTable(
"Settings", cloudRADChildElementLinkPrefix, listOfPackageChildrenSummaries);
}

// If Stubs exist in this package, create a table of them
// If package is a Stub package, create a table of Stub classes
boolean containsStubClasses =
listOfPackageChildrenSummaries.stream()
.anyMatch(packageChildSummary -> "Stub".equals(packageChildSummary.getType()));
if (containsStubClasses) {
if (containsStubClasses && (packageLookup.isApiVersionStubPackage(this.packageElement))) {
this.STUB_TABLE_HEADER = "## Stub Classes\n";
this.STUB_TABLE_BLURB = "";
this.STUB_TABLE =
createHtmlTable("Stub", cloudRADChildElementLinkPrefix, listOfPackageChildrenSummaries);
}

// If Callable Factory classes exist in this package, create a table of them
// If package is a Stub package and Callable Factory classes exist in this package, create a
// table of them
boolean containsCallableFactoryClasses =
listOfPackageChildrenSummaries.stream()
.anyMatch(
packageChildSummary -> "CallableFactory".equals(packageChildSummary.getType()));
if (containsCallableFactoryClasses) {
if (containsCallableFactoryClasses
&& (packageLookup.isApiVersionStubPackage(this.packageElement))) {
this.CALLABLE_FACTORY_TABLE_HEADER = "## Callable Factory Classes\n";
this.CALLABLE_FACTORY_TABLE_BLURB = "";
this.CALLABLE_FACTORY_TABLE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private TocItem buildPackage(PackageElement element) {
// build classes/interfaces/enums/exceptions/annotations
packageTocItem
.getItems()
.addAll(classBuilder.buildFilesForPackage(element, classMetadataFiles));
.addAll(classBuilder.buildFilesForPackage(element, classMetadataFiles, repoMetadata));

// build stubs
TocItem stubPackagesItem = new TocItem("Stub packages", "Stub packages", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public LibraryOverviewFile(
+ repoMetadata.getProductDocumentationUri()
+ "\">"
+ repoMetadata.getNamePretty()
+ " product reference</a></td>\n"
+ " Product Reference</a></td>\n"
+ " <td><a href=\""
+ repoMetadata.getGithubLink()
+ "\">Github repository (includes samples)</a></td>\n"
+ "\">GitHub Repository (includes samples)</a></td>\n"
+ " <td><a href=\""
+ repoMetadata.getMavenLink()
+ "\">Maven artifact</a></td>\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Package com.microsoft.samples.agreements (0.18.0)
<table>
<tr>
<td><a href="https://github.com/googleapis/google-cloud-java/tree/main/java-apikeys/google-cloud-apikeys/src/main/java/com/microsoft/samples/agreements">Github repository</a></td>
<td><a href="https://github.com/googleapis/google-cloud-java/tree/main/java-apikeys/google-cloud-apikeys/src/main/java/com/microsoft/samples/agreements">GitHub Repository</a></td>
<td><a href="https://cloud.google.com/api-keys/docs/reference/rpc">RPC Documentation</a></td>
<td><a href="https://cloud.google.com/api-keys/docs/reference/rest">REST Documentation</a></td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Package com.microsoft.samples.commentinheritance (0.18.0)
<table>
<tr>
<td><a href="https://github.com/googleapis/google-cloud-java/tree/main/java-apikeys/google-cloud-apikeys/src/main/java/com/microsoft/samples/commentinheritance">Github repository</a></td>
<td><a href="https://github.com/googleapis/google-cloud-java/tree/main/java-apikeys/google-cloud-apikeys/src/main/java/com/microsoft/samples/commentinheritance">GitHub Repository</a></td>
<td><a href="https://cloud.google.com/api-keys/docs/reference/rpc">RPC Documentation</a></td>
<td><a href="https://cloud.google.com/api-keys/docs/reference/rest">REST Documentation</a></td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Package com.microsoft.samples.google (0.18.0)
<table>
<tr>
<td><a href="https://github.com/googleapis/google-cloud-java/tree/main/java-apikeys/google-cloud-apikeys/src/main/java/com/microsoft/samples/google">Github repository</a></td>
<td><a href="https://github.com/googleapis/google-cloud-java/tree/main/java-apikeys/google-cloud-apikeys/src/main/java/com/microsoft/samples/google">GitHub Repository</a></td>
<td><a href="https://cloud.google.com/api-keys/docs/reference/rpc">RPC Documentation</a></td>
<td><a href="https://cloud.google.com/api-keys/docs/reference/rest">REST Documentation</a></td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,10 @@ items:
fullName: "com.microsoft.samples.google.v1.SpeechClient"
type: "Class"
package: "com.microsoft.samples.google.v1"
summary: "Service Description: Service that implements Google Cloud Speech API.\n\n <p>This class provides the ability to make remote calls to the backing service through method\n calls that map to API methods. Sample code to get started:\n\n <pre class=\"prettyprint lang-java\"><code>\n try (SpeechClient speechClient = SpeechClient.create()) {\n RecognitionConfig config = RecognitionConfig.newBuilder().build();\n RecognitionAudio audio = RecognitionAudio.newBuilder().build();\n RecognizeResponse response = speechClient.recognize(config, audio);\n }\n </code></pre>\n\n <p>Note: close() needs to be called on the SpeechClient object to clean up resources such as\n threads. In the example above, try-with-resources is used, which automatically calls close().\n\n <p>The surface of this class includes several types of Java methods for each of the API's\n methods:\n\n <ol>\n <li>A \"flattened\" method. With this type of method, the fields of the request type have been\n converted into function parameters. It may be the case that not all fields are available as\n parameters, and not every API method will have a flattened method entry point.\n <li>A \"request object\" method. This type of method only takes one parameter, a request object,\n which must be constructed before the call. Not every API method will have a request object\n method.\n <li>A \"callable\" method. This type of method takes no parameters and returns an immutable API\n callable object, which can be used to initiate calls to the service.\n </ol>\n\n <p>See the individual methods for example code.\n\n <p>Many parameters require resource names to be formatted in a particular way. To assist with\n these names, this class includes a format method for each type of name, and additionally a parse\n method to extract the individual identifiers contained within names that are returned.\n\n <p>This class can be customized by passing in a custom instance of SpeechSettings to create().\n For example:\n\n <p>To customize credentials:\n\n <pre class=\"prettyprint lang-java\"><code>\n SpeechSettings speechSettings =\n SpeechSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))\n .build();\n SpeechClient speechClient = SpeechClient.create(speechSettings);\n </code></pre>\n\n <p>To customize the endpoint:\n\n <pre class=\"prettyprint lang-java\"><code>\n SpeechSettings speechSettings = SpeechSettings.newBuilder().setEndpoint(myEndpoint).build();\n SpeechClient speechClient = SpeechClient.create(speechSettings);\n </code></pre>\n\n <p>Please refer to the GitHub repository's samples for more quickstart code snippets."
syntax:
content: "public class SpeechClient implements BackgroundResource"
summary: "<table><tr><td><a href=\"https://github.com/googleapis/google-cloud-java/tree/main/java-apikeys/google-cloud-apikeys/src/main/java/com/microsoft/samples/google/v1/SpeechClient.java\">GitHub Repository</a></td><td><a href=\"https://cloud.google.com/api-keys/\">Product Reference</a></td><td><a href=\"https://cloud.google.com/api-keys/docs/reference/rest\">REST Documentation</a></td><td><a href=\"https://cloud.google.com/api-keys/docs/reference/rpc\">RPC Documentation</a></td></tr></table>\n\nService Description: Service that implements Google Cloud Speech API.\n\n <p>This class provides the ability to make remote calls to the backing service through method\n calls that map to API methods. Sample code to get started:\n\n <pre class=\"prettyprint lang-java\"><code>\n try (SpeechClient speechClient = SpeechClient.create()) {\n RecognitionConfig config = RecognitionConfig.newBuilder().build();\n RecognitionAudio audio = RecognitionAudio.newBuilder().build();\n RecognizeResponse response = speechClient.recognize(config, audio);\n }\n </code></pre>\n\n <p>Note: close() needs to be called on the SpeechClient object to clean up resources such as\n threads. In the example above, try-with-resources is used, which automatically calls close().\n\n <p>The surface of this class includes several types of Java methods for each of the API's\n methods:\n\n <ol>\n <li>A \"flattened\" method. With this type of method, the fields of the request type have been\n converted into function parameters. It may be the case that not all fields are available as\n parameters, and not every API method will have a flattened method entry point.\n <li>A \"request object\" method. This type of method only takes one parameter, a request object,\n which must be constructed before the call. Not every API method will have a request object\n method.\n <li>A \"callable\" method. This type of method takes no parameters and returns an immutable API\n callable object, which can be used to initiate calls to the service.\n </ol>\n\n <p>See the individual methods for example code.\n\n <p>Many parameters require resource names to be formatted in a particular way. To assist with\n these names, this class includes a format method for each type of name, and additionally a parse\n method to extract the individual identifiers contained within names that are returned.\n\n <p>This class can be customized by passing in a custom instance of SpeechSettings to create().\n For example:\n\n <p>To customize credentials:\n\n <pre class=\"prettyprint lang-java\"><code>\n SpeechSettings speechSettings =\n SpeechSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))\n .build();\n SpeechClient speechClient = SpeechClient.create(speechSettings);\n </code></pre>\n\n <p>To customize the endpoint:\n\n <pre class=\"prettyprint lang-java\"><code>\n SpeechSettings speechSettings = SpeechSettings.newBuilder().setEndpoint(myEndpoint).build();\n SpeechClient speechClient = SpeechClient.create(speechSettings);\n </code></pre>\n\n <p>Please refer to the GitHub repository's samples for more quickstart code snippets."
syntax: {}
inheritance:
- "java.lang.Object"
implements:
- "com.google.api.gax.core.BackgroundResource"
inheritedMembers:
- "java.lang.Object.clone()"
- "java.lang.Object.equals(java.lang.Object)"
- "java.lang.Object.finalize()"
- "java.lang.Object.getClass()"
- "java.lang.Object.hashCode()"
- "java.lang.Object.notify()"
- "java.lang.Object.notifyAll()"
- "java.lang.Object.toString()"
- "java.lang.Object.wait()"
- "java.lang.Object.wait(long)"
- "java.lang.Object.wait(long,int)"
- uid: "com.microsoft.samples.google.v1.SpeechClient.SpeechClient(com.google.cloud.speech.v1p1beta1.stub.SpeechStub)"
id: "SpeechClient(com.google.cloud.speech.v1p1beta1.stub.SpeechStub)"
parent: "com.microsoft.samples.google.v1.SpeechClient"
Expand Down
Loading

0 comments on commit 6145bbe

Please sign in to comment.