diff --git a/packages/api-extractor/src/generators/ApiModelGenerator.ts b/packages/api-extractor/src/generators/ApiModelGenerator.ts index 039a21f28eb0..d4b56ce037ec 100644 --- a/packages/api-extractor/src/generators/ApiModelGenerator.ts +++ b/packages/api-extractor/src/generators/ApiModelGenerator.ts @@ -114,7 +114,7 @@ interface DocgenEventJson { } interface DocgenParamJson { - default?: string; + default?: boolean | number | string; description: string; name: string; nullable?: boolean; @@ -155,7 +155,7 @@ interface DocgenMethodJson { interface DocgenPropertyJson { abstract?: boolean; access?: DocgenAccess; - default?: string; + default?: boolean | number | string; deprecated?: DocgenDeprecated; description: string; meta: DocgenMetaJson; @@ -1264,7 +1264,7 @@ export class ApiModelGenerator { const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration); const docComment: tsdoc.DocComment | undefined = jsDoc ? this._tsDocParser.parseString( - `/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}\n${ + `/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}${jsDoc.default ? ` (default: ${this._escapeSpecialChars(jsDoc.default)})` : ''}\n${ 'see' in jsDoc ? jsDoc.see.map((see) => ` * @see ${see}\n`).join('') : '' }${'readonly' in jsDoc && jsDoc.readonly ? ' * @readonly\n' : ''}${ 'deprecated' in jsDoc && jsDoc.deprecated @@ -1342,7 +1342,7 @@ export class ApiModelGenerator { const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration); const docComment: tsdoc.DocComment | undefined = jsDoc ? this._tsDocParser.parseString( - `/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}\n${ + `/**\n * ${this._fixLinkTags(jsDoc.description) ?? ''}${jsDoc.default ? ` (default: ${this._escapeSpecialChars(jsDoc.default)})` : ''}\n${ 'see' in jsDoc ? jsDoc.see.map((see) => ` * @see ${see}\n`).join('') : '' }${'readonly' in jsDoc && jsDoc.readonly ? ' * @readonly\n' : ''}${ 'deprecated' in jsDoc && jsDoc.deprecated @@ -1746,6 +1746,14 @@ export class ApiModelGenerator { return sourceLocation; } + private _escapeSpecialChars(input: boolean | number | string) { + if (typeof input !== 'string') { + return input; + } + + return input.replaceAll(/(?[{}])/g, '\\$'); + } + private _fixLinkTags(input?: string): string | undefined { return input ?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => { @@ -1823,7 +1831,7 @@ export class ApiModelGenerator { isOptional: Boolean(prop.nullable), isReadonly: Boolean(prop.readonly), docComment: this._tsDocParser.parseString( - `/**\n * ${this._fixLinkTags(prop.description) ?? ''}\n${ + `/**\n * ${this._fixLinkTags(prop.description) ?? ''}${prop.default ? ` (default: ${this._escapeSpecialChars(prop.default)})` : ''}\n${ prop.see?.map((see) => ` * @see ${see}\n`).join('') ?? '' }${prop.readonly ? ' * @readonly\n' : ''} */`, ).docComment, diff --git a/packages/scripts/src/generateSplitDocumentation.ts b/packages/scripts/src/generateSplitDocumentation.ts index 41019ba8706a..6c523a34ef47 100644 --- a/packages/scripts/src/generateSplitDocumentation.ts +++ b/packages/scripts/src/generateSplitDocumentation.ts @@ -39,6 +39,7 @@ import { } from '@discordjs/api-extractor-model'; import { DocNodeKind, SelectorKind, StandardTags } from '@microsoft/tsdoc'; import type { + DocEscapedText, DocNode, DocNodeContainer, DocDeclarationReference, @@ -307,6 +308,11 @@ function itemTsDoc(item: DocNode, apiItem: ApiItem) { kind: DocNodeKind.PlainText, text: (node as DocPlainText).text, }; + case DocNodeKind.EscapedText: + return { + kind: DocNodeKind.PlainText, + text: (node as DocEscapedText).decodedText, + }; case DocNodeKind.Section: case DocNodeKind.Paragraph: return (node as DocNodeContainer).nodes.map((node) => createNode(node));