@@ -6,17 +6,15 @@ import { Operations } from './operations';
66import { Operation } from './operation' ;
77import { Servers } from './servers' ;
88import { Server } from './server' ;
9-
9+ import { xParserObjectUniqueId } from '../../constants' ;
1010import { CoreModel } from './mixins' ;
11-
1211import type { ChannelInterface } from '../channel' ;
1312import type { ChannelParametersInterface } from '../channel-parameters' ;
1413import type { MessagesInterface } from '../messages' ;
1514import type { OperationsInterface } from '../operations' ;
1615import type { OperationInterface } from '../operation' ;
1716import type { ServersInterface } from '../servers' ;
1817import type { ServerInterface } from '../server' ;
19-
2018import type { v3 } from '../../spec-types' ;
2119
2220export class Channel extends CoreModel < v3 . ChannelObject , { id : string } > implements ChannelInterface {
@@ -30,8 +28,8 @@ export class Channel extends CoreModel<v3.ChannelObject, { id: string }> impleme
3028
3129 servers ( ) : ServersInterface {
3230 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 ] ) => {
3533 if ( allowedServers . length === 0 || allowedServers . includes ( server ) ) {
3634 servers . push ( this . createModel ( Server , server , { id : serverName , pointer : `/servers/${ serverName } ` } ) ) ;
3735 }
@@ -41,8 +39,10 @@ export class Channel extends CoreModel<v3.ChannelObject, { id: string }> impleme
4139
4240 operations ( ) : OperationsInterface {
4341 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 ) {
4646 operations . push (
4747 this . createModel ( Operation , operation as v3 . OperationObject , { id : operationId , pointer : `/operations/${ operationId } ` } ) ,
4848 ) ;
@@ -53,15 +53,15 @@ export class Channel extends CoreModel<v3.ChannelObject, { id: string }> impleme
5353
5454 messages ( ) : MessagesInterface {
5555 return new Messages (
56- Object . entries ( this . _json . messages || { } ) . map ( ( [ messageName , message ] ) => {
56+ Object . entries ( this . _json . messages ?? { } ) . map ( ( [ messageName , message ] ) => {
5757 return this . createModel ( Message , message as v3 . MessageObject , { id : messageName , pointer : this . jsonPath ( `messages/${ messageName } ` ) } ) ;
5858 } )
5959 ) ;
6060 }
6161
6262 parameters ( ) : ChannelParametersInterface {
6363 return new ChannelParameters (
64- Object . entries ( this . _json . parameters || { } ) . map ( ( [ channelParameterName , channelParameter ] ) => {
64+ Object . entries ( this . _json . parameters ?? { } ) . map ( ( [ channelParameterName , channelParameter ] ) => {
6565 return this . createModel ( ChannelParameter , channelParameter as v3 . ParameterObject , {
6666 id : channelParameterName ,
6767 pointer : this . jsonPath ( `parameters/${ channelParameterName } ` ) ,
0 commit comments