Skip to content

docs(clients): remove excessive STS and SSO client from TOC #2254

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

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { dirname } from "path";
import { ReferenceType } from "typedoc/dist/lib/models";
import { DeclarationReflection, Reflection, ReflectionKind } from "typedoc/dist/lib/models/reflections";
import {
DeclarationReflection,
ProjectReflection,
Reflection,
ReflectionKind,
} from "typedoc/dist/lib/models/reflections";
import { Component, RendererComponent } from "typedoc/dist/lib/output/components";
import { PageEvent } from "typedoc/dist/lib/output/events";
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem";
Expand All @@ -12,6 +18,7 @@ export class SdkClientTocPlugin extends RendererComponent {
private commandsNavigationItem?: NavigationItem;
private clientsNavigationItem?: NavigationItem;
private paginatorsNavigationItem?: NavigationItem;
private clientDir?: string;

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

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

if (index < trail.length - 1 && children.length > 40) {
const child = trail[index + 1];
Expand Down Expand Up @@ -131,4 +141,16 @@ export class SdkClientTocPlugin extends RendererComponent {
this.commandsNavigationItem?.children.sort((childA, childB) => childA.title.localeCompare(childB.title));
}
}

private loadClientDir(model: Reflection) {
let projectModel = (model as any) as ProjectReflection;
while (projectModel.constructor.name !== "ProjectReflection" && !projectModel.kindOf(ReflectionKind.SomeModule)) {
projectModel = projectModel.parent as ProjectReflection;
}
const clientsDirectory = (projectModel as ProjectReflection).directory.directories["clients"].directories;
const dir = Object.values(clientsDirectory).filter((directory) =>
directory?.files.find((file) => file.name.endsWith("Client.ts"))
)[0];
return dirname(dir?.files.find((file) => file.name.endsWith("Client.ts")).fullFileName);
}
}