@@ -1592,10 +1592,27 @@ function insertMethodMacros(template, methodObj, platformApi, appApi, templates,
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 ( '' ) : ''
15941594 const eventForSubscriber = getNotifierForMethod ( method , appApi )
1595- let eventAllParams = ( eventForSubscriber && eventForSubscriber . params && eventForSubscriber . params . length ) ? getTemplate ( '/sections/parameters' , templates ) + eventForSubscriber . params . map ( p => insertParameterMacros ( getTemplate ( '/parameters/default' , templates ) , p , eventForSubscriber , appApi ) ) . join ( ', ' ) : ''
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+ }
15961613
15971614 if ( isGeneratingDocs ( languages ) ) {
1598- eventAllParams = isEventMethod ( methodObj ) && event . result ? Types . getMethodSignatureResult ( event , currentModuleApiForEvent , { callback : true , namespace : ! config . copySchemasIntoModules } ) : ''
1615+ eventNonContextualParams = isEventMethod ( methodObj ) && event . result ? Types . getMethodSignatureResult ( event , currentModuleApiForEvent , { callback : true , namespace : ! config . copySchemasIntoModules } ) : ''
15991616 // If there's a notifier for this method, and it has examples, use its params for the eventParams section
16001617 if ( eventForSubscriber && eventForSubscriber . examples && eventForSubscriber . examples . length ) {
16011618 eventParams = ( eventForSubscriber . params && eventForSubscriber . params . length ) ?
@@ -1800,7 +1817,7 @@ function insertMethodMacros(template, methodObj, platformApi, appApi, templates,
18001817 . 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
18011818 . 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 } ) )
18021819 // todo: what does prefix do?
1803- . replace ( / \$ \{ e v e n t \. r e s u l t \. t y p e \} / g, isEventMethod ( methodObj ) && eventAllParams ? eventAllParams : '' )
1820+ . replace ( / \$ \{ e v e n t \. r e s u l t \. t y p e \} / g, isEventMethod ( methodObj ) && eventNonContextualParams ? eventNonContextualParams : '' )
18041821 . replace ( / \$ \{ e v e n t \. r e s u l t \. j s o n \. t y p e \} / g, resultJsonType )
18051822 . replace ( / \$ \{ e v e n t \. r e s u l t \. j s o n \. t y p e \} / g, callbackResultJsonType )
18061823 . 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