Skip to content

Commit 2432d90

Browse files
committed
Fix generation of IApiParameter output
1 parent d3a482d commit 2432d90

7 files changed

Lines changed: 88 additions & 84 deletions

File tree

‎common/reviews/api/api-extractor.api.ts‎

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ class ApiFileGenerator extends AstItemVisitor {
66
public static areEquivalentApiFileContents(actualFileContent: string, expectedFileContent: string): boolean;
77
// (undocumented)
88
public generateApiFileContent(extractor: Extractor): string;
9-
// WARNING: The type "AstParameter" needs to be exported by the package (e.g. added to index.ts)
10-
// (undocumented)
11-
protected visitApiParam(astParam: AstParameter): void;
129
// WARNING: The type "AstEnum" needs to be exported by the package (e.g. added to index.ts)
1310
// (undocumented)
1411
protected visitAstEnum(astEnum: AstEnum): void;
@@ -44,9 +41,6 @@ class ApiJsonGenerator extends AstItemVisitor {
4441
// WARNING: The type "AstItem" needs to be exported by the package (e.g. added to index.ts)
4542
// (undocumented)
4643
protected visit(astItem: AstItem, refObject?: Object): void;
47-
// WARNING: The type "AstParameter" needs to be exported by the package (e.g. added to index.ts)
48-
// (undocumented)
49-
protected visitApiParam(astParam: AstParameter, refObject?: Object): void;
5044
// WARNING: The type "AstEnum" needs to be exported by the package (e.g. added to index.ts)
5145
// (undocumented)
5246
protected visitAstEnum(astEnum: AstEnum, refObject?: Object): void;
@@ -126,18 +120,14 @@ interface IApiClass extends IApiBaseDefinition {
126120
extends?: string;
127121
implements?: string;
128122
kind: 'class';
129-
members: {
130-
[ name: string ]: ApiMember
131-
}
123+
members: IApiNameMap<ApiMember>;
132124
typeParameters?: string[];
133125
}
134126

135127
// @alpha
136128
interface IApiConstructor extends IApiBaseDefinition {
137129
kind: 'constructor';
138-
parameters: {
139-
[ name: string ]: IApiParameter
140-
}
130+
parameters: IApiNameMap<IApiParameter>;
141131
}
142132

143133
// @alpha
@@ -157,9 +147,7 @@ interface IApiEnumMember extends IApiBaseDefinition {
157147
// @alpha
158148
interface IApiFunction extends IApiBaseDefinition {
159149
kind: 'function';
160-
parameters: {
161-
[ name: string ]: IApiParameter
162-
}
150+
parameters: IApiNameMap<IApiParameter>;
163151
returnValue: IApiReturnValue;
164152
}
165153

@@ -168,9 +156,7 @@ interface IApiInterface extends IApiBaseDefinition {
168156
extends?: string;
169157
implements?: string;
170158
kind: 'interface';
171-
members: {
172-
[ name: string ]: ApiMember
173-
}
159+
members: IApiNameMap<ApiMember>;
174160
typeParameters?: string[];
175161
}
176162

@@ -188,20 +174,22 @@ interface IApiMethod extends IApiBaseDefinition {
188174
isOptional: boolean;
189175
isStatic: boolean;
190176
kind: 'method';
191-
parameters: {
192-
[ name: string ]: IApiParameter
193-
}
177+
parameters: IApiNameMap<IApiParameter>;
194178
returnValue: IApiReturnValue;
195179
signature: string;
196180
}
197181

182+
// @alpha
183+
interface IApiNameMap<T> {
184+
// (undocumented)
185+
[ name: string ]: T;
186+
}
187+
198188
// @alpha
199189
interface IApiPackage {
200190
// (undocumented)
201191
deprecatedMessage?: IDocElement[];
202-
exports: {
203-
[ name: string ]: ApiItem
204-
}
192+
exports: IApiNameMap<ApiItem>;
205193
isBeta?: boolean;
206194
kind: 'package';
207195
name: string;

‎libraries/api-extractor/src/generators/ApiFileGenerator.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import AstFunction from '../ast/AstFunction';
1010
import AstItem, { AstItemKind } from '../ast/AstItem';
1111
import AstItemVisitor from './AstItemVisitor';
1212
import AstPackage from '../ast/AstPackage';
13-
import AstParameter from '../ast/AstParameter';
1413
import AstMember from '../ast/AstMember';
1514
import AstNamespace from '../ast/AstNamespace';
1615
import AstModuleVariable from '../ast/AstModuleVariable';
@@ -178,10 +177,6 @@ export default class ApiFileGenerator extends AstItemVisitor {
178177
this._indentedWriter.write(astFunction.getDeclarationLine());
179178
}
180179

181-
protected visitApiParam(astParam: AstParameter): void {
182-
throw Error('Not Implemented');
183-
}
184-
185180
/**
186181
* Writes a synopsis of the AEDoc comments, which indicates the release tag,
187182
* whether the item has been documented, and any warnings that were detected

‎libraries/api-extractor/src/generators/ApiJsonGenerator.ts‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import AstNamespace from '../ast/AstNamespace';
2121
import AstModuleVariable from '../ast/AstModuleVariable';
2222
import AstMethod from '../ast/AstMethod';
2323
import { ReleaseTag } from '../aedoc/ReleaseTag';
24-
import { IApiReturnValue, IApiParameter } from '../api/ApiItem';
24+
import { IAedocParameter } from '../aedoc/ApiDocumentation';
25+
import { IApiReturnValue, IApiParameter, IApiNameMap } from '../api/ApiItem';
2526
import ApiJsonFile from '../api/ApiJsonFile';
2627

2728
/**
@@ -168,9 +169,6 @@ export default class ApiJsonGenerator extends AstItemVisitor {
168169
return;
169170
}
170171

171-
for (const param of astFunction.params) {
172-
this.visitApiParam(param, astFunction.documentation.parameters[param.name]);
173-
}
174172
const returnValueNode: IApiReturnValue = {
175173
type: astFunction.returnType,
176174
description: astFunction.documentation.returnsMessage
@@ -179,7 +177,7 @@ export default class ApiJsonGenerator extends AstItemVisitor {
179177
const newNode: Object = {
180178
kind: ApiJsonFile.convertKindToJson(astFunction.kind),
181179
returnValue: returnValueNode,
182-
parameters: astFunction.documentation.parameters,
180+
parameters: this._createParameters(astFunction),
183181
deprecatedMessage: astFunction.inheritedDeprecatedMessage || [],
184182
summary: astFunction.documentation.summary || [],
185183
remarks: astFunction.documentation.remarks || [],
@@ -278,16 +276,12 @@ export default class ApiJsonGenerator extends AstItemVisitor {
278276
return;
279277
}
280278

281-
for (const param of astMethod.params) {
282-
this.visitApiParam(param, astMethod.documentation.parameters[param.name]);
283-
}
284-
285279
let newNode: Object;
286280
if (astMethod.name === '__constructor') {
287281
newNode = {
288282
kind: ApiJsonFile.convertKindToJson(AstItemKind.Constructor),
289283
signature: astMethod.getDeclarationLine(),
290-
parameters: astMethod.documentation.parameters,
284+
parameters: this._createParameters(astMethod),
291285
deprecatedMessage: astMethod.inheritedDeprecatedMessage || [],
292286
summary: astMethod.documentation.summary || [],
293287
remarks: astMethod.documentation.remarks || []
@@ -305,7 +299,7 @@ export default class ApiJsonGenerator extends AstItemVisitor {
305299
isOptional: !!astMethod.isOptional,
306300
isStatic: !!astMethod.isStatic,
307301
returnValue: returnValueNode,
308-
parameters: astMethod.documentation.parameters,
302+
parameters: this._createParameters(astMethod),
309303
deprecatedMessage: astMethod.inheritedDeprecatedMessage || [],
310304
summary: astMethod.documentation.summary || [],
311305
remarks: astMethod.documentation.remarks || [],
@@ -316,15 +310,31 @@ export default class ApiJsonGenerator extends AstItemVisitor {
316310
refObject[astMethod.name] = newNode;
317311
}
318312

319-
protected visitApiParam(astParam: AstParameter, refObject?: Object): void {
320-
if (!astParam.supportedName) {
321-
return;
322-
}
313+
private _createParameters(astFunction: AstMethod | AstFunction): IApiNameMap<IApiParameter> {
314+
const result: IApiNameMap<IApiParameter> = { };
315+
316+
for (const astParameter of astFunction.params) {
317+
if (!astParameter.supportedName) {
318+
continue; // skip parameter names with unusual characters
319+
}
323320

324-
if (refObject) {
325-
(refObject as IApiParameter).isOptional = astParam.isOptional;
326-
(refObject as IApiParameter).isSpread = astParam.isSpread;
327-
(refObject as IApiParameter).type = astParam.type;
321+
const apiParameter: IApiParameter = {
322+
name: astParameter.name,
323+
description: [],
324+
isOptional: astParameter.isOptional,
325+
isSpread: astParameter.isSpread,
326+
type: astParameter.type || ''
327+
};
328+
329+
const aedocParameter: IAedocParameter = astFunction.documentation.parameters[astParameter.name];
330+
if (aedocParameter) {
331+
apiParameter.description = aedocParameter.description;
332+
}
333+
334+
result[astParameter.name] = apiParameter;
328335
}
336+
337+
return result;
329338
}
339+
330340
}

‎libraries/api-extractor/src/generators/AstItemVisitor.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import AstStructuredType from '../ast/AstStructuredType';
1010
import AstMember from '../ast/AstMember';
1111
import AstMethod from '../ast/AstMethod';
1212
import AstNamespace from '../ast/AstNamespace';
13-
import AstParameter from '../ast/AstParameter';
1413
import AstProperty from '../ast/AstProperty';
1514
import AstModuleVariable from '../ast/AstModuleVariable';
1615

@@ -66,8 +65,6 @@ abstract class AstItemVisitor {
6665
protected visitAstProperty(astProperty: AstProperty, refObject?: Object): void {
6766
this.visitAstMember(astProperty, refObject);
6867
}
69-
70-
protected abstract visitApiParam(astParam: AstParameter, refObject?: Object): void;
7168
}
7269

7370
export default AstItemVisitor;

‎libraries/api-extractor/testInputs/example1/example1-output.json‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@
6363
"type": "__proto__",
6464
"description": []
6565
},
66-
"parameters": {},
66+
"parameters": {
67+
"___proto__": {
68+
"name": "___proto__",
69+
"description": [],
70+
"isOptional": false,
71+
"isSpread": false,
72+
"type": "string"
73+
}
74+
},
6775
"deprecatedMessage": [],
6876
"summary": [],
6977
"remarks": [],
@@ -227,7 +235,15 @@
227235
"type": "string",
228236
"description": []
229237
},
230-
"parameters": {},
238+
"parameters": {
239+
"param": {
240+
"name": "param",
241+
"description": [],
242+
"isOptional": false,
243+
"isSpread": false,
244+
"type": "number"
245+
}
246+
},
231247
"deprecatedMessage": [],
232248
"summary": [],
233249
"remarks": [],

‎libraries/api-extractor/testInputs/example3/example3-output.json‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,7 @@
191191
}
192192
]
193193
},
194-
"parameters": {
195-
"param1": {
196-
"name": "param1",
197-
"description": [
198-
{
199-
"kind": "textDocElement",
200-
"value": "A description for param1."
201-
}
202-
],
203-
"isOptional": false,
204-
"isSpread": false,
205-
"type": "string"
206-
}
207-
},
194+
"parameters": {},
208195
"deprecatedMessage": [],
209196
"summary": [
210197
{
@@ -233,20 +220,7 @@
233220
}
234221
]
235222
},
236-
"parameters": {
237-
"param1": {
238-
"name": "param1",
239-
"description": [
240-
{
241-
"kind": "textDocElement",
242-
"value": "A description for param1."
243-
}
244-
],
245-
"isOptional": false,
246-
"isSpread": false,
247-
"type": "string"
248-
}
249-
},
223+
"parameters": {},
250224
"deprecatedMessage": [],
251225
"summary": [
252226
{

‎libraries/api-extractor/testInputs/example4/example4-output.json‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929
"type": "void",
3030
"description": []
3131
},
32-
"parameters": {},
32+
"parameters": {
33+
"promise": {
34+
"name": "promise",
35+
"description": [],
36+
"isOptional": false,
37+
"isSpread": false,
38+
"type": "Promise<void>"
39+
}
40+
},
3341
"deprecatedMessage": [],
3442
"summary": [
3543
{
@@ -98,7 +106,15 @@
98106
"type": "MissingExport",
99107
"description": []
100108
},
101-
"parameters": {},
109+
"parameters": {
110+
"library": {
111+
"name": "library",
112+
"description": [],
113+
"isOptional": false,
114+
"isSpread": false,
115+
"type": "MyLibrary3"
116+
}
117+
},
102118
"deprecatedMessage": [],
103119
"summary": [
104120
{
@@ -119,7 +135,15 @@
119135
"type": "void",
120136
"description": []
121137
},
122-
"parameters": {},
138+
"parameters": {
139+
"missing": {
140+
"name": "missing",
141+
"description": [],
142+
"isOptional": false,
143+
"isSpread": false,
144+
"type": "MissingExport"
145+
}
146+
},
123147
"deprecatedMessage": [],
124148
"summary": [
125149
{

0 commit comments

Comments
 (0)