Skip to content

Commit b7ff842

Browse files
authored
docs(clients): remove excessive STS and SSO client from TOC (#2254)
1 parent 32b563b commit b7ff842

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

packages/client-documentation-generator/src/sdk-client-toc-plugin.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import { dirname } from "path";
12
import { ReferenceType } from "typedoc/dist/lib/models";
2-
import { DeclarationReflection, Reflection, ReflectionKind } from "typedoc/dist/lib/models/reflections";
3+
import {
4+
DeclarationReflection,
5+
ProjectReflection,
6+
Reflection,
7+
ReflectionKind,
8+
} from "typedoc/dist/lib/models/reflections";
39
import { Component, RendererComponent } from "typedoc/dist/lib/output/components";
410
import { PageEvent } from "typedoc/dist/lib/output/events";
511
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem";
@@ -12,6 +18,7 @@ export class SdkClientTocPlugin extends RendererComponent {
1218
private commandsNavigationItem?: NavigationItem;
1319
private clientsNavigationItem?: NavigationItem;
1420
private paginatorsNavigationItem?: NavigationItem;
21+
private clientDir?: string;
1522

1623
initialize() {
1724
// disable existing toc plugin
@@ -57,8 +64,10 @@ export class SdkClientTocPlugin extends RendererComponent {
5764
model.kindOf(ReflectionKind.Class) &&
5865
model.getFullName() !== "Client" && // Exclude the Smithy Client class.
5966
(model.name.endsWith("Client") /* Modular client like S3Client */ ||
60-
(extendedTypes.length === 1 &&
61-
(extendedTypes[0] as ReferenceType).name.endsWith("Client"))) /* Legacy client like S3 */
67+
extendedTypes.filter((reference) => (reference as ReferenceType).name === `${model.name}Client`).length > 0) &&
68+
/* Filter out other client classes that not sourced from the same directory as current client. e.g. STS, SSO */
69+
this.clientDir &&
70+
dirname(model.sources[0]?.file.fullFileName) === this.clientDir
6271
);
6372
}
6473

@@ -93,6 +102,7 @@ export class SdkClientTocPlugin extends RendererComponent {
93102
buildToc(model: Reflection, trail: Reflection[], parent: NavigationItem, restriction?: string[]) {
94103
const index = trail.indexOf(model);
95104
const children = model["children"] || [];
105+
if (!this.clientDir) this.clientDir = this.loadClientDir(model);
96106

97107
if (index < trail.length - 1 && children.length > 40) {
98108
const child = trail[index + 1];
@@ -131,4 +141,16 @@ export class SdkClientTocPlugin extends RendererComponent {
131141
this.commandsNavigationItem?.children.sort((childA, childB) => childA.title.localeCompare(childB.title));
132142
}
133143
}
144+
145+
private loadClientDir(model: Reflection) {
146+
let projectModel = (model as any) as ProjectReflection;
147+
while (projectModel.constructor.name !== "ProjectReflection" && !projectModel.kindOf(ReflectionKind.SomeModule)) {
148+
projectModel = projectModel.parent as ProjectReflection;
149+
}
150+
const clientsDirectory = (projectModel as ProjectReflection).directory.directories["clients"].directories;
151+
const dir = Object.values(clientsDirectory).filter((directory) =>
152+
directory?.files.find((file) => file.name.endsWith("Client.ts"))
153+
)[0];
154+
return dirname(dir?.files.find((file) => file.name.endsWith("Client.ts")).fullFileName);
155+
}
134156
}

0 commit comments

Comments
 (0)