@@ -26,19 +26,29 @@ type ClassDecorator = (
26
26
*/
27
27
export const Controller =
28
28
( pathPrefix : string = "" ) : ClassDecorator => ( target , context ) : void => {
29
+ const ctrlClassName = target . name ;
29
30
debug (
30
- `invoking ControllerDecorator for ${ target . name } -` ,
31
+ `invoking ControllerDecorator for ${ ctrlClassName } -` ,
31
32
"runtime provides context:" ,
32
33
context ,
33
34
) ;
34
35
const fnNames : string [ ] = Object . getOwnPropertyNames ( target . prototype ) ;
35
36
for ( const fnName of fnNames ) {
36
37
const pair = store . get ( fnName ) ;
37
38
if ( ! pair ) continue ;
38
- pair . forEach ( ( path , verb , p ) => {
39
+ const patchedPair = new Map ( ) ;
40
+ pair . forEach ( ( verb , path ) => {
39
41
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 ) ;
42
49
} ) ;
50
+ store . delete ( fnName ) ;
51
+ const fqFnName = `${ ctrlClassName } .${ fnName } ` ;
52
+ store . set ( fqFnName , patchedPair ) ;
43
53
}
44
54
} ;
0 commit comments