@@ -22,11 +22,11 @@ interface ServerAsyncApi {
22
22
[ key : string ] : {
23
23
description ?: string ;
24
24
subscribe ?: {
25
- message : Message ;
25
+ message : Message | { oneOf : Message [ ] } ;
26
26
bindings ?: any ;
27
27
} ;
28
28
publish ?: {
29
- message : Message ;
29
+ message : Message | { oneOf : Message [ ] } ;
30
30
bindings ?: any ;
31
31
} ;
32
32
} ;
@@ -82,43 +82,47 @@ export class AsyncApiService {
82
82
} ;
83
83
}
84
84
85
- private mapServers ( servers : { [ key : string ] : Server } ) : Map < string , Server > {
85
+ private mapServers ( servers : ServerAsyncApi [ "servers" ] ) : Map < string , Server > {
86
86
const s = new Map < string , Server > ( ) ;
87
87
Object . entries ( servers ) . forEach ( ( [ k , v ] ) => s . set ( k , v ) ) ;
88
88
return s ;
89
89
}
90
90
91
- private mapChannels ( channels : {
92
- [ key : string ] : {
93
- description ?: string ;
94
- subscribe ?: {
95
- message : Message ;
96
- bindings ?: any ;
97
- } ;
98
- publish ?: {
99
- message : Message | { oneOf : Message [ ] } ;
100
- bindings ?: any ;
101
- } ;
102
- }
103
- } ) : Channel [ ] {
91
+ private mapChannels ( channels : ServerAsyncApi [ "channels" ] ) : Channel [ ] {
104
92
const s = new Array < Channel > ( ) ;
105
93
Object . entries ( channels ) . forEach ( ( [ k , v ] ) => {
106
- let operation = v . publish ? v . publish : v . subscribe ;
107
- let isSubscribe = ! ! v . subscribe ;
94
+ const subscriberChannels = this . mapChannel ( k , v . description , v . subscribe , " consumer" )
95
+ subscriberChannels . forEach ( channel => s . push ( channel ) )
108
96
109
- let messages : Message [ ] = 'oneOf' in operation . message ? operation . message . oneOf : [ operation . message ] ;
110
- messages . forEach ( message => s . push ( {
111
- name : k ,
112
- description : v . description ,
113
- operation : this . mapOperation ( isSubscribe , message , operation . bindings )
114
- } ) )
97
+ const publisherChannels = this . mapChannel ( k , v . description , v . publish , " producer" )
98
+ publisherChannels . forEach ( channel => s . push ( channel ) )
115
99
} ) ;
116
100
return s ;
117
101
}
118
102
119
- private mapOperation ( isSubscribe : boolean , message : Message , bindings ?: any ) : Operation {
103
+ private mapChannel (
104
+ topicName : string ,
105
+ description : ServerAsyncApi [ "channels" ] [ "" ] [ "description" ] ,
106
+ operation : ServerAsyncApi [ "channels" ] [ "" ] [ "subscribe" ] | ServerAsyncApi [ "channels" ] [ "" ] [ "publish" ] ,
107
+ operationName : string ) : Channel [ ]
108
+ {
109
+ if ( operation !== undefined ) {
110
+ let messages : Message [ ] = 'oneOf' in operation . message ? operation . message . oneOf : [ operation . message ] ;
111
+
112
+ return messages . map ( message => {
113
+ return {
114
+ name : topicName ,
115
+ description : description ,
116
+ operation : this . mapOperation ( operationName , message , operation . bindings )
117
+ }
118
+ } )
119
+ }
120
+ return [ ] ;
121
+ }
122
+
123
+ private mapOperation ( operationName : string , message : Message , bindings ?: any ) : Operation {
120
124
return {
121
- type : this . getProtocol ( bindings ) + ( isSubscribe ? " producer" : " consumer" ) ,
125
+ type : this . getProtocol ( bindings ) + operationName ,
122
126
message : message ,
123
127
bindings : bindings
124
128
}
0 commit comments