Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into vnext
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed Oct 10, 2023
2 parents a0c6d7f + f923c65 commit 0679627
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 85 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
18 changes: 16 additions & 2 deletions src/LEGO.AsyncAPI.Bindings/Sns/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,8 +21,14 @@ public class Consumer : IAsyncApiExtensible

/// <summary>
/// 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.
/// </summary>
public FilterPolicy FilterPolicy { get; set; }
public AsyncApiAny FilterPolicy { get; set; }

/// <summary>
/// Determines whether the FilterPolicy applies to MessageAttributes or MessageBody.
/// </summary>
public FilterPolicyScope FilterPolicyScope { get; set; }

/// <summary>
/// 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.
Expand Down Expand Up @@ -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));
Expand All @@ -77,4 +85,10 @@ public enum Protocol
[Display("lambda")] Lambda,
[Display("firehose")] Firehose,
}

public enum FilterPolicyScope
{
[Display("MessageAttributes")] MessageAttributes,
[Display("MessageBody")] MessageBody,
}
}
31 changes: 0 additions & 31 deletions src/LEGO.AsyncAPI.Bindings/Sns/FilterPolicy.cs

This file was deleted.

8 changes: 2 additions & 6 deletions src/LEGO.AsyncAPI.Bindings/Sns/SnsOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@ public class SnsOperationBinding : OperationBinding<SnsOperationBinding>
{
{ "protocol", (a, n) => { a.Protocol = n.GetScalarValue().GetEnumFromDisplayName<Protocol>(); } },
{ "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<FilterPolicyScope>(); } },
{ "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<FilterPolicy> filterPolicyFixedFields => new()
{
{ "attributes", (a, n) => { a.Attributes = n.CreateAny(); } },
};

private FixedFieldMap<RedrivePolicy> redrivePolicyFixedFields => new()
{
{ "deadLetterQueue", (a, n) => { a.DeadLetterQueue = n.ParseMapWithExtensions(identifierFixFields); } },
Expand Down
78 changes: 32 additions & 46 deletions test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<string, IAsyncApiExtension>()
{
"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()
{
Expand Down

0 comments on commit 0679627

Please sign in to comment.