Skip to content

Commit b8307c5

Browse files
authored
fix: add missing walk and visit methods for bindings. (#191)
1 parent e1830b9 commit b8307c5

File tree

4 files changed

+165
-10
lines changed

4 files changed

+165
-10
lines changed

src/LEGO.AsyncAPI/Services/AsyncApiVisitorBase.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,38 @@ public virtual void Visit(IDictionary<string, AsyncApiChannel> channels)
246246
{
247247
}
248248

249+
public virtual void Visit(AsyncApiBindings<IServerBinding> bindings)
250+
{
251+
}
252+
253+
public virtual void Visit(IServerBinding binding)
254+
{
255+
}
256+
257+
public virtual void Visit(AsyncApiBindings<IChannelBinding> bindings)
258+
{
259+
}
260+
261+
public virtual void Visit(IChannelBinding binding)
262+
{
263+
}
264+
265+
public virtual void Visit(AsyncApiBindings<IOperationBinding> bindings)
266+
{
267+
}
268+
269+
public virtual void Visit(IOperationBinding binding)
270+
{
271+
}
272+
273+
public virtual void Visit(AsyncApiBindings<IMessageBinding> bindings)
274+
{
275+
}
276+
277+
public virtual void Visit(IMessageBinding binding)
278+
{
279+
}
280+
249281
public virtual void Visit(AsyncApiChannel channel)
250282
{
251283
}

src/LEGO.AsyncAPI/Services/AsyncApiWalker.cs

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,48 @@ internal void Walk(AsyncApiComponents components)
7474
});
7575

7676
this.Walk(AsyncApiConstants.ServerBindings, () =>
77-
{
78-
if (components.ServerBindings != null)
79-
{
80-
foreach (var item in components.ServerBindings)
81-
{
82-
this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true));
83-
}
84-
}
85-
});
77+
{
78+
if (components.ServerBindings != null)
79+
{
80+
foreach (var item in components.ServerBindings)
81+
{
82+
this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true));
83+
}
84+
}
85+
});
86+
87+
this.Walk(AsyncApiConstants.ChannelBindings, () =>
88+
{
89+
if (components.ChannelBindings != null)
90+
{
91+
foreach (var item in components.ChannelBindings)
92+
{
93+
this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true));
94+
}
95+
}
96+
});
97+
98+
this.Walk(AsyncApiConstants.OperationBindings, () =>
99+
{
100+
if (components.OperationBindings != null)
101+
{
102+
foreach (var item in components.OperationBindings)
103+
{
104+
this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true));
105+
}
106+
}
107+
});
108+
109+
this.Walk(AsyncApiConstants.MessageBindings, () =>
110+
{
111+
if (components.MessageBindings != null)
112+
{
113+
foreach (var item in components.MessageBindings)
114+
{
115+
this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true));
116+
}
117+
}
118+
});
86119

87120
this.Walk(AsyncApiConstants.Parameters, () =>
88121
{
@@ -562,6 +595,25 @@ internal void Walk(AsyncApiBindings<IServerBinding> serverBindings, bool isCompo
562595
}
563596

564597
this.visitor.Visit(serverBindings);
598+
if (serverBindings != null)
599+
{
600+
foreach (var binding in serverBindings)
601+
{
602+
this.visitor.CurrentKeys.ServerBinding = binding.Key;
603+
this.Walk(binding.Key, () => this.Walk(binding.Value));
604+
this.visitor.CurrentKeys.ServerBinding = null;
605+
}
606+
}
607+
}
608+
609+
internal void Walk(IServerBinding binding)
610+
{
611+
if (binding == null)
612+
{
613+
return;
614+
}
615+
616+
this.visitor.Visit(binding);
565617
}
566618

567619
internal void Walk(AsyncApiBindings<IChannelBinding> channelBindings, bool isComponent = false)
@@ -572,6 +624,25 @@ internal void Walk(AsyncApiBindings<IChannelBinding> channelBindings, bool isCom
572624
}
573625

574626
this.visitor.Visit(channelBindings);
627+
if (channelBindings != null)
628+
{
629+
foreach (var binding in channelBindings)
630+
{
631+
this.visitor.CurrentKeys.ChannelBinding = binding.Key;
632+
this.Walk(binding.Key, () => this.Walk(binding.Value));
633+
this.visitor.CurrentKeys.ChannelBinding = null;
634+
}
635+
}
636+
}
637+
638+
internal void Walk(IChannelBinding binding)
639+
{
640+
if (binding == null)
641+
{
642+
return;
643+
}
644+
645+
this.visitor.Visit(binding);
575646
}
576647

577648
internal void Walk(AsyncApiBindings<IOperationBinding> operationBindings, bool isComponent = false)
@@ -582,6 +653,25 @@ internal void Walk(AsyncApiBindings<IOperationBinding> operationBindings, bool i
582653
}
583654

584655
this.visitor.Visit(operationBindings);
656+
if (operationBindings != null)
657+
{
658+
foreach (var binding in operationBindings)
659+
{
660+
this.visitor.CurrentKeys.OperationBinding = binding.Key;
661+
this.Walk(binding.Key, () => this.Walk(binding.Value));
662+
this.visitor.CurrentKeys.OperationBinding = null;
663+
}
664+
}
665+
}
666+
667+
internal void Walk(IOperationBinding binding)
668+
{
669+
if (binding == null)
670+
{
671+
return;
672+
}
673+
674+
this.visitor.Visit(binding);
585675
}
586676

587677
internal void Walk(AsyncApiBindings<IMessageBinding> messageBindings, bool isComponent = false)
@@ -592,6 +682,25 @@ internal void Walk(AsyncApiBindings<IMessageBinding> messageBindings, bool isCom
592682
}
593683

594684
this.visitor.Visit(messageBindings);
685+
if (messageBindings != null)
686+
{
687+
foreach (var binding in messageBindings)
688+
{
689+
this.visitor.CurrentKeys.MessageBinding = binding.Key;
690+
this.Walk(binding.Key, () => this.Walk(binding.Value));
691+
this.visitor.CurrentKeys.MessageBinding = null;
692+
}
693+
}
694+
}
695+
696+
internal void Walk(IMessageBinding binding)
697+
{
698+
if (binding == null)
699+
{
700+
return;
701+
}
702+
703+
this.visitor.Visit(binding);
595704
}
596705

597706
internal void Walk(IList<AsyncApiMessageExample> examples)

src/LEGO.AsyncAPI/Services/CurrentKeys.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ namespace LEGO.AsyncAPI.Services
44
{
55
public class CurrentKeys
66
{
7-
public string ServerBindings { get; internal set; }
7+
public string ServerBinding { get; internal set; }
8+
9+
public string ChannelBinding { get; internal set; }
10+
11+
public string OperationBinding { get; internal set; }
12+
13+
public string MessageBinding { get; internal set; }
814

915
public string Channel { get; internal set; }
1016

src/LEGO.AsyncAPI/Validation/AsyncApiValidator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ public void AddWarning(AsyncApiValidatorWarning warning)
136136
/// <param name="item">The object to be validated.</param>
137137
public override void Visit(AsyncApiServer item) => this.Validate(item);
138138

139+
public override void Visit(IServerBinding item) => this.Validate(item);
140+
141+
public override void Visit(IChannelBinding item) => this.Validate(item);
142+
143+
public override void Visit(IOperationBinding item) => this.Validate(item);
144+
145+
public override void Visit(IMessageBinding item) => this.Validate(item);
146+
139147
/// <summary>
140148
/// Execute validation rules against an <see cref="IAsyncApiExtensible"/>.
141149
/// </summary>

0 commit comments

Comments
 (0)