Skip to content

Commit 9643f62

Browse files
committed
Fix up _getYamlItemName() handling of nested namespaces
1 parent 93c35bb commit 9643f62

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

apps/api-documenter/src/documenters/YamlDocumenter.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,46 @@ export class YamlDocumenter {
650650

651651
private _getYamlItemName(apiItem: ApiItem): string {
652652
if (apiItem.parent && apiItem.parent.kind === ApiItemKind.Namespace) {
653-
// For members a namespace, show the full name excluding the package part:
654-
// Example: excel.Excel.Binding --> Excel.Binding
655-
return apiItem.getScopedNameWithinPackage();
653+
// If the immediate parent is a namespace, then add the namespaces to the name. For example:
654+
//
655+
// // Name: "N1"
656+
// export namespace N1 {
657+
// // Name: "N1.N2"
658+
// export namespace N2 {
659+
// // Name: "N1.N2.f(x,y)"
660+
// export function f(x: string, y: string): string {
661+
// return x + y;
662+
// }
663+
//
664+
//
665+
// // Name: "N1.N2.C"
666+
// export class C {
667+
// // Name: "member(x,y)" <===========
668+
// public member(x: string, y: string): string {
669+
// return x + y;
670+
// }
671+
// }
672+
// }
673+
// }
674+
//
675+
// In the above example, "member(x, y)" does not appear as "N1.N2.C.member(x,y)" because YamlDocumenter
676+
// embeds this entry in the web page for "N1.N2.C", so the container is obvious. Whereas "N1.N2.f(x,y)"
677+
// needs to be qualified because the DocFX template doesn't make pages for namespaces. Instead, they get
678+
// flattened into the package's page.
679+
const nameParts: string[] = [ Utilities.getConciseSignature(apiItem) ];
680+
681+
for (let current: ApiItem | undefined = apiItem.parent; current; current = current.parent) {
682+
if (current.kind !== ApiItemKind.Namespace) {
683+
break;
684+
}
685+
686+
nameParts.unshift(current.displayName);
687+
}
688+
689+
return nameParts.join('.');
690+
} else {
691+
return Utilities.getConciseSignature(apiItem);
656692
}
657-
return Utilities.getConciseSignature(apiItem);
658693
}
659694

660695
private _getYamlFilePath(apiItem: ApiItem): string {

build-tests/api-documenter-test/etc/yaml/api-documenter-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ items:
4444
- number
4545
- uid: 'api-documenter-test!OuterNamespace.InnerNamespace.nestedFunction:function(1)'
4646
summary: A function inside a namespace
47-
name: OuterNamespace.InnerNamespace.nestedFunction()
48-
fullName: OuterNamespace.InnerNamespace.nestedFunction()
47+
name: OuterNamespace.InnerNamespace.nestedFunction(x)
48+
fullName: OuterNamespace.InnerNamespace.nestedFunction(x)
4949
langs:
5050
- typeScript
5151
type: function

0 commit comments

Comments
 (0)