diff --git a/CHANGELOG.md b/CHANGELOG.md index efb62f45..4e5bda60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [4.1.0](https://github.com/LEGO/AsyncAPI.NET/compare/v4.0.2...v4.1.0) (2023-09-27) + + +### Features + +* **bindings:** update FilterPolicy to match AWS API ([#128](https://github.com/LEGO/AsyncAPI.NET/issues/128)) ([5b64654](https://github.com/LEGO/AsyncAPI.NET/commit/5b6465474ae09d42a27377bf04d58fdbd1dd8a59)) + ## [4.0.2](https://github.com/LEGO/AsyncAPI.NET/compare/v4.0.1...v4.0.2) (2023-08-01) diff --git a/src/LEGO.AsyncAPI.Bindings/Sns/Consumer.cs b/src/LEGO.AsyncAPI.Bindings/Sns/Consumer.cs index 46548977..262521d0 100644 --- a/src/LEGO.AsyncAPI.Bindings/Sns/Consumer.cs +++ b/src/LEGO.AsyncAPI.Bindings/Sns/Consumer.cs @@ -3,6 +3,7 @@ namespace LEGO.AsyncAPI.Bindings.Sns using System; using System.Collections.Generic; using LEGO.AsyncAPI.Attributes; + using LEGO.AsyncAPI.Models; using LEGO.AsyncAPI.Models.Interfaces; using LEGO.AsyncAPI.Writers; @@ -20,8 +21,14 @@ public class Consumer : IAsyncApiExtensible /// /// Only receive a subset of messages from the channel, determined by this policy. + /// Depending on the FilterPolicyScope, a map of either a message attribute or message body to an array of possible matches. The match may be a simple string for an exact match, but it may also be an object that represents a constraint and values for that constraint. /// - public FilterPolicy FilterPolicy { get; set; } + public AsyncApiAny FilterPolicy { get; set; } + + /// + /// Determines whether the FilterPolicy applies to MessageAttributes or MessageBody. + /// + public FilterPolicyScope FilterPolicyScope { get; set; } /// /// If true AWS SNS attributes are removed from the body, and for SQS, SNS message attributes are copied to SQS message attributes. If false the SNS attributes are included in the body. @@ -55,7 +62,8 @@ public void Serialize(IAsyncApiWriter writer) writer.WriteStartObject(); writer.WriteRequiredProperty("protocol", this.Protocol.GetDisplayName()); writer.WriteRequiredObject("endpoint", this.Endpoint, (w, e) => e.Serialize(w)); - writer.WriteOptionalObject("filterPolicy", this.FilterPolicy, (w, f) => f.Serialize(w)); + writer.WriteOptionalObject("filterPolicy", this.FilterPolicy, (w, f) => f.Write(w)); + writer.WriteOptionalProperty("filterPolicyScope", this.FilterPolicyScope.GetDisplayName()); writer.WriteRequiredProperty("rawMessageDelivery", this.RawMessageDelivery); writer.WriteOptionalObject("redrivePolicy", this.RedrivePolicy, (w, p) => p.Serialize(w)); writer.WriteOptionalObject("deliveryPolicy", this.DeliveryPolicy, (w, p) => p.Serialize(w)); @@ -77,4 +85,10 @@ public enum Protocol [Display("lambda")] Lambda, [Display("firehose")] Firehose, } + + public enum FilterPolicyScope + { + [Display("MessageAttributes")] MessageAttributes, + [Display("MessageBody")] MessageBody, + } } \ No newline at end of file diff --git a/src/LEGO.AsyncAPI.Bindings/Sns/FilterPolicy.cs b/src/LEGO.AsyncAPI.Bindings/Sns/FilterPolicy.cs deleted file mode 100644 index f24ae280..00000000 --- a/src/LEGO.AsyncAPI.Bindings/Sns/FilterPolicy.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace LEGO.AsyncAPI.Bindings.Sns -{ - using System; - using System.Collections.Generic; - using LEGO.AsyncAPI.Models; - using LEGO.AsyncAPI.Models.Interfaces; - using LEGO.AsyncAPI.Writers; - - public class FilterPolicy : IAsyncApiExtensible - { - /// - /// A map of a message attribute to an array of possible matches. The match may be a simple string for an exact match, but it may also be an object that represents a constraint and values for that constraint. - /// - public AsyncApiAny Attributes { get; set; } - - public IDictionary Extensions { get; set; } = new Dictionary(); - - public void Serialize(IAsyncApiWriter writer) - { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - writer.WriteStartObject(); - writer.WriteRequiredObject("attributes", this.Attributes, (w, a) => w.WriteAny(a)); - writer.WriteExtensions(this.Extensions); - writer.WriteEndObject(); - } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI.Bindings/Sns/SnsOperationBinding.cs b/src/LEGO.AsyncAPI.Bindings/Sns/SnsOperationBinding.cs index e474e4a6..ffab9afb 100644 --- a/src/LEGO.AsyncAPI.Bindings/Sns/SnsOperationBinding.cs +++ b/src/LEGO.AsyncAPI.Bindings/Sns/SnsOperationBinding.cs @@ -47,18 +47,14 @@ public class SnsOperationBinding : OperationBinding { { "protocol", (a, n) => { a.Protocol = n.GetScalarValue().GetEnumFromDisplayName(); } }, { "endpoint", (a, n) => { a.Endpoint = n.ParseMapWithExtensions(this.identifierFixFields); } }, - { "filterPolicy", (a, n) => { a.FilterPolicy = n.ParseMapWithExtensions(this.filterPolicyFixedFields); } }, + { "filterPolicy", (a, n) => { a.FilterPolicy = n.CreateAny(); } }, + { "filterPolicyScope", (a, n) => { a.FilterPolicyScope = n.GetScalarValue().GetEnumFromDisplayName(); } }, { "rawMessageDelivery", (a, n) => { a.RawMessageDelivery = n.GetBooleanValue(); } }, { "redrivePolicy", (a, n) => { a.RedrivePolicy = n.ParseMapWithExtensions(this.redrivePolicyFixedFields); } }, { "deliveryPolicy", (a, n) => { a.DeliveryPolicy = n.ParseMapWithExtensions(this.deliveryPolicyFixedFields); } }, { "displayName", (a, n) => { a.DisplayName = n.GetScalarValue(); } }, }; - private FixedFieldMap filterPolicyFixedFields => new() - { - { "attributes", (a, n) => { a.Attributes = n.CreateAny(); } }, - }; - private FixedFieldMap redrivePolicyFixedFields => new() { { "deadLetterQueue", (a, n) => { a.DeadLetterQueue = n.ParseMapWithExtensions(identifierFixFields); } }, diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs index 0ae28e88..607510d9 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs @@ -164,20 +164,18 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes() x-identifierExtension: identifierXPropertyName: identifierXPropertyValue filterPolicy: - attributes: - store: - - asyncapi_corp - contact: dec.kolakowski - event: - - anything-but: order_cancelled - order_key: - transient: by_area - customer_interests: - - rugby - - football - - baseball - x-filterPolicyExtension: - filterPolicyXPropertyName: filterPolicyXPropertyValue + store: + - asyncapi_corp + contact: dec.kolakowski + event: + - anything-but: order_cancelled + order_key: + transient: by_area + customer_interests: + - rugby + - football + - baseball + filterPolicyScope: MessageAttributes rawMessageDelivery: false redrivePolicy: deadLetterQueue: @@ -250,47 +248,35 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes() }, }, }, - FilterPolicy = new FilterPolicy() - { - Attributes = new AsyncApiObject() + FilterPolicy = new AsyncApiObject() + { + { "store", new AsyncApiArray() { new AsyncApiAny("asyncapi_corp") } }, + { "contact", new AsyncApiAny("dec.kolakowski") }, { - { "store", new AsyncApiArray() { new AsyncApiAny("asyncapi_corp") } }, - { "contact", new AsyncApiAny("dec.kolakowski") }, - { - "event", new AsyncApiArray() - { - new AsyncApiObject() - { - { "anything-but", new AsyncApiAny("order_cancelled") }, - }, - } - }, + "event", new AsyncApiArray() { - "order_key", new AsyncApiObject() + new AsyncApiObject() { - { "transient", new AsyncApiAny("by_area") }, - } - }, + { "anything-but", new AsyncApiAny("order_cancelled") }, + }, + } + }, + { + "order_key", new AsyncApiObject() { - "customer_interests", new AsyncApiArray() - { - new AsyncApiAny("rugby"), - new AsyncApiAny("football"), - new AsyncApiAny("baseball"), - } - }, + { "transient", new AsyncApiAny("by_area") }, + } }, - Extensions = new Dictionary() { + "customer_interests", new AsyncApiArray() { - "x-filterPolicyExtension", - new AsyncApiObject() - { - { "filterPolicyXPropertyName", new AsyncApiAny("filterPolicyXPropertyValue") }, - } - }, + new AsyncApiAny("rugby"), + new AsyncApiAny("football"), + new AsyncApiAny("baseball"), + } }, }, + FilterPolicyScope = FilterPolicyScope.MessageAttributes, RawMessageDelivery = false, RedrivePolicy = new RedrivePolicy() {