From b3ba8294f7ac76616f3675078f2489d92aad53c4 Mon Sep 17 00:00:00 2001 From: VisualBean Date: Mon, 29 Jul 2024 13:43:52 +0200 Subject: [PATCH] fix: walking bindings --- .../Services/AsyncApiVisitorBase.cs | 32 +++++ src/LEGO.AsyncAPI/Services/AsyncApiWalker.cs | 127 ++++++++++++++++-- src/LEGO.AsyncAPI/Services/CurrentKeys.cs | 8 +- .../Validation/AsyncApiValidator.cs | 8 ++ 4 files changed, 165 insertions(+), 10 deletions(-) diff --git a/src/LEGO.AsyncAPI/Services/AsyncApiVisitorBase.cs b/src/LEGO.AsyncAPI/Services/AsyncApiVisitorBase.cs index 8e3dc241..899731d0 100644 --- a/src/LEGO.AsyncAPI/Services/AsyncApiVisitorBase.cs +++ b/src/LEGO.AsyncAPI/Services/AsyncApiVisitorBase.cs @@ -246,6 +246,38 @@ public virtual void Visit(IDictionary channels) { } + public virtual void Visit(AsyncApiBindings bindings) + { + } + + public virtual void Visit(IServerBinding binding) + { + } + + public virtual void Visit(AsyncApiBindings bindings) + { + } + + public virtual void Visit(IChannelBinding binding) + { + } + + public virtual void Visit(AsyncApiBindings bindings) + { + } + + public virtual void Visit(IOperationBinding binding) + { + } + + public virtual void Visit(AsyncApiBindings bindings) + { + } + + public virtual void Visit(IMessageBinding binding) + { + } + public virtual void Visit(AsyncApiChannel channel) { } diff --git a/src/LEGO.AsyncAPI/Services/AsyncApiWalker.cs b/src/LEGO.AsyncAPI/Services/AsyncApiWalker.cs index fc5c5186..844ab7e9 100644 --- a/src/LEGO.AsyncAPI/Services/AsyncApiWalker.cs +++ b/src/LEGO.AsyncAPI/Services/AsyncApiWalker.cs @@ -74,15 +74,48 @@ internal void Walk(AsyncApiComponents components) }); this.Walk(AsyncApiConstants.ServerBindings, () => - { - if (components.ServerBindings != null) - { - foreach (var item in components.ServerBindings) - { - this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true)); - } - } - }); + { + if (components.ServerBindings != null) + { + foreach (var item in components.ServerBindings) + { + this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true)); + } + } + }); + + this.Walk(AsyncApiConstants.ChannelBindings, () => + { + if (components.ChannelBindings != null) + { + foreach (var item in components.ChannelBindings) + { + this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true)); + } + } + }); + + this.Walk(AsyncApiConstants.OperationBindings, () => + { + if (components.OperationBindings != null) + { + foreach (var item in components.OperationBindings) + { + this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true)); + } + } + }); + + this.Walk(AsyncApiConstants.MessageBindings, () => + { + if (components.MessageBindings != null) + { + foreach (var item in components.MessageBindings) + { + this.Walk(item.Key, () => this.Walk(item.Value, isComponent: true)); + } + } + }); this.Walk(AsyncApiConstants.Parameters, () => { @@ -562,6 +595,25 @@ internal void Walk(AsyncApiBindings serverBindings, bool isCompo } this.visitor.Visit(serverBindings); + if (serverBindings != null) + { + foreach (var binding in serverBindings) + { + this.visitor.CurrentKeys.ServerBinding = binding.Key; + this.Walk(binding.Key, () => this.Walk(binding.Value)); + this.visitor.CurrentKeys.ServerBinding = null; + } + } + } + + internal void Walk(IServerBinding binding) + { + if (binding == null) + { + return; + } + + this.visitor.Visit(binding); } internal void Walk(AsyncApiBindings channelBindings, bool isComponent = false) @@ -572,6 +624,25 @@ internal void Walk(AsyncApiBindings channelBindings, bool isCom } this.visitor.Visit(channelBindings); + if (channelBindings != null) + { + foreach (var binding in channelBindings) + { + this.visitor.CurrentKeys.ChannelBinding = binding.Key; + this.Walk(binding.Key, () => this.Walk(binding.Value)); + this.visitor.CurrentKeys.ChannelBinding = null; + } + } + } + + internal void Walk(IChannelBinding binding) + { + if (binding == null) + { + return; + } + + this.visitor.Visit(binding); } internal void Walk(AsyncApiBindings operationBindings, bool isComponent = false) @@ -582,6 +653,25 @@ internal void Walk(AsyncApiBindings operationBindings, bool i } this.visitor.Visit(operationBindings); + if (operationBindings != null) + { + foreach (var binding in operationBindings) + { + this.visitor.CurrentKeys.OperationBinding = binding.Key; + this.Walk(binding.Key, () => this.Walk(binding.Value)); + this.visitor.CurrentKeys.OperationBinding = null; + } + } + } + + internal void Walk(IOperationBinding binding) + { + if (binding == null) + { + return; + } + + this.visitor.Visit(binding); } internal void Walk(AsyncApiBindings messageBindings, bool isComponent = false) @@ -592,6 +682,25 @@ internal void Walk(AsyncApiBindings messageBindings, bool isCom } this.visitor.Visit(messageBindings); + if (messageBindings != null) + { + foreach (var binding in messageBindings) + { + this.visitor.CurrentKeys.MessageBinding = binding.Key; + this.Walk(binding.Key, () => this.Walk(binding.Value)); + this.visitor.CurrentKeys.MessageBinding = null; + } + } + } + + internal void Walk(IMessageBinding binding) + { + if (binding == null) + { + return; + } + + this.visitor.Visit(binding); } internal void Walk(IList examples) diff --git a/src/LEGO.AsyncAPI/Services/CurrentKeys.cs b/src/LEGO.AsyncAPI/Services/CurrentKeys.cs index 3544eb21..f610aabb 100644 --- a/src/LEGO.AsyncAPI/Services/CurrentKeys.cs +++ b/src/LEGO.AsyncAPI/Services/CurrentKeys.cs @@ -4,7 +4,13 @@ namespace LEGO.AsyncAPI.Services { public class CurrentKeys { - public string ServerBindings { get; internal set; } + public string ServerBinding { get; internal set; } + + public string ChannelBinding { get; internal set; } + + public string OperationBinding { get; internal set; } + + public string MessageBinding { get; internal set; } public string Channel { get; internal set; } diff --git a/src/LEGO.AsyncAPI/Validation/AsyncApiValidator.cs b/src/LEGO.AsyncAPI/Validation/AsyncApiValidator.cs index 4ce96627..3f8bf392 100644 --- a/src/LEGO.AsyncAPI/Validation/AsyncApiValidator.cs +++ b/src/LEGO.AsyncAPI/Validation/AsyncApiValidator.cs @@ -136,6 +136,14 @@ public void AddWarning(AsyncApiValidatorWarning warning) /// The object to be validated. public override void Visit(AsyncApiServer item) => this.Validate(item); + public override void Visit(IServerBinding item) => this.Validate(item); + + public override void Visit(IChannelBinding item) => this.Validate(item); + + public override void Visit(IOperationBinding item) => this.Validate(item); + + public override void Visit(IMessageBinding item) => this.Validate(item); + /// /// Execute validation rules against an . ///