1+ import { dirname } from "path" ;
12import { 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" ;
39import { Component , RendererComponent } from "typedoc/dist/lib/output/components" ;
410import { PageEvent } from "typedoc/dist/lib/output/events" ;
511import { 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