@@ -11,6 +11,7 @@ import { ParameterGenerator } from './parameterGenerator';
1111import { Tsoa } from '@namecheap/tsoa-runtime' ;
1212import { TypeResolver } from './typeResolver' ;
1313import { getHeaderType } from '../utils/headerTypeHelpers' ;
14+ import { DecoratorProcessorContext } from './types/nodeDecoratorProcessor' ;
1415
1516export class MethodGenerator {
1617 private method : 'options' | 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' ;
@@ -54,7 +55,7 @@ export class MethodGenerator {
5455 const additionalResponses = parameters . filter ( ( p ) : p is Tsoa . ResParameter => p . in === 'res' ) ;
5556 responses . push ( ...additionalResponses ) ;
5657
57- return {
58+ const methodMetadata : Tsoa . Method = {
5859 extensions : this . getExtensions ( ) ,
5960 deprecated : this . getIsDeprecated ( ) ,
6061 description : getJSDocDescription ( this . node ) ,
@@ -73,6 +74,10 @@ export class MethodGenerator {
7374 tags : this . getTags ( ) ,
7475 type,
7576 } ;
77+
78+ this . processCustomDecorators ( methodMetadata ) ;
79+
80+ return methodMetadata ;
7681 }
7782
7883 private buildParameters ( ) {
@@ -353,4 +358,26 @@ export class MethodGenerator {
353358 }
354359 return ;
355360 }
361+
362+ private processCustomDecorators ( methodMetadata : Tsoa . Method ) : void {
363+ if ( ! this . current . customDecoratorProcessors ) {
364+ return ;
365+ }
366+
367+ for ( const [ decoratorName , processor ] of Object . entries ( this . current . customDecoratorProcessors ) ) {
368+ const decorators = getDecorators ( this . node , identifier => identifier . text === decoratorName ) ;
369+
370+ for ( const decorator of decorators ) {
371+ try {
372+ const context : DecoratorProcessorContext = {
373+ methodObject : methodMetadata ,
374+ decoratorArguments : getDecoratorValues ( decorator , this . current . typeChecker ) ,
375+ } ;
376+ processor ( context ) ;
377+ } catch ( error ) {
378+ throw new GenerateMetadataError ( `Error in custom decorator processor for '${ decoratorName } '` , this . node ) ;
379+ }
380+ }
381+ }
382+ }
356383}
0 commit comments