Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace ByteBard.AsyncAPI.Bindings.AnypointMQ
{
using System;
using ByteBard.AsyncAPI.Models;
using ByteBard.AsyncAPI.Readers.ParseNodes;
using ByteBard.AsyncAPI.Writers;

/// <summary>Binding for an Anypoint MQ destination.</summary>
public class AnypointMQChannelBinding : ChannelBinding<AnypointMQChannelBinding>
{
public string Destination { get; set; }

public string DestinationType { get; set; }

public override string BindingKey => "anypointmq";

protected override FixedFieldMap<AnypointMQChannelBinding> FixedFieldMap => new()
{
{ "destination", (a, n) => { a.Destination = n.GetScalarValue(); } },
{ "destinationType", (a, n) => { a.DestinationType = n.GetScalarValue(); } },
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
};

/// <summary>
/// Writes the Anypoint MQ channel binding object and its extensions for AsyncAPI 2.0.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
public override void SerializeV2(IAsyncApiWriter writer) => this.SerializeV3(writer);

/// <summary>
/// Writes the Anypoint MQ channel binding object and its extensions for AsyncAPI 3.0.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
public override void SerializeV3(IAsyncApiWriter writer) => this.SerializeProperties(writer);

/// <summary>
/// Writes the Anypoint MQ channel binding object and its extensions for AsyncAPI 3.0.
/// </summary>
/// <remarks>An unset binding version is omitted.</remarks>
/// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
public override void SerializeProperties(IAsyncApiWriter writer)
{
if (writer is null) throw new ArgumentNullException(nameof(writer));
writer.WriteStartObject();
writer.WriteOptionalProperty("destination", this.Destination);
writer.WriteOptionalProperty("destinationType", this.DestinationType);
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace ByteBard.AsyncAPI.Bindings.AnypointMQ
{
using System;
using ByteBard.AsyncAPI.Models;
using ByteBard.AsyncAPI.Readers;
using ByteBard.AsyncAPI.Readers.ParseNodes;
using ByteBard.AsyncAPI.Writers;

/// <summary>Binding for an Anypoint MQ message.</summary>
public class AnypointMQMessageBinding : MessageBinding<AnypointMQMessageBinding>
{
/// <summary>Message headers described by a schema or schema reference.</summary>
public AsyncApiJsonSchema Headers { get; set; }

public override string BindingKey => "anypointmq";

protected override FixedFieldMap<AnypointMQMessageBinding> FixedFieldMap => new()
{
{ "headers", (a, n) => { a.Headers = AsyncApiJsonSchemaDeserializer.LoadSchema(n); } },
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
};

/// <summary>
/// Writes the Anypoint MQ message binding object and its extensions for AsyncAPI 2.0.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
public override void SerializeV2(IAsyncApiWriter writer)
{
if (writer is null) throw new ArgumentNullException(nameof(writer));
writer.WriteStartObject();
writer.WriteOptionalObject("headers", this.Headers, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}

/// <summary>
/// Writes the Anypoint MQ message binding object and its extensions for AsyncAPI 3.0.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
public override void SerializeV3(IAsyncApiWriter writer) => this.SerializeProperties(writer);

/// <summary>
/// Writes the Anypoint MQ message binding object and its extensions for AsyncAPI 3.0.
/// </summary>
/// <remarks>An unset binding version is omitted.</remarks>
/// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
public override void SerializeProperties(IAsyncApiWriter writer)
{
if (writer is null) throw new ArgumentNullException(nameof(writer));
writer.WriteStartObject();
writer.WriteOptionalObject("headers", this.Headers, (w, h) => h.SerializeV3(w));
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
}
}
15 changes: 13 additions & 2 deletions src/ByteBard.AsyncAPI.Bindings/BindingHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
namespace ByteBard.AsyncAPI.Bindings
{
using System;
using System.Collections.Generic;
using ByteBard.AsyncAPI.Models.Interfaces;
using ByteBard.AsyncAPI.Readers;
using ByteBard.AsyncAPI.Readers.ParseNodes;

public static class BindingHelpers
{
/// <summary>
/// Parses a nested object using the supplied field handlers.
/// </summary>
/// <param name="node">The nested object to parse.</param>
/// <param name="fixedFieldMap">Handlers for recognized property names; other properties follow the reader's unmapped-member setting.</param>
/// <returns>A new instance populated from recognized fields, which may be incomplete when field parsing reports errors.</returns>
/// <remarks>Field-level reader and AsyncAPI exceptions are recorded as diagnostics; other handler exceptions propagate.</remarks>
/// <exception cref="ByteBard.AsyncAPI.Readers.Exceptions.AsyncApiReaderException"><paramref name="node"/> is not a map.</exception>
public static T ParseMap<T>(this ParseNode node, FixedFieldMap<T> fixedFieldMap)
where T : new()
{
Expand All @@ -16,10 +26,11 @@ public static T ParseMap<T>(this ParseNode node, FixedFieldMap<T> fixedFieldMap)
}

var instance = new T();
var emptyPatternFields = new Dictionary<Func<string, bool>, Action<T, string, ParseNode>>();

foreach (var propertyNode in mapNode)
{
propertyNode.ParseField(instance, fixedFieldMap, null);
propertyNode.ParseField(instance, fixedFieldMap, emptyPatternFields);
}

return instance;
Expand All @@ -44,4 +55,4 @@ public static T ParseMapWithExtensions<T>(this ParseNode node, FixedFieldMap<T>
return instance;
}
}
}
}
116 changes: 70 additions & 46 deletions src/ByteBard.AsyncAPI.Bindings/BindingsCollection.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,59 @@
namespace ByteBard.AsyncAPI.Bindings
namespace ByteBard.AsyncAPI.Bindings
{
using System;
using System.Collections.Generic;
using ByteBard.AsyncAPI.Bindings.AMQP;
using ByteBard.AsyncAPI.Bindings.AnypointMQ;
using ByteBard.AsyncAPI.Bindings.GooglePubSub;
using ByteBard.AsyncAPI.Bindings.Http;
using ByteBard.AsyncAPI.Bindings.IBMMQ;
using ByteBard.AsyncAPI.Bindings.JMS;
using ByteBard.AsyncAPI.Bindings.Kafka;
using ByteBard.AsyncAPI.Bindings.MQTT;
using ByteBard.AsyncAPI.Bindings.MQTT5;
using ByteBard.AsyncAPI.Bindings.NATS;
using ByteBard.AsyncAPI.Bindings.Pulsar;
using ByteBard.AsyncAPI.Bindings.ROS2;
using ByteBard.AsyncAPI.Bindings.Sns;
using ByteBard.AsyncAPI.Bindings.Solace;
using ByteBard.AsyncAPI.Bindings.Sqs;
using ByteBard.AsyncAPI.Bindings.WebSockets;
using ByteBard.AsyncAPI.Models.Interfaces;
using ByteBard.AsyncAPI.Readers.Interface;

public static class BindingsCollection
{
public static TCollection Add<TCollection, TItem>(
this TCollection destination,
IEnumerable<TItem> source)
where TCollection : ICollection<TItem>
/// <summary>
/// Adds the source items to the destination collection.
/// </summary>
/// <returns>The same destination collection, after adding the items.</returns>
/// <remarks>Enumeration and collection errors propagate; items already added are not rolled back.</remarks>
/// <exception cref="ArgumentNullException"><paramref name="destination"/> or <paramref name="source"/> is null.</exception>
/// <exception cref="NotSupportedException">The destination collection does not support adding items.</exception>
public static TCollection Add<TCollection, TItem>(this TCollection destination, IEnumerable<TItem> source)
where TCollection : ICollection<TItem>
{
if (destination == null)
{
throw new ArgumentNullException(nameof(destination));
}

if (source == null)
{
throw new ArgumentNullException(nameof(source));
}

if (destination == null) throw new ArgumentNullException(nameof(destination));
if (source == null) throw new ArgumentNullException(nameof(source));
if (destination is List<TItem> list)
{
list.AddRange(source);
return destination;
}

foreach (var item in source)
{
destination.Add(item);
}

foreach (var item in source) destination.Add(item);
return destination;
}

public static ICollection<IBindingParser<IBinding>> All => new List<IBindingParser<IBinding>>
{
Pulsar,
Kafka,
Http,
Websockets,
Sqs,
Sns,
AMQP,
MQTT,
Pulsar, Kafka, Http, Websockets, Sqs, Sns, AMQP, MQTT, AnypointMQ, GooglePubSub,
IBMMQ, JMS, MQTT5, NATS, ROS2, Solace,
};

public static ICollection<IBindingParser<IBinding>> Http => new List<IBindingParser<IBinding>>
{
new HttpOperationBinding(),
new HttpMessageBinding(),
new HttpOperationBinding(), new HttpMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> Websockets => new List<IBindingParser<IBinding>>
Expand All @@ -69,42 +63,72 @@ public static TCollection Add<TCollection, TItem>(

public static ICollection<IBindingParser<IBinding>> Kafka => new List<IBindingParser<IBinding>>
{
new KafkaServerBinding(),
new KafkaChannelBinding(),
new KafkaOperationBinding(),
new KafkaMessageBinding(),
new KafkaServerBinding(), new KafkaChannelBinding(), new KafkaOperationBinding(), new KafkaMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> Pulsar => new List<IBindingParser<IBinding>>
{
new PulsarServerBinding(),
new PulsarChannelBinding(),
new PulsarServerBinding(), new PulsarChannelBinding(),
};

public static ICollection<IBindingParser<IBinding>> Sqs => new List<IBindingParser<IBinding>>
{
new SqsChannelBinding(),
new SqsOperationBinding(),
new SqsChannelBinding(), new SqsOperationBinding(),
};

public static ICollection<IBindingParser<IBinding>> Sns => new List<IBindingParser<IBinding>>
{
new SnsChannelBinding(),
new SnsOperationBinding(),
new SnsChannelBinding(), new SnsOperationBinding(),
};

public static ICollection<IBindingParser<IBinding>> AMQP => new List<IBindingParser<IBinding>>
{
new AMQPChannelBinding(),
new AMQPOperationBinding(),
new AMQPMessageBinding(),
new AMQPChannelBinding(), new AMQPOperationBinding(), new AMQPMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> AnypointMQ => new List<IBindingParser<IBinding>>
{
new AnypointMQChannelBinding(), new AnypointMQMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> GooglePubSub => new List<IBindingParser<IBinding>>
{
new GooglePubSubChannelBinding(), new GooglePubSubMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> IBMMQ => new List<IBindingParser<IBinding>>
{
new IBMMQServerBinding(), new IBMMQChannelBinding(), new IBMMQMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> JMS => new List<IBindingParser<IBinding>>
{
new JMSServerBinding(), new JMSChannelBinding(), new JMSMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> MQTT => new List<IBindingParser<IBinding>>
{
new MQTTServerBinding(),
new MQTTOperationBinding(),
new MQTTMessageBinding(),
new MQTTServerBinding(), new MQTTOperationBinding(), new MQTTMessageBinding(),
};

public static ICollection<IBindingParser<IBinding>> MQTT5 => new List<IBindingParser<IBinding>>
{
new MQTT5ServerBinding(),
};

public static ICollection<IBindingParser<IBinding>> NATS => new List<IBindingParser<IBinding>>
{
new NATSOperationBinding(),
};

public static ICollection<IBindingParser<IBinding>> ROS2 => new List<IBindingParser<IBinding>>
{
new ROS2ServerBinding(), new ROS2OperationBinding(),
};

public static ICollection<IBindingParser<IBinding>> Solace => new List<IBindingParser<IBinding>>
{
new SolaceServerBinding(), new SolaceOperationBinding(),
};
}
}
Loading
Loading