@@ -26,19 +26,29 @@ type ClassDecorator = (
2626 */
2727export const Controller =
2828 ( pathPrefix : string = "" ) : ClassDecorator => ( target , context ) : void => {
29+ const ctrlClassName = target . name ;
2930 debug (
30- `invoking ControllerDecorator for ${ target . name } -` ,
31+ `invoking ControllerDecorator for ${ ctrlClassName } -` ,
3132 "runtime provides context:" ,
3233 context ,
3334 ) ;
3435 const fnNames : string [ ] = Object . getOwnPropertyNames ( target . prototype ) ;
3536 for ( const fnName of fnNames ) {
3637 const pair = store . get ( fnName ) ;
3738 if ( ! pair ) continue ;
38- pair . forEach ( ( path , verb , p ) => {
39+ const patchedPair = new Map ( ) ;
40+ pair . forEach ( ( verb , path ) => {
3941 const fullPath = join ( pathPrefix , path ) ;
40- p . set ( verb , fullPath ) ;
41- patchOasPath ( fnName , verb , fullPath ) ;
42+ patchedPair . set ( fullPath , verb ) ;
43+ debug (
44+ `[${ ctrlClassName } ] @Controller: patched [${ verb } ] ${ path } to ${ fullPath } ` ,
45+ ) ;
46+ // @TODO consider throwing if we discover 2 (or more) Controllers
47+ // sharing the exact same set of path, fnName, and method
48+ patchOasPath ( ctrlClassName , fnName , verb , fullPath ) ;
4249 } ) ;
50+ store . delete ( fnName ) ;
51+ const fqFnName = `${ ctrlClassName } .${ fnName } ` ;
52+ store . set ( fqFnName , patchedPair ) ;
4353 }
4454 } ;
0 commit comments