1- namespace ByteBard . AsyncAPI . Readers
1+ namespace ByteBard . AsyncAPI . Readers
22{
3- using ByteBard . AsyncAPI . Exceptions ;
43 using ByteBard . AsyncAPI . Extensions ;
54 using ByteBard . AsyncAPI . Models ;
65 using ByteBard . AsyncAPI . Models . Interfaces ;
76 using ByteBard . AsyncAPI . Readers . ParseNodes ;
87
98 internal static partial class AsyncApiV3Deserializer
109 {
10+ private static readonly PatternFieldMap < AsyncApiBindings < IChannelBinding > > channelBindingPatternFields =
11+ new ( )
12+ {
13+ { s => s . StartsWith ( "x-" ) , ( o , p , n ) => o . AddExtension ( p , LoadExtension ( p , n ) ) } ,
14+ } ;
15+
1116 internal static AsyncApiBindings < IChannelBinding > LoadChannelBindings ( ParseNode node )
1217 {
1318 var mapNode = node . CheckMapNode ( "channelBindings" ) ;
@@ -17,50 +22,7 @@ internal static AsyncApiBindings<IChannelBinding> LoadChannelBindings(ParseNode
1722 return new AsyncApiBindingsReference < IChannelBinding > ( pointer ) ;
1823 }
1924
20- var channelBindings = new AsyncApiBindings < IChannelBinding > ( ) ;
21- foreach ( var property in mapNode )
22- {
23- var channelBinding = LoadChannelBinding ( property ) ;
24-
25- if ( channelBinding != null )
26- {
27- channelBindings . Add ( channelBinding ) ;
28- }
29- else
30- {
31- mapNode . Context . Diagnostic . Errors . Add (
32- new AsyncApiError ( node . Context . GetLocation ( ) , $ "ChannelBinding { property . Name } is not found") ) ;
33- }
34- }
35-
36- mapNode . ParseFields ( channelBindings , channelBindingPatternFields ) ;
37-
38- return channelBindings ;
39- }
40-
41- private static readonly PatternFieldMap < AsyncApiBindings < IChannelBinding > > channelBindingPatternFields =
42- new ( )
43- {
44- { s => s . StartsWith ( "x-" ) , ( o , p , n ) => o . AddExtension ( p , LoadExtension ( p , n ) ) } ,
45- } ;
46-
47- private static IChannelBinding LoadChannelBinding ( ParseNode node )
48- {
49- var property = node as PropertyNode ;
50- try
51- {
52- if ( node . Context . ChannelBindingParsers . TryGetValue ( property . Name , out var parser ) )
53- {
54- return parser . LoadBinding ( property ) ;
55- }
56- }
57- catch ( AsyncApiException ex )
58- {
59- ex . Pointer = node . Context . GetLocation ( ) ;
60- node . Context . Diagnostic . Errors . Add ( new AsyncApiError ( ex ) ) ;
61- }
62-
63- return null ;
25+ return BindingDeserializer . LoadBindings ( mapNode , node . Context . ChannelBindingParsers , channelBindingPatternFields ) ;
6426 }
6527 }
6628}
0 commit comments