@@ -1591,9 +1591,28 @@ function insertMethodMacros(template, methodObj, platformApi, appApi, templates,
15911591
15921592
15931593 let eventParams = event . params && event . params . length ? getTemplate ( '/sections/parameters' , templates ) + event . params . map ( p => insertParameterMacros ( getTemplate ( '/parameters/default' , templates ) , p , event , currentModuleApiForEvent ) ) . join ( '' ) : ''
1594-
1594+ const eventForSubscriber = getNotifierForMethod ( method , appApi )
1595+
1596+ // Filter parameters to remove context parameters, because only non-context parameters are parameters for the event callback
1597+ let xContextParams = 0
1598+ let eventNonContextualParams = ''
1599+ if ( eventForSubscriber ) {
1600+ if ( eventForSubscriber . tags ) {
1601+ const tag = eventForSubscriber . tags . find ( tag => tag . name === 'notifier' ) ;
1602+ xContextParams = tag [ 'x-contextual-params' ] || 0
1603+ }
1604+
1605+ if ( eventForSubscriber . params && eventForSubscriber . params . length ) {
1606+ if ( xContextParams > 0 ) {
1607+ const nonContextParamsArray = eventForSubscriber . params . slice ( xContextParams , eventForSubscriber . params . length )
1608+ eventNonContextualParams = getTemplate ( '/sections/parameters' , templates ) + nonContextParamsArray . map ( p => insertParameterMacros ( getTemplate ( '/parameters/default' , templates ) , p , eventForSubscriber , appApi ) ) . join ( ', ' )
1609+ } else
1610+ eventNonContextualParams = getTemplate ( '/sections/parameters' , templates ) + eventForSubscriber . params . map ( p => insertParameterMacros ( getTemplate ( '/parameters/default' , templates ) , p , eventForSubscriber , appApi ) ) . join ( ', ' )
1611+ }
1612+ }
1613+
15951614 if ( isGeneratingDocs ( languages ) ) {
1596- const eventForSubscriber = getNotifierForMethod ( method , appApi )
1615+ eventNonContextualParams = isEventMethod ( methodObj ) && event . result ? Types . getMethodSignatureResult ( event , currentModuleApiForEvent , { callback : true , namespace : ! config . copySchemasIntoModules } ) : ''
15971616 // If there's a notifier for this method, and it has examples, use its params for the eventParams section
15981617 if ( eventForSubscriber && eventForSubscriber . examples && eventForSubscriber . examples . length ) {
15991618 eventParams = ( eventForSubscriber . params && eventForSubscriber . params . length ) ?
@@ -1729,7 +1748,6 @@ function insertMethodMacros(template, methodObj, platformApi, appApi, templates,
17291748 }
17301749 }
17311750
1732-
17331751 template = insertExampleMacros ( template , examples || [ ] , methodObj , platformApi , templates , appApi , isGeneratingDocs ( languages ) )
17341752
17351753 template = template . replace ( / \$ \{ m e t h o d \. n a m e \} / g, method . name )
@@ -1799,7 +1817,7 @@ function insertMethodMacros(template, methodObj, platformApi, appApi, templates,
17991817 . replace ( / \$ \{ m e t h o d \. r e s u l t \. t y p e \} / g, Types . getSchemaType ( result . schema , platformApi , { templateDir : state . typeTemplateDir , title : true , asPath : false , result : true , namespace : false } ) ) //, baseUrl: options.baseUrl
18001818 . replace ( / \$ \{ m e t h o d \. r e s u l t \. j s o n \} / g, Types . getSchemaType ( result . schema . type === 'null' ? getNonNullSchema ( methodObj , event , platformApi , appApi ) : result . schema , platformApi , { templateDir : 'json-types' , title : true , code : false , link : false , asPath : false , expandEnums : false , namespace : true } ) )
18011819 // todo: what does prefix do?
1802- . replace ( / \$ \{ e v e n t \. r e s u l t \. t y p e \} / g, isEventMethod ( methodObj ) && event . result ? Types . getMethodSignatureResult ( event , currentModuleApiForEvent , { callback : true , namespace : ! config . copySchemasIntoModules } ) : '' )
1820+ . replace ( / \$ \{ e v e n t \. r e s u l t \. t y p e \} / g, isEventMethod ( methodObj ) && eventNonContextualParams ? eventNonContextualParams : '' )
18031821 . replace ( / \$ \{ e v e n t \. r e s u l t \. j s o n \. t y p e \} / g, resultJsonType )
18041822 . replace ( / \$ \{ e v e n t \. r e s u l t \. j s o n \. t y p e \} / g, callbackResultJsonType )
18051823 . replace ( / \$ \{ e v e n t \. p u l l s \. p a r a m \. n a m e \} / g, pullsEventParamName )
0 commit comments