diff --git a/lib/plugin/utils/ast-utils.ts b/lib/plugin/utils/ast-utils.ts index e1be073a9..5eeea754b 100644 --- a/lib/plugin/utils/ast-utils.ts +++ b/lib/plugin/utils/ast-utils.ts @@ -30,27 +30,17 @@ import { DocBlock } from '@microsoft/tsdoc'; -export class Formatter { - public static renderDocNode(docNode: DocNode): string { - let result: string = ''; - if (docNode) { - if (docNode instanceof DocExcerpt) { - result += docNode.content.toString(); - } - for (const childNode of docNode.getChildNodes()) { - result += Formatter.renderDocNode(childNode); - } +export function renderDocNode(docNode: DocNode) { + let result: string = ''; + if (docNode) { + if (docNode instanceof DocExcerpt) { + result += docNode.content.toString(); } - return result; - } - - public static renderDocNodes(docNodes: ReadonlyArray): string { - let result: string = ''; - for (const docNode of docNodes) { - result += Formatter.renderDocNode(docNode); + for (const childNode of docNode.getChildNodes()) { + result += renderDocNode(childNode); } - return result; } + return result; } export function isArray(type: Type) { @@ -157,7 +147,7 @@ export function getMainCommentOfNode( node.getFullText() ); const docComment: DocComment = parserContext.docComment; - return Formatter.renderDocNode(docComment.summarySection).trim(); + return renderDocNode(docComment.summarySection).trim(); } export function parseCommentDocValue(docValue: string, type: ts.Type) { @@ -209,9 +199,7 @@ export function getTsDocTagsOfNode(node: Node, typeChecker: TypeChecker) { const type = typeChecker.getTypeAtLocation(node); if (hasProperties) { blocks.forEach((block) => { - const docValue = Formatter.renderDocNode(block.content).split( - '\n' - )[0]; + const docValue = renderDocNode(block.content).split('\n')[0]; const value = parseCommentDocValue(docValue, type); if (value !== null) { @@ -226,6 +214,11 @@ export function getTsDocTagsOfNode(node: Node, typeChecker: TypeChecker) { tagResults[tag] = true; } } + if (docComment.remarksBlock) { + tagResults['remarks'] = renderDocNode( + docComment.remarksBlock.content + ).trim(); + } if (docComment.deprecatedBlock) { tagResults['deprecated'] = true; } diff --git a/lib/plugin/visitors/controller-class.visitor.ts b/lib/plugin/visitors/controller-class.visitor.ts index f1da31a50..68162c6e5 100644 --- a/lib/plugin/visitors/controller-class.visitor.ts +++ b/lib/plugin/visitors/controller-class.visitor.ts @@ -233,6 +233,18 @@ export class ControllerClassVisitor extends AbstractFileVisitor { ...(apiOperationExistingProps ?? factory.createNodeArray()) ]; + const hasRemarksKey = hasPropertyKey( + 'description', + factory.createNodeArray(apiOperationExistingProps) + ); + if (!hasRemarksKey && tags.remarks) { + const remarksPropertyAssignment = factory.createPropertyAssignment( + 'description', + createLiteralFromAnyValue(factory, tags.remarks) + ); + properties.push(remarksPropertyAssignment); + } + const hasDeprecatedKey = hasPropertyKey( 'deprecated', factory.createNodeArray(apiOperationExistingProps) diff --git a/test/plugin/fixtures/app.controller.ts b/test/plugin/fixtures/app.controller.ts index 385a21c5c..e407a9db7 100644 --- a/test/plugin/fixtures/app.controller.ts +++ b/test/plugin/fixtures/app.controller.ts @@ -9,6 +9,8 @@ export class AppController { /** * create a Cat + * + * @remarks Creating a test cat * * @returns {Promise} * @memberof AppController @@ -71,6 +73,8 @@ let AppController = exports.AppController = class AppController { /** * create a Cat * + * @remarks Creating a test cat + * * @returns {Promise} * @memberof AppController */ @@ -104,7 +108,7 @@ let AppController = exports.AppController = class AppController { async findAll() { } }; __decorate([ - openapi.ApiOperation({ summary: \"create a Cat\" }), + openapi.ApiOperation({ summary: \"create a Cat\", description: \"Creating a test cat\" }), (0, common_1.Post)(), openapi.ApiResponse({ status: 201, type: Cat }) ], AppController.prototype, \"create\", null);