Skip to content

Commit a2a2cf1

Browse files
committed
Add support for emitting type parameters to yaml
1 parent 90bce40 commit a2a2cf1

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import {
3333
ApiMethodSignature,
3434
ApiConstructor,
3535
ApiFunction,
36-
ApiReturnTypeMixin
36+
ApiReturnTypeMixin,
37+
ApiTypeParameterListMixin
3738
} from '@microsoft/api-extractor-model';
3839

3940
import {
@@ -328,11 +329,11 @@ export class YamlDocumenter {
328329
break;
329330
case ApiItemKind.Class:
330331
yamlItem.type = 'class';
331-
this._populateYamlClassOrInterface(yamlItem, apiItem);
332+
this._populateYamlClassOrInterface(yamlItem, apiItem as ApiClass);
332333
break;
333334
case ApiItemKind.Interface:
334335
yamlItem.type = 'interface';
335-
this._populateYamlClassOrInterface(yamlItem, apiItem);
336+
this._populateYamlClassOrInterface(yamlItem, apiItem as ApiInterface);
336337
break;
337338
case ApiItemKind.Method:
338339
case ApiItemKind.MethodSignature:
@@ -379,7 +380,27 @@ export class YamlDocumenter {
379380
return yamlItem as IYamlItem;
380381
}
381382

382-
private _populateYamlClassOrInterface(yamlItem: Partial<IYamlItem>, apiItem: ApiDocumentedItem): void {
383+
private _populateYamlTypeParameters(apiItem: ApiTypeParameterListMixin): IYamlParameter[] {
384+
const typeParameters: IYamlParameter[] = [];
385+
for (const apiTypeParameter of apiItem.typeParameters) {
386+
const typeParameter: IYamlParameter = {
387+
id: apiTypeParameter.name
388+
};
389+
390+
if (apiTypeParameter.tsdocTypeParamBlock) {
391+
typeParameter.description = this._renderMarkdown(apiTypeParameter.tsdocTypeParamBlock.content, apiItem);
392+
}
393+
394+
if (apiTypeParameter.constraintExcerpt) {
395+
typeParameter.type = [ this._linkToUidIfPossible(apiTypeParameter.constraintExcerpt.text) ];
396+
}
397+
398+
typeParameters.push(typeParameter);
399+
}
400+
return typeParameters;
401+
}
402+
403+
private _populateYamlClassOrInterface(yamlItem: Partial<IYamlItem>, apiItem: ApiClass | ApiInterface): void {
383404
if (apiItem instanceof ApiClass) {
384405
if (apiItem.extendsType) {
385406
yamlItem.extends = [ this._linkToUidIfPossible(apiItem.extendsType.excerpt.text) ];
@@ -397,6 +418,11 @@ export class YamlDocumenter {
397418
yamlItem.extends.push(this._linkToUidIfPossible(extendsType.excerpt.text));
398419
}
399420
}
421+
422+
const typeParameters: IYamlParameter[] = this._populateYamlTypeParameters(apiItem);
423+
if (typeParameters.length) {
424+
yamlItem.syntax = { typeParameters };
425+
}
400426
}
401427

402428
if (apiItem.tsdocComment) {
@@ -462,6 +488,14 @@ export class YamlDocumenter {
462488
if (parameters.length) {
463489
syntax.parameters = parameters;
464490
}
491+
492+
if (ApiTypeParameterListMixin.isBaseClassOf(apiItem)) {
493+
const typeParameters: IYamlParameter[] = this._populateYamlTypeParameters(apiItem);
494+
if (typeParameters.length) {
495+
syntax.typeParameters = typeParameters;
496+
}
497+
}
498+
465499
}
466500

467501
private _populateYamlProperty(yamlItem: Partial<IYamlItem>, apiItem: ApiPropertyItem): void {

apps/api-documenter/src/yaml/IYamlApiFile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,6 @@ export interface IYamlSource {
112112
export interface IYamlSyntax {
113113
content?: string;
114114
parameters?: IYamlParameter[];
115+
typeParameters?: IYamlParameter[];
115116
return?: IYamlReturn;
116117
}

apps/api-documenter/src/yaml/typescript.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@
221221
"content": {
222222
"type": "string"
223223
},
224+
"typeParameters": {
225+
"type": "array",
226+
"items": {
227+
"$ref": "#/definitions/parameter"
228+
},
229+
"minItems": 1,
230+
"uniqueItems": true
231+
},
224232
"parameters": {
225233
"type": "array",
226234
"items": {

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -690,16 +690,7 @@
690690
"releaseTag": "Public",
691691
"typeParameters": [
692692
{
693-
"kind": "TypeParameter",
694-
"canonicalReference": "(T:typeparam)",
695-
"docComment": "",
696-
"excerptTokens": [
697-
{
698-
"kind": "Reference",
699-
"text": "T"
700-
}
701-
],
702-
"name": "T"
693+
"typeParameterName": "T"
703694
}
704695
],
705696
"name": "Generic",

0 commit comments

Comments
 (0)