@@ -118,17 +118,8 @@ export default class EventsGen extends BaseGen {
118118 const unique = camelCase ( this . formSingleUniqueName ( el ) )
119119 if ( isResourceLike ( el ) && ! el . future && el . events ) {
120120 const topic = this . topicOfRestResource ( el ) ;
121- channels [ topic ] = {
122- description :
123- this . translateDoc ( el . comment ) || "no documentation" ,
124- subscribe : {
125- summary : "REST: " + el . name ,
126- operationId : el . name ,
127- message : {
128- $ref : `#/components/messages/${ unique } `
129- }
130- }
131- }
121+ const channel = this . eventChannelForRestResource ( el , unique ) ;
122+ channels [ topic ] = channel
132123 }
133124 if ( isProduces ( el ) ) {
134125 produces . add ( el . event . name )
@@ -143,26 +134,8 @@ export default class EventsGen extends BaseGen {
143134 all . forEach ( ( name ) => {
144135 const def = this . extractDefinition ( name )
145136 const topic = this . topicOfAdhocEvent ( def ) ;
146- const unq = camelCase ( this . formSingleUniqueName ( def ) )
147- const details : any = {
148- description :
149- this . translateDoc ( def . comment ) || "no documentation"
150- }
151- const msg = {
152- summary : "Adhoc: " + def . name ,
153- operationId : def . name ,
154- message : {
155- $ref : `#/components/messages/${ unq } `
156- }
157- }
158- if ( produces . has ( name ) ) {
159- details . publish = msg
160- }
161- if ( consumes . has ( name ) ) {
162- details . subscribe = msg
163- }
164-
165- channels [ topic ] = details
137+ const channel = this . eventChannelForAdhocDefinition ( def , name , produces , consumes ) ;
138+ channels [ topic ] = channel
166139 } )
167140 }
168141
@@ -173,13 +146,55 @@ export default class EventsGen extends BaseGen {
173146 return this . toEventTopic ( ns , version , name ) ;
174147 }
175148
149+ private eventChannelForAdhocDefinition ( def : AnyKind , name : string , produces : Set < string > , consumes : Set < string > ) {
150+ const unq = camelCase ( this . formSingleUniqueName ( def ) )
151+ const channel : any = {
152+ description :
153+ this . translateDoc ( def . comment ) || "no documentation"
154+ }
155+ const operationBody = {
156+ summary : "Adhoc: " + def . name ,
157+ operationId : def . name ,
158+ message : {
159+ $ref : `#/components/messages/${ unq } `
160+ }
161+ }
162+ if ( produces . has ( name ) ) {
163+ channel . publish = operationBody
164+ }
165+ if ( consumes . has ( name ) ) {
166+ channel . subscribe = operationBody
167+ }
168+ return channel ;
169+ }
170+
176171 private topicOfRestResource ( el : IReference ) {
177172 let ns = kebabCase ( this . getSpace ( ) ) ;
178173 let version = getVersion ( el . name ) ;
179174 let name = kebabCase ( el . name ) ;
180175 return this . toEventTopic ( ns , version , name ) ;
181176 }
182177
178+ private eventChannelForRestResource ( el : IResourceLike , unique : string ) {
179+ const channelDescription = this . translateDoc ( el . comment ) || "no documentation" ;
180+ const subscribeOpDescription = el . events
181+ ?. map ( e => this . translateDoc ( e . comment ) )
182+ . filter ( d => ! ! d )
183+ . join ( "\n\n" ) ?? ""
184+ let channelForRestResource = {
185+ description : channelDescription ,
186+ subscribe : {
187+ summary : "REST: " + el . name ,
188+ description : subscribeOpDescription != "" ? subscribeOpDescription : null ,
189+ operationId : el . name ,
190+ message : {
191+ $ref : `#/components/messages/${ unique } `
192+ }
193+ }
194+ } ;
195+ return channelForRestResource ;
196+ }
197+
183198 private toEventTopic ( ns : string , version : string , name : string ) {
184199 const basic = `${ ns } _${ version } -${ name } ` ;
185200 const escaped = basic . replace ( / [ ^ a - z A - Z 0 - 9 _ - ] / , "_" ) ;
0 commit comments