X Tutup
Skip to content

Commit d395618

Browse files
committed
Fix issue with duplicate yaml references
1 parent 7b67d84 commit d395618

File tree

7 files changed

+81
-18
lines changed

7 files changed

+81
-18
lines changed

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ export class YamlDocumenter {
116116
}
117117

118118
private _visitApiItems(apiItem: ApiDocumentedItem, parentYamlFile: IYamlApiFile | undefined): boolean {
119+
let savedYamlReferences: IYamlReferences | undefined;
120+
if (!this._shouldEmbed(apiItem.kind)) {
121+
savedYamlReferences = this._yamlReferences;
122+
this._yamlReferences = undefined;
123+
}
124+
119125
const yamlItem: IYamlItem | undefined = this._generateYamlItem(apiItem);
120126
if (!yamlItem) {
121127
return false;
@@ -155,17 +161,12 @@ export class YamlDocumenter {
155161
}
156162
}
157163

158-
if (this._yamlReferences) {
159-
if (this._yamlReferences.references.length > 0) {
160-
if (newYamlFile.references) {
161-
newYamlFile.references = [...newYamlFile.references, ...this._yamlReferences.references];
162-
} else {
163-
newYamlFile.references = this._yamlReferences.references;
164-
}
165-
}
166-
this._yamlReferences = undefined;
164+
if (this._yamlReferences && this._yamlReferences.references.length > 0) {
165+
newYamlFile.references = this._yamlReferences.references;
167166
}
168167

168+
this._yamlReferences = savedYamlReferences;
169+
169170
const yamlFilePath: string = this._getYamlFilePath(apiItem);
170171

171172
if (apiItem.kind === ApiItemKind.Package) {
@@ -175,15 +176,10 @@ export class YamlDocumenter {
175176
this._writeYamlFile(newYamlFile, yamlFilePath, 'UniversalReference', yamlApiSchema);
176177

177178
if (parentYamlFile) {
178-
if (!parentYamlFile.references) {
179-
parentYamlFile.references = [];
180-
}
181-
182-
parentYamlFile.references.push({
183-
uid: this._getUid(apiItem),
184-
name: this._getYamlItemName(apiItem)
185-
});
186-
179+
this._recordYamlReference(
180+
this._ensureYamlReferences(),
181+
this._getUid(apiItem),
182+
this._getYamlItemName(apiItem));
187183
}
188184
}
189185

build-tests/api-documenter-test/etc/api-documenter-test.api.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,34 @@
16021602
}
16031603
],
16041604
"implementsTokenRanges": []
1605+
},
1606+
{
1607+
"kind": "Function",
1608+
"canonicalReference": "api-documenter-test!yamlReferenceUniquenessTest:function(1)",
1609+
"docComment": "/**\n * @public\n */\n",
1610+
"excerptTokens": [
1611+
{
1612+
"kind": "Content",
1613+
"text": "export declare function yamlReferenceUniquenessTest(): "
1614+
},
1615+
{
1616+
"kind": "Reference",
1617+
"text": "IDocInterface1",
1618+
"canonicalReference": "api-documenter-test!IDocInterface1:interface"
1619+
},
1620+
{
1621+
"kind": "Content",
1622+
"text": ";"
1623+
}
1624+
],
1625+
"returnTypeTokenRange": {
1626+
"startIndex": 1,
1627+
"endIndex": 2
1628+
},
1629+
"releaseTag": "Public",
1630+
"overloadIndex": 1,
1631+
"parameters": [],
1632+
"name": "yamlReferenceUniquenessTest"
16051633
}
16061634
]
16071635
}

build-tests/api-documenter-test/etc/api-documenter-test.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,8 @@ export class SystemEvent {
123123
addHandler(handler: () => void): void;
124124
}
125125

126+
// @public (undocumented)
127+
export function yamlReferenceUniquenessTest(): IDocInterface1;
128+
126129

127130
```

build-tests/api-documenter-test/etc/markdown/api-documenter-test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This project tests various documentation generation scenarios and doc comment sy
2828
| Function | Description |
2929
| --- | --- |
3030
| [globalFunction(x)](./api-documenter-test.globalfunction.md) | An exported function |
31+
| [yamlReferenceUniquenessTest()](./api-documenter-test.yamlreferenceuniquenesstest.md) | |
3132

3233
## Interfaces
3334

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [api-documenter-test](./api-documenter-test.md) &gt; [yamlReferenceUniquenessTest](./api-documenter-test.yamlreferenceuniquenesstest.md)
4+
5+
## yamlReferenceUniquenessTest() function
6+
7+
8+
<b>Signature:</b>
9+
10+
```typescript
11+
export declare function yamlReferenceUniquenessTest(): IDocInterface1;
12+
```
13+
<b>Returns:</b>
14+
15+
`IDocInterface1`
16+

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ items:
2424
- 'api-documenter-test!IDocInterface6:interface'
2525
- 'api-documenter-test!OuterNamespace.InnerNamespace.nestedFunction:function(1)'
2626
- 'api-documenter-test!SystemEvent:class'
27+
- 'api-documenter-test!yamlReferenceUniquenessTest:function(1)'
2728
- uid: 'api-documenter-test!globalFunction:function(1)'
2829
summary: An exported function
2930
name: globalFunction(x)
@@ -60,6 +61,18 @@ items:
6061
description: ''
6162
type:
6263
- number
64+
- uid: 'api-documenter-test!yamlReferenceUniquenessTest:function(1)'
65+
name: yamlReferenceUniquenessTest()
66+
fullName: yamlReferenceUniquenessTest()
67+
langs:
68+
- typeScript
69+
type: function
70+
syntax:
71+
content: 'export declare function yamlReferenceUniquenessTest(): IDocInterface1;'
72+
return:
73+
type:
74+
- 'api-documenter-test!IDocInterface1:interface'
75+
description: ''
6376
references:
6477
- uid: 'api-documenter-test!DocBaseClass:class'
6578
name: DocBaseClass

build-tests/api-documenter-test/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
export * from './DocClass1';
1414
export * from './DocEnums';
15+
import { IDocInterface1 } from './DocClass1';
1516

1617
/**
1718
* A type alias
@@ -55,3 +56,8 @@ export namespace OuterNamespace {
5556
*/
5657
export let nestedVariable: boolean = false;
5758
}
59+
60+
/**
61+
* @public
62+
*/
63+
export declare function yamlReferenceUniquenessTest(): IDocInterface1;

0 commit comments

Comments
 (0)
X Tutup