in apps/api-documenter/src/documenters/YamlDocumenter.ts [374:524]
private _generateYamlItem(apiItem: ApiDocumentedItem): IYamlItem | undefined {
// Filter out known items that are not yet supported
if (!this._shouldInclude(apiItem.kind)) {
return undefined;
}
const uid: DeclarationReference = this._getUidObject(apiItem);
const yamlItem: Partial<IYamlItem> = {
uid: uid.toString()
};
if (apiItem.tsdocComment) {
const tsdocComment: DocComment = apiItem.tsdocComment;
if (tsdocComment.summarySection) {
const summary: string = this._renderMarkdown(tsdocComment.summarySection, apiItem);
if (summary) {
yamlItem.summary = summary;
}
}
if (tsdocComment.remarksBlock) {
const remarks: string = this._renderMarkdown(tsdocComment.remarksBlock.content, apiItem);
if (remarks) {
yamlItem.remarks = remarks;
}
}
if (tsdocComment) {
// Write the @example blocks
const exampleBlocks: DocBlock[] = tsdocComment.customBlocks.filter(
(x) => x.blockTag.tagNameWithUpperCase === StandardTags.example.tagNameWithUpperCase
);
for (const exampleBlock of exampleBlocks) {
const example: string = this._renderMarkdown(exampleBlock.content, apiItem);
if (example) {
yamlItem.example = [...(yamlItem.example || []), example];
}
}
}
if (tsdocComment.deprecatedBlock) {
const deprecatedMessage: string = this._renderMarkdown(tsdocComment.deprecatedBlock.content, apiItem);
if (deprecatedMessage.length > 0) {
yamlItem.deprecated = { content: deprecatedMessage };
}
}
}
if (ApiReleaseTagMixin.isBaseClassOf(apiItem)) {
if (apiItem.releaseTag === ReleaseTag.Beta) {
yamlItem.isPreview = true;
}
}
yamlItem.name = this._getYamlItemName(apiItem, {
includeSignature: true,
includeNamespace: !this.newDocfxNamespaces
});
yamlItem.fullName = this._getYamlItemName(apiItem, { includeSignature: true, includeNamespace: true });
yamlItem.langs = ['typeScript'];
// Add the namespace of the item if it is contained in one.
// Do not add the namespace parent of a namespace as they are flattened in the documentation.
if (
apiItem.kind !== ApiItemKind.Namespace &&
apiItem.parent &&
apiItem.parent.kind === ApiItemKind.Namespace &&
this.newDocfxNamespaces
) {
yamlItem.namespace = apiItem.parent.canonicalReference.toString();
}
switch (apiItem.kind) {
case ApiItemKind.Enum:
yamlItem.type = 'enum';
break;
case ApiItemKind.EnumMember:
yamlItem.type = 'field';
const enumMember: ApiEnumMember = apiItem as ApiEnumMember;
if (enumMember.initializerExcerpt.text.length > 0) {
yamlItem.numericValue = enumMember.initializerExcerpt.text;
}
break;
case ApiItemKind.Class:
yamlItem.type = 'class';
this._populateYamlClassOrInterface(uid, yamlItem, apiItem as ApiClass);
break;
case ApiItemKind.Interface:
yamlItem.type = 'interface';
this._populateYamlClassOrInterface(uid, yamlItem, apiItem as ApiInterface);
break;
case ApiItemKind.Method:
case ApiItemKind.MethodSignature:
yamlItem.type = 'method';
this._populateYamlFunctionLike(uid, yamlItem, apiItem as ApiMethod | ApiMethodSignature);
break;
case ApiItemKind.Constructor:
yamlItem.type = 'constructor';
this._populateYamlFunctionLike(uid, yamlItem, apiItem as ApiConstructor);
break;
case ApiItemKind.Package:
yamlItem.type = 'package';
break;
case ApiItemKind.Namespace:
yamlItem.type = 'namespace';
break;
case ApiItemKind.Property:
case ApiItemKind.PropertySignature:
const apiProperty: ApiPropertyItem = apiItem as ApiPropertyItem;
if (apiProperty.isEventProperty) {
yamlItem.type = 'event';
} else {
yamlItem.type = 'property';
}
this._populateYamlProperty(uid, yamlItem, apiProperty);
break;
case ApiItemKind.Function:
yamlItem.type = 'function';
this._populateYamlFunctionLike(uid, yamlItem, apiItem as ApiFunction);
break;
case ApiItemKind.Variable:
yamlItem.type = 'variable';
this._populateYamlVariable(uid, yamlItem, apiItem as ApiVariable);
break;
case ApiItemKind.TypeAlias:
yamlItem.type = 'typealias';
this._populateYamlTypeAlias(uid, yamlItem, apiItem as ApiTypeAlias);
break;
default:
throw new Error('Unimplemented item kind: ' + apiItem.kind);
}
if (apiItem.kind !== ApiItemKind.Package && !this._shouldEmbed(apiItem.kind)) {
const associatedPackage: ApiPackage | undefined = apiItem.getAssociatedPackage();
if (!associatedPackage) {
throw new Error('Unable to determine associated package for ' + apiItem.displayName);
}
yamlItem.package = this._getUid(associatedPackage);
}
return yamlItem as IYamlItem;
}