@@ -75,13 +75,16 @@ export class YamlDocumenter {
7575
7676 private _apiItemsByCanonicalReference : Map < string , ApiItem > ;
7777 private _yamlReferences : IYamlReferences | undefined ;
78+ // Keeps track of ApiItems whose names collide with one or more siblings.
79+ private _collisions : Set < ApiItem > ;
7880
7981 private _outputFolder : string ;
8082
8183 public constructor ( apiModel : ApiModel ) {
8284 this . _apiModel = apiModel ;
8385 this . _markdownEmitter = new CustomMarkdownEmitter ( this . _apiModel ) ;
8486 this . _apiItemsByCanonicalReference = new Map < string , ApiItem > ( ) ;
87+ this . _collisions = new Set < ApiItem > ( ) ;
8588
8689 this . _initApiItems ( ) ;
8790 }
@@ -232,25 +235,18 @@ export class YamlDocumenter {
232235 if ( apiItem . kind === ApiItemKind . Namespace ) {
233236 // Namespaces don't have nodes yet
234237 tocItem = {
235- name : apiItem . displayName
238+ name : this . _getTocItemName ( apiItem )
236239 } ;
237240 } else {
238241 if ( this . _shouldEmbed ( apiItem . kind ) ) {
239242 // Don't generate table of contents items for embedded definitions
240243 continue ;
241244 }
242245
243- if ( apiItem . kind === ApiItemKind . Package ) {
244- tocItem = {
245- name : PackageName . getUnscopedName ( apiItem . displayName ) ,
246- uid : this . _getUid ( apiItem )
247- } ;
248- } else {
249- tocItem = {
250- name : apiItem . displayName ,
251- uid : this . _getUid ( apiItem )
252- } ;
253- }
246+ tocItem = {
247+ name : this . _getTocItemName ( apiItem ) ,
248+ uid : this . _getUid ( apiItem )
249+ } ;
254250 }
255251
256252 tocItems . push ( tocItem ) ;
@@ -271,6 +267,20 @@ export class YamlDocumenter {
271267 return tocItems ;
272268 }
273269
270+ /** @virtual */
271+ protected _getTocItemName ( apiItem : ApiItem ) : string {
272+ let name : string = apiItem . displayName ;
273+ if ( apiItem . kind === ApiItemKind . Package ) {
274+ name = PackageName . getUnscopedName ( name ) ;
275+ }
276+
277+ if ( this . _collisions . has ( apiItem ) ) {
278+ name += ` (${ apiItem . kind } )` ;
279+ }
280+
281+ return name ;
282+ }
283+
274284 protected _shouldEmbed ( apiItemKind : ApiItemKind ) : boolean {
275285 switch ( apiItemKind ) {
276286 case ApiItemKind . Class :
@@ -591,7 +601,6 @@ export class YamlDocumenter {
591601 */
592602 private _initApiItems ( ) : void {
593603 this . _initApiItemsRecursive ( this . _apiModel ) ;
594-
595604 }
596605
597606 /**
@@ -604,12 +613,39 @@ export class YamlDocumenter {
604613
605614 // Recurse container members
606615 if ( ApiItemContainerMixin . isBaseClassOf ( apiItem ) ) {
616+ const singletons : Map < string , ApiItem > = new Map < string , ApiItem > ( ) ;
617+ const collidingNames : Set < string > = new Set < string > ( ) ;
607618 for ( const apiMember of apiItem . members ) {
619+ this . _trackCollisionsWithSiblings ( apiMember , singletons , collidingNames ) ;
608620 this . _initApiItemsRecursive ( apiMember ) ;
609621 }
610622 }
611623 }
612624
625+ private _trackCollisionsWithSiblings (
626+ apiItem : ApiItem ,
627+ singletons ?: Map < string , ApiItem > ,
628+ collidingNames ?: Set < string >
629+ ) : void {
630+ if ( singletons && collidingNames ) {
631+ if ( ! collidingNames . has ( apiItem . displayName ) ) {
632+ const collision : ApiItem | undefined = singletons . get ( apiItem . displayName ) ;
633+ if ( ! collision ) {
634+ // No collision. Record this singleton entry.
635+ singletons . set ( apiItem . displayName , apiItem ) ;
636+ return ;
637+ }
638+ // First collision. Record the colliding name.
639+ collidingNames . add ( apiItem . displayName ) ;
640+ singletons . delete ( apiItem . displayName ) ;
641+ // Record the initial entry.
642+ this . _collisions . add ( collision ) ;
643+ }
644+ // Record the colliding entry.
645+ this . _collisions . add ( apiItem ) ;
646+ }
647+ }
648+
613649 private _ensureYamlReferences ( ) : IYamlReferences {
614650 if ( ! this . _yamlReferences ) {
615651 this . _yamlReferences = {
@@ -803,7 +839,13 @@ export class YamlDocumenter {
803839 break ;
804840 }
805841 }
806- return path . join ( this . _outputFolder , result + '.yml' ) ;
842+
843+ let disambiguator : string = '' ;
844+ if ( this . _collisions . has ( apiItem ) ) {
845+ disambiguator = `-${ apiItem . kind . toLowerCase ( ) } ` ;
846+ }
847+
848+ return path . join ( this . _outputFolder , result + disambiguator + '.yml' ) ;
807849 }
808850
809851 private _deleteOldOutputFiles ( ) : void {
0 commit comments