Skip to content

Commit 7e6b64f

Browse files
committedFeb 7, 2024
feat: update test and optimize code
1 parent d3e7e1c commit 7e6b64f

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed
 

‎lib/plugin/utils/ast-utils.ts

+15-22
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,17 @@ import {
3030
DocBlock
3131
} from '@microsoft/tsdoc';
3232

33-
export class Formatter {
34-
public static renderDocNode(docNode: DocNode): string {
35-
let result: string = '';
36-
if (docNode) {
37-
if (docNode instanceof DocExcerpt) {
38-
result += docNode.content.toString();
39-
}
40-
for (const childNode of docNode.getChildNodes()) {
41-
result += Formatter.renderDocNode(childNode);
42-
}
33+
export function renderDocNode(docNode: DocNode) {
34+
let result: string = '';
35+
if (docNode) {
36+
if (docNode instanceof DocExcerpt) {
37+
result += docNode.content.toString();
4338
}
44-
return result;
45-
}
46-
47-
public static renderDocNodes(docNodes: ReadonlyArray<DocNode>): string {
48-
let result: string = '';
49-
for (const docNode of docNodes) {
50-
result += Formatter.renderDocNode(docNode);
39+
for (const childNode of docNode.getChildNodes()) {
40+
result += renderDocNode(childNode);
5141
}
52-
return result;
5342
}
43+
return result;
5444
}
5545

5646
export function isArray(type: Type) {
@@ -157,7 +147,7 @@ export function getMainCommentOfNode(
157147
node.getFullText()
158148
);
159149
const docComment: DocComment = parserContext.docComment;
160-
return Formatter.renderDocNode(docComment.summarySection).trim();
150+
return renderDocNode(docComment.summarySection).trim();
161151
}
162152

163153
export function parseCommentDocValue(docValue: string, type: ts.Type) {
@@ -209,9 +199,7 @@ export function getTsDocTagsOfNode(node: Node, typeChecker: TypeChecker) {
209199
const type = typeChecker.getTypeAtLocation(node);
210200
if (hasProperties) {
211201
blocks.forEach((block) => {
212-
const docValue = Formatter.renderDocNode(block.content).split(
213-
'\n'
214-
)[0];
202+
const docValue = renderDocNode(block.content).split('\n')[0];
215203
const value = parseCommentDocValue(docValue, type);
216204

217205
if (value !== null) {
@@ -226,6 +214,11 @@ export function getTsDocTagsOfNode(node: Node, typeChecker: TypeChecker) {
226214
tagResults[tag] = true;
227215
}
228216
}
217+
if (docComment.remarksBlock) {
218+
tagResults['remarks'] = renderDocNode(
219+
docComment.remarksBlock.content
220+
).trim();
221+
}
229222
if (docComment.deprecatedBlock) {
230223
tagResults['deprecated'] = true;
231224
}

‎lib/plugin/visitors/controller-class.visitor.ts

+12
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ export class ControllerClassVisitor extends AbstractFileVisitor {
233233
...(apiOperationExistingProps ?? factory.createNodeArray())
234234
];
235235

236+
const hasRemarksKey = hasPropertyKey(
237+
'description',
238+
factory.createNodeArray(apiOperationExistingProps)
239+
);
240+
if (!hasRemarksKey && tags.remarks) {
241+
const remarksPropertyAssignment = factory.createPropertyAssignment(
242+
'description',
243+
createLiteralFromAnyValue(factory, tags.remarks)
244+
);
245+
properties.push(remarksPropertyAssignment);
246+
}
247+
236248
const hasDeprecatedKey = hasPropertyKey(
237249
'deprecated',
238250
factory.createNodeArray(apiOperationExistingProps)

‎test/plugin/fixtures/app.controller.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export class AppController {
99
1010
/**
1111
* create a Cat
12+
*
13+
* @remarks Creating a test cat
1214
*
1315
* @returns {Promise<Cat>}
1416
* @memberof AppController
@@ -71,6 +73,8 @@ let AppController = exports.AppController = class AppController {
7173
/**
7274
* create a Cat
7375
*
76+
* @remarks Creating a test cat
77+
*
7478
* @returns {Promise<Cat>}
7579
* @memberof AppController
7680
*/
@@ -104,7 +108,7 @@ let AppController = exports.AppController = class AppController {
104108
async findAll() { }
105109
};
106110
__decorate([
107-
openapi.ApiOperation({ summary: \"create a Cat\" }),
111+
openapi.ApiOperation({ summary: \"create a Cat\", description: \"Creating a test cat\" }),
108112
(0, common_1.Post)(),
109113
openapi.ApiResponse({ status: 201, type: Cat })
110114
], AppController.prototype, \"create\", null);

0 commit comments

Comments
 (0)
Please sign in to comment.