Skip to content

Commit 7fe243a

Browse files
committed
fix: support tsdoc, do not word wrap jsdoc tag values
1 parent d9bfa75 commit 7fe243a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/utils/jsdoc.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function extractJsDoc(entity: AnnotatedApiEntity | boolean): JsDocBlock {
6969
result.tags.push({name: 'deprecated'});
7070
}
7171
if (entity.example !== undefined) {
72-
result.tags.push({name: 'example', value: exampleToString(entity.example)});
72+
result.tags.push({name: 'example', value: '\n' + exampleToString(entity.example).trim()});
7373
}
7474
if (entity.examples !== undefined) {
7575
for (const [exampleName, example] of Object.entries(entity.examples)) {
@@ -79,7 +79,7 @@ export function extractJsDoc(entity: AnnotatedApiEntity | boolean): JsDocBlock {
7979
}
8080
result.tags.push({
8181
name: 'example',
82-
value: `${exampleInfo.length > 0 ? ` ${exampleInfo.join('. ')}` : ''} ${exampleToString(example.value)}`
82+
value: `${exampleInfo.length > 0 ? ` ${exampleInfo.join('. ')}` : ''}\n${exampleToString(example.value)}`
8383
});
8484
}
8585
}
@@ -113,6 +113,19 @@ const defaultWordWrapLineWidth = 80;
113113

114114
export type JsDocRenderConfig = OpenApiClientGeneratorConfig['jsDoc'];
115115

116+
function renderJsDocTag(tag: JsDocBlockTag): string {
117+
let result = `@${tag.name}`;
118+
119+
if (tag.value) {
120+
if (!tag.value.match(/^[\n\r \t]/)) {
121+
result += ' ';
122+
}
123+
result += tag.value;
124+
}
125+
126+
return result;
127+
}
128+
116129
export function renderJsDoc(jsdoc: JsDocBlock, config: JsDocRenderConfig = {}): string | null {
117130
function processText(text: string) {
118131
if (config?.wordWrap !== false) {
@@ -131,9 +144,7 @@ export function renderJsDoc(jsdoc: JsDocBlock, config: JsDocRenderConfig = {}):
131144
jsdocParts.push(processText(description));
132145
}
133146
if (jsdoc.tags.length > 0) {
134-
jsdocParts.push(
135-
jsdoc.tags.map(({name, value}) => `@${name}${value ? ` ${processText(value.trim())}` : ''}`).join('\n')
136-
);
147+
jsdocParts.push(jsdoc.tags.map(renderJsDocTag).join('\n'));
137148
}
138149
if (jsdocParts.length === 0) {
139150
return null;

0 commit comments

Comments
 (0)