Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/api-extractor/src/ResolvedApiItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ResolvedApiItem {
public kind: AstItemKind;
public summary: MarkupElement[];
public remarks: MarkupElement[];
public examples: MarkupElement[][];
public deprecatedMessage: MarkupBasicElement[] | undefined;
public releaseTag: ReleaseTag;
public isBeta: boolean;
Expand All @@ -35,6 +36,7 @@ export class ResolvedApiItem {
astItem.kind,
astItem.documentation.summary,
astItem.documentation.remarks,
astItem.documentation.examples,
astItem.documentation.deprecatedMessage,
astItem.documentation.releaseTag === ReleaseTag.Beta,
astItem.documentation.parameters,
Expand Down Expand Up @@ -68,6 +70,7 @@ export class ResolvedApiItem {
ApiJsonConverter.convertJsonToKind(docItem.kind),
docItem.summary,
docItem.remarks,
docItem.examples,
docItem.deprecatedMessage,
docItem.isBeta,
parameters,
Expand All @@ -81,6 +84,7 @@ export class ResolvedApiItem {
kind: AstItemKind,
summary: MarkupElement[],
remarks: MarkupElement[],
examples: MarkupElement[][],
deprecatedMessage: MarkupBasicElement[] | undefined,
isBeta: boolean,
params: { [name: string]: IAedocParameter } | undefined,
Expand All @@ -90,6 +94,7 @@ export class ResolvedApiItem {
this.kind = kind;
this.summary = summary;
this.remarks = remarks;
this.examples = examples;
this.deprecatedMessage = deprecatedMessage;
this.isBeta = isBeta;
this.params = params;
Expand Down
8 changes: 8 additions & 0 deletions apps/api-extractor/src/aedoc/ApiDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ApiDocumentation {
'@beta',
'@betadocumentation',
'@eventproperty',
'@example',
'@internal',
'@internalremarks',
'@override',
Expand Down Expand Up @@ -83,6 +84,7 @@ export class ApiDocumentation {
public summary: MarkupElement[];
public deprecatedMessage: MarkupBasicElement[];
public remarks: MarkupElement[];
public examples: MarkupElement[][];
public returnsMessage: MarkupBasicElement[];
public parameters: { [name: string]: IAedocParameter; };

Expand Down Expand Up @@ -233,6 +235,7 @@ export class ApiDocumentation {
this.returnsMessage = [];
this.deprecatedMessage = [];
this.remarks = [];
this.examples = [];
this.incompleteLinks = [];
this.incompleteInheritdocs = [];
this.releaseTag = ReleaseTag.None;
Expand Down Expand Up @@ -263,6 +266,11 @@ export class ApiDocumentation {
this._checkInheritDocStatus(token.tag);
this.remarks = DocElementParser.parseAndNormalize(this, tokenizer);
break;
case '@example':
tokenizer.getToken();
this._checkInheritDocStatus(token.tag);
this.examples.push(DocElementParser.parseAndNormalize(this, tokenizer));
break;
case '@returns':
tokenizer.getToken();
this._checkInheritDocStatus(token.tag);
Expand Down
1 change: 1 addition & 0 deletions apps/api-extractor/src/aedoc/DocElementParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class DocElementParser {
// inheritdoc found, copy over IApiBaseDefinition properties
documentation.summary = resolvedAstItem.summary;
documentation.remarks = resolvedAstItem.remarks;
documentation.examples = resolvedAstItem.examples;

// Copy over detailed properties if neccessary
// Add additional cases if needed
Expand Down
2 changes: 2 additions & 0 deletions apps/api-extractor/src/api/ApiItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export interface IApiBaseDefinition {
isBeta: boolean;
summary: MarkupBasicElement[];
remarks: MarkupStructuredElement[];
examples: MarkupStructuredElement[][],
deprecatedMessage?: MarkupBasicElement[];
}

Expand Down Expand Up @@ -448,6 +449,7 @@ export interface IApiPackage {
isBeta: boolean;
summary: MarkupBasicElement[];
remarks: MarkupStructuredElement[];
examples: MarkupStructuredElement[][],
deprecatedMessage?: MarkupBasicElement[];
}

Expand Down
88 changes: 88 additions & 0 deletions apps/api-extractor/src/api/api-json.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -513,6 +521,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -574,6 +590,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -678,6 +702,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -781,6 +813,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -848,6 +888,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -898,6 +946,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -939,6 +995,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -1004,6 +1068,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -1064,6 +1136,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"deprecatedMessage": {
"description": "If present, indicates that the item is deprecated and describes the recommended alternative",
"type": "array",
Expand Down Expand Up @@ -1103,6 +1183,14 @@
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
},
"examples": {
"description": "Example regarding usage of the item",
"type": "array",
"items": {
"type": "array",
"items": { "$ref": "#/definitions/markupStructuredElement" }
}
},
"exports": {
"description": "The exported definitions for this API package",
"type": "object",
Expand Down
12 changes: 11 additions & 1 deletion apps/api-extractor/src/generators/ApiJsonGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astStructuredType.inheritedDeprecatedMessage || [],
summary: astStructuredType.documentation.summary || [],
remarks: astStructuredType.documentation.remarks || [],
examples: astStructuredType.documentation.examples || [],
isBeta: astStructuredType.inheritedReleaseTag === ReleaseTag.Beta
};

Expand Down Expand Up @@ -130,6 +131,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astEnum.inheritedDeprecatedMessage || [],
summary: astEnum.documentation.summary || [],
remarks: astEnum.documentation.remarks || [],
examples: astEnum.documentation.examples || [],
isBeta: astEnum.inheritedReleaseTag === ReleaseTag.Beta
};
refObject![astEnum.name] = enumNode;
Expand All @@ -156,6 +158,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astEnumValue.inheritedDeprecatedMessage || [],
summary: astEnumValue.documentation.summary || [],
remarks: astEnumValue.documentation.remarks || [],
examples: astEnumValue.documentation.examples || [],
isBeta: astEnumValue.inheritedReleaseTag === ReleaseTag.Beta
};
}
Expand All @@ -178,6 +181,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astFunction.inheritedDeprecatedMessage || [],
summary: astFunction.documentation.summary || [],
remarks: astFunction.documentation.remarks || [],
examples: astFunction.documentation.examples || [],
isBeta: astFunction.inheritedReleaseTag === ReleaseTag.Beta
};

Expand All @@ -190,6 +194,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
refObject!['name'] = astPackage.name;
refObject!['summary'] = astPackage.documentation.summary;
refObject!['remarks'] = astPackage.documentation.remarks;
refObject!['examples'] = astPackage.documentation.examples;
/* tslint:enable:no-string-literal */

const membersNode: Object = {};
Expand All @@ -215,6 +220,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astNamespace.inheritedDeprecatedMessage || [],
summary: astNamespace.documentation.summary || [],
remarks: astNamespace.documentation.remarks || [],
examples: astNamespace.documentation.examples || [],
isBeta: astNamespace.inheritedReleaseTag === ReleaseTag.Beta,
exports: membersNode
};
Expand Down Expand Up @@ -249,6 +255,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astProperty.inheritedDeprecatedMessage || [],
summary: astProperty.documentation.summary || [],
remarks: astProperty.documentation.remarks || [],
examples: astProperty.documentation.examples || [],
isBeta: astProperty.inheritedReleaseTag === ReleaseTag.Beta,
isSealed: !!astProperty.documentation.isSealed,
isVirtual: !!astProperty.documentation.isVirtual,
Expand All @@ -268,6 +275,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astModuleVariable.inheritedDeprecatedMessage || [],
summary: astModuleVariable.documentation.summary || [],
remarks: astModuleVariable.documentation.remarks || [],
examples: astModuleVariable.documentation.examples || [],
isBeta: astModuleVariable.inheritedReleaseTag === ReleaseTag.Beta
};

Expand All @@ -287,7 +295,8 @@ export class ApiJsonGenerator extends AstItemVisitor {
parameters: this._createParameters(astMethod),
deprecatedMessage: astMethod.inheritedDeprecatedMessage || [],
summary: astMethod.documentation.summary || [],
remarks: astMethod.documentation.remarks || []
remarks: astMethod.documentation.remarks || [],
examples: astMethod.documentation.examples || []
};
} else {
const returnValueNode: IApiReturnValue = {
Expand All @@ -306,6 +315,7 @@ export class ApiJsonGenerator extends AstItemVisitor {
deprecatedMessage: astMethod.inheritedDeprecatedMessage || [],
summary: astMethod.documentation.summary || [],
remarks: astMethod.documentation.remarks || [],
examples: astMethod.documentation.examples || [],
isBeta: astMethod.inheritedReleaseTag === ReleaseTag.Beta,
isSealed: !!astMethod.documentation.isSealed,
isVirtual: !!astMethod.documentation.isVirtual,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor",
"comment": "Add support to AEDoc for the \"@example\" tag.",
"type": "minor"
}
],
"packageName": "@microsoft/api-extractor",
"email": "[email protected]"
}
4 changes: 4 additions & 0 deletions common/reviews/api/api-extractor.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ interface IApiBaseDefinition {
// (undocumented)
deprecatedMessage?: MarkupBasicElement[];
// (undocumented)
examples: MarkupStructuredElement[][];
// (undocumented)
isBeta: boolean;
kind: string;
// (undocumented)
Expand Down Expand Up @@ -134,6 +136,8 @@ interface IApiNamespace extends IApiBaseDefinition {
interface IApiPackage {
// (undocumented)
deprecatedMessage?: MarkupBasicElement[];
// (undocumented)
examples: MarkupStructuredElement[][];
exports: IApiNameMap<ApiItem>;
isBeta: boolean;
kind: 'package';
Expand Down