Skip to content

Commit

Permalink
Merge branch 'main' into extend-aws-policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadam8 authored Aug 6, 2024
2 parents c20ad8d + c90f41d commit ec23ee5
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 67 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## [5.2.4](https://github.com/LEGO/AsyncAPI.NET/compare/v5.2.3...v5.2.4) (2024-07-29)


### Bug Fixes

* remove persistence nullability ([52165f2](https://github.com/LEGO/AsyncAPI.NET/commit/52165f213502d9436e25a4e761804b5796b5de8c))

## [5.2.3](https://github.com/LEGO/AsyncAPI.NET/compare/v5.2.2...v5.2.3) (2024-07-29)


### Bug Fixes

* add missing walk and visit methods for bindings. ([#191](https://github.com/LEGO/AsyncAPI.NET/issues/191)) ([b8307c5](https://github.com/LEGO/AsyncAPI.NET/commit/b8307c57a6f9bc7c546702c24dffdfb1833aa5d3))

## [5.2.2](https://github.com/LEGO/AsyncAPI.NET/compare/v5.2.1...v5.2.2) (2024-07-29)


### Bug Fixes

* correct typing of exclusive maximums and minimums for draft7 jso… ([#188](https://github.com/LEGO/AsyncAPI.NET/issues/188)) ([fb50d00](https://github.com/LEGO/AsyncAPI.NET/commit/fb50d00192896f9ac26e65df1e991854b33aa17c))
* resolving wrong reference ([#180](https://github.com/LEGO/AsyncAPI.NET/issues/180)) ([47685cd](https://github.com/LEGO/AsyncAPI.NET/commit/47685cd19c7e58391625be043b1e5d82c49eedc8))

## [5.2.1](https://github.com/LEGO/AsyncAPI.NET/compare/v5.2.0...v5.2.1) (2024-06-12)


Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Pulsar/PulsarChannelBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PulsarChannelBinding : ChannelBinding<PulsarChannelBinding>
/// <summary>
/// persistence of the topic in Pulsar persistent or non-persistent.
/// </summary>
public Persistence? Persistence { get; set; }
public Persistence Persistence { get; set; }

/// <summary>
/// Topic compaction threshold given in bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,6 @@ namespace LEGO.AsyncAPI.Models
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;

public static class BindingExtensions
{
public static bool TryGetValue<TBinding>(this AsyncApiBindings<IServerBinding> bindings, out IServerBinding binding)
where TBinding : IServerBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IChannelBinding> bindings, out IChannelBinding binding)
where TBinding : IChannelBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IOperationBinding> bindings, out IOperationBinding binding)
where TBinding : IOperationBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IMessageBinding> bindings, out IMessageBinding binding)
where TBinding : IMessageBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}
}

public class AsyncApiBindings<TBinding> : Dictionary<string, TBinding>, IAsyncApiReferenceable
where TBinding : IBinding
{
Expand Down
62 changes: 62 additions & 0 deletions src/LEGO.AsyncAPI/Models/BindingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Models
{
using System;
using LEGO.AsyncAPI.Models.Interfaces;

public static class BindingExtensions
{
public static bool TryGetValue<TBinding>(this AsyncApiBindings<IServerBinding> bindings, out TBinding binding)
where TBinding : class, IServerBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var serverBinding))
{
binding = serverBinding as TBinding;
return true;
}

binding = default;
return false;
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IChannelBinding> bindings, out TBinding binding)
where TBinding : class, IChannelBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var channelBinding))
{
binding = channelBinding as TBinding;
return true;
}

binding = default;
return false;
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IOperationBinding> bindings, out TBinding binding)
where TBinding : class, IOperationBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var operationBinding))
{
binding = operationBinding as TBinding;
return true;
}

binding = default;
return false;
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IMessageBinding> bindings, out TBinding binding)
where TBinding : class, IMessageBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var messageBinding))
{
binding = messageBinding as TBinding;
return true;
}

binding = default;
return false;
}
}
}
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> bindings)
{
}

public virtual void Visit(IServerBinding binding)
{
}

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

public virtual void Visit(IChannelBinding binding)
{
}

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

public virtual void Visit(IOperationBinding binding)
{
}

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

public virtual void Visit(IMessageBinding binding)
{
}

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
Loading

0 comments on commit ec23ee5

Please sign in to comment.