@@ -6,17 +6,15 @@ import { Operations } from './operations';
6
6
import { Operation } from './operation' ;
7
7
import { Servers } from './servers' ;
8
8
import { Server } from './server' ;
9
-
9
+ import { xParserObjectUniqueId } from '../../constants' ;
10
10
import { CoreModel } from './mixins' ;
11
-
12
11
import type { ChannelInterface } from '../channel' ;
13
12
import type { ChannelParametersInterface } from '../channel-parameters' ;
14
13
import type { MessagesInterface } from '../messages' ;
15
14
import type { OperationsInterface } from '../operations' ;
16
15
import type { OperationInterface } from '../operation' ;
17
16
import type { ServersInterface } from '../servers' ;
18
17
import type { ServerInterface } from '../server' ;
19
-
20
18
import type { v3 } from '../../spec-types' ;
21
19
22
20
export class Channel extends CoreModel < v3 . ChannelObject , { id : string } > implements ChannelInterface {
@@ -30,8 +28,8 @@ export class Channel extends CoreModel<v3.ChannelObject, { id: string }> impleme
30
28
31
29
servers ( ) : ServersInterface {
32
30
const servers : ServerInterface [ ] = [ ] ;
33
- const allowedServers = this . _json . servers || [ ] ;
34
- Object . entries ( this . _meta . asyncapi ?. parsed . servers || { } ) . forEach ( ( [ serverName , server ] ) => {
31
+ const allowedServers = this . _json . servers ?? [ ] ;
32
+ Object . entries ( this . _meta . asyncapi ?. parsed . servers ?? { } ) . forEach ( ( [ serverName , server ] ) => {
35
33
if ( allowedServers . length === 0 || allowedServers . includes ( server ) ) {
36
34
servers . push ( this . createModel ( Server , server , { id : serverName , pointer : `/servers/${ serverName } ` } ) ) ;
37
35
}
@@ -41,8 +39,10 @@ export class Channel extends CoreModel<v3.ChannelObject, { id: string }> impleme
41
39
42
40
operations ( ) : OperationsInterface {
43
41
const operations : OperationInterface [ ] = [ ] ;
44
- Object . entries ( ( ( this . _meta . asyncapi ?. parsed as v3 . AsyncAPIObject ) ?. operations || { } ) ) . forEach ( ( [ operationId , operation ] ) => {
45
- if ( ( operation as v3 . OperationObject ) . channel === this . _json ) {
42
+ Object . entries ( ( ( this . _meta . asyncapi ?. parsed as v3 . AsyncAPIObject ) ?. operations ?? { } as v3 . OperationsObject ) ) . forEach ( ( [ operationId , operation ] ) => {
43
+ const operationChannelId = ( ( operation as v3 . OperationObject ) . channel as any ) [ xParserObjectUniqueId ] ;
44
+ const channelId = ( this . _json as any ) [ xParserObjectUniqueId ] ;
45
+ if ( operationChannelId === channelId ) {
46
46
operations . push (
47
47
this . createModel ( Operation , operation as v3 . OperationObject , { id : operationId , pointer : `/operations/${ operationId } ` } ) ,
48
48
) ;
@@ -53,15 +53,15 @@ export class Channel extends CoreModel<v3.ChannelObject, { id: string }> impleme
53
53
54
54
messages ( ) : MessagesInterface {
55
55
return new Messages (
56
- Object . entries ( this . _json . messages || { } ) . map ( ( [ messageName , message ] ) => {
56
+ Object . entries ( this . _json . messages ?? { } ) . map ( ( [ messageName , message ] ) => {
57
57
return this . createModel ( Message , message as v3 . MessageObject , { id : messageName , pointer : this . jsonPath ( `messages/${ messageName } ` ) } ) ;
58
58
} )
59
59
) ;
60
60
}
61
61
62
62
parameters ( ) : ChannelParametersInterface {
63
63
return new ChannelParameters (
64
- Object . entries ( this . _json . parameters || { } ) . map ( ( [ channelParameterName , channelParameter ] ) => {
64
+ Object . entries ( this . _json . parameters ?? { } ) . map ( ( [ channelParameterName , channelParameter ] ) => {
65
65
return this . createModel ( ChannelParameter , channelParameter as v3 . ParameterObject , {
66
66
id : channelParameterName ,
67
67
pointer : this . jsonPath ( `parameters/${ channelParameterName } ` ) ,
0 commit comments