@@ -4,8 +4,9 @@ import { ApiOperation, ApiResponse } from '../../decorators';
4
4
import { PluginOptions } from '../merge-options' ;
5
5
import { OPENAPI_NAMESPACE } from '../plugin-constants' ;
6
6
import {
7
+ docNodeToString ,
7
8
getDecoratorArguments ,
8
- getMainCommentAndExamplesOfNode
9
+ getMainCommentAndExamplesOfNode , getNodeDocs
9
10
} from '../utils/ast-utils' ;
10
11
import {
11
12
getDecoratorOrUndefinedByNames ,
@@ -116,25 +117,46 @@ export class ControllerClassVisitor extends AbstractFileVisitor {
116
117
! apiOperationExprProperties ||
117
118
! hasPropertyKey ( keyToGenerate , apiOperationExprProperties )
118
119
) {
119
- const [ extractedComments ] = getMainCommentAndExamplesOfNode (
120
- node ,
121
- sourceFile ,
122
- typeChecker
123
- ) ;
124
- if ( ! extractedComments ) {
125
- // Node does not have any comments
126
- return [ ] ;
120
+ const properties = [ ] ;
121
+
122
+ if ( keyToGenerate ) {
123
+ const [ extractedComments ] = getMainCommentAndExamplesOfNode (
124
+ node ,
125
+ sourceFile ,
126
+ typeChecker
127
+ ) ;
128
+
129
+ if ( ! extractedComments ) {
130
+ // Node does not have any comments
131
+ return [ ] ;
132
+ }
133
+
134
+ properties . push ( ts . createPropertyAssignment ( keyToGenerate , ts . createLiteral ( extractedComments ) ) ) ;
135
+ } else {
136
+ const docs = getNodeDocs ( node ) ;
137
+
138
+ if ( ! docs ) {
139
+ return [ ] ;
140
+ }
141
+
142
+ const summary = docNodeToString ( docs . summarySection ) ;
143
+ if ( summary && ( ! apiOperationExprProperties || ! hasPropertyKey ( "summary" , apiOperationExprProperties ) ) ) {
144
+ properties . push ( ts . createPropertyAssignment ( "summary" , ts . createLiteral ( summary ) ) ) ;
145
+ }
146
+
147
+ const remarks = docNodeToString ( docs . remarksBlock . content ) ;
148
+ if ( remarks && ( ! apiOperationExprProperties || ! hasPropertyKey ( "description" , apiOperationExprProperties ) ) ) {
149
+ properties . push ( ts . createPropertyAssignment ( "description" , ts . createLiteral ( remarks ) ) ) ;
150
+ }
127
151
}
128
- const properties = [
129
- ts . createPropertyAssignment (
130
- keyToGenerate ,
131
- ts . createLiteral ( extractedComments )
132
- ) ,
133
- ...( apiOperationExprProperties ?? ts . createNodeArray ( ) )
134
- ] ;
152
+
135
153
const apiOperationDecoratorArguments : ts . NodeArray < ts . Expression > = ts . createNodeArray (
136
- [ ts . createObjectLiteral ( compact ( properties ) ) ]
154
+ [ ts . createObjectLiteral ( compact ( [
155
+ ...properties ,
156
+ ...( apiOperationExprProperties ?? ts . createNodeArray ( ) )
157
+ ] ) ) ]
137
158
) ;
159
+
138
160
if ( apiOperationDecorator ) {
139
161
( ( apiOperationDecorator . expression as ts . CallExpression ) as any ) . arguments = apiOperationDecoratorArguments ;
140
162
} else {
0 commit comments