Skip to content

Commit

Permalink
fix: walking bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed Jul 29, 2024
1 parent e1830b9 commit f15ad13
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 10 deletions.
32 changes: 32 additions & 0 deletions src/LEGO.AsyncAPI/Services/AsyncApiVisitorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,38 @@ public virtual void Visit(IDictionary<string, AsyncApiChannel> channels)
{
}

public virtual void Visit(AsyncApiBindings<IServerBinding> serverBindings)
{
}

public virtual void Visit(IServerBinding serverBinding)
{
}

public virtual void Visit(AsyncApiBindings<IChannelBinding> serverBindings)
{
}

public virtual void Visit(IChannelBinding serverBinding)
{
}

public virtual void Visit(AsyncApiBindings<IOperationBinding> serverBindings)
{
}

public virtual void Visit(IOperationBinding serverBinding)
{
}

public virtual void Visit(AsyncApiBindings<IMessageBinding> serverBindings)
{
}

public virtual void Visit(IMessageBinding serverBinding)
{
}

public virtual void Visit(AsyncApiChannel channel)
{
}
Expand Down
127 changes: 118 additions & 9 deletions src/LEGO.AsyncAPI/Services/AsyncApiWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, () =>
{
Expand Down Expand Up @@ -562,6 +595,25 @@ internal void Walk(AsyncApiBindings<IServerBinding> 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<IChannelBinding> channelBindings, bool isComponent = false)
Expand All @@ -572,6 +624,25 @@ internal void Walk(AsyncApiBindings<IChannelBinding> 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<IOperationBinding> operationBindings, bool isComponent = false)
Expand All @@ -582,6 +653,25 @@ internal void Walk(AsyncApiBindings<IOperationBinding> 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<IMessageBinding> messageBindings, bool isComponent = false)
Expand All @@ -592,6 +682,25 @@ internal void Walk(AsyncApiBindings<IMessageBinding> 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<AsyncApiMessageExample> examples)
Expand Down
8 changes: 7 additions & 1 deletion src/LEGO.AsyncAPI/Services/CurrentKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
8 changes: 8 additions & 0 deletions src/LEGO.AsyncAPI/Validation/AsyncApiValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public void AddWarning(AsyncApiValidatorWarning warning)
/// <param name="item">The object to be validated.</param>
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);

/// <summary>
/// Execute validation rules against an <see cref="IAsyncApiExtensible"/>.
/// </summary>
Expand Down

0 comments on commit f15ad13

Please sign in to comment.