Skip to content

Commit 0679627

Browse files
committed
Merge remote-tracking branch 'origin/main' into vnext
2 parents a0c6d7f + f923c65 commit 0679627

File tree

5 files changed

+57
-85
lines changed

5 files changed

+57
-85
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [4.1.0](https://github.com/LEGO/AsyncAPI.NET/compare/v4.0.2...v4.1.0) (2023-09-27)
2+
3+
4+
### Features
5+
6+
* **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))
7+
18
## [4.0.2](https://github.com/LEGO/AsyncAPI.NET/compare/v4.0.1...v4.0.2) (2023-08-01)
29

310

src/LEGO.AsyncAPI.Bindings/Sns/Consumer.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace LEGO.AsyncAPI.Bindings.Sns
33
using System;
44
using System.Collections.Generic;
55
using LEGO.AsyncAPI.Attributes;
6+
using LEGO.AsyncAPI.Models;
67
using LEGO.AsyncAPI.Models.Interfaces;
78
using LEGO.AsyncAPI.Writers;
89

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

2122
/// <summary>
2223
/// Only receive a subset of messages from the channel, determined by this policy.
24+
/// 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.
2325
/// </summary>
24-
public FilterPolicy FilterPolicy { get; set; }
26+
public AsyncApiAny FilterPolicy { get; set; }
27+
28+
/// <summary>
29+
/// Determines whether the FilterPolicy applies to MessageAttributes or MessageBody.
30+
/// </summary>
31+
public FilterPolicyScope FilterPolicyScope { get; set; }
2532

2633
/// <summary>
2734
/// 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)
5562
writer.WriteStartObject();
5663
writer.WriteRequiredProperty("protocol", this.Protocol.GetDisplayName());
5764
writer.WriteRequiredObject("endpoint", this.Endpoint, (w, e) => e.Serialize(w));
58-
writer.WriteOptionalObject("filterPolicy", this.FilterPolicy, (w, f) => f.Serialize(w));
65+
writer.WriteOptionalObject("filterPolicy", this.FilterPolicy, (w, f) => f.Write(w));
66+
writer.WriteOptionalProperty("filterPolicyScope", this.FilterPolicyScope.GetDisplayName());
5967
writer.WriteRequiredProperty("rawMessageDelivery", this.RawMessageDelivery);
6068
writer.WriteOptionalObject("redrivePolicy", this.RedrivePolicy, (w, p) => p.Serialize(w));
6169
writer.WriteOptionalObject("deliveryPolicy", this.DeliveryPolicy, (w, p) => p.Serialize(w));
@@ -77,4 +85,10 @@ public enum Protocol
7785
[Display("lambda")] Lambda,
7886
[Display("firehose")] Firehose,
7987
}
88+
89+
public enum FilterPolicyScope
90+
{
91+
[Display("MessageAttributes")] MessageAttributes,
92+
[Display("MessageBody")] MessageBody,
93+
}
8094
}

src/LEGO.AsyncAPI.Bindings/Sns/FilterPolicy.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/LEGO.AsyncAPI.Bindings/Sns/SnsOperationBinding.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,14 @@ public class SnsOperationBinding : OperationBinding<SnsOperationBinding>
4747
{
4848
{ "protocol", (a, n) => { a.Protocol = n.GetScalarValue().GetEnumFromDisplayName<Protocol>(); } },
4949
{ "endpoint", (a, n) => { a.Endpoint = n.ParseMapWithExtensions(this.identifierFixFields); } },
50-
{ "filterPolicy", (a, n) => { a.FilterPolicy = n.ParseMapWithExtensions(this.filterPolicyFixedFields); } },
50+
{ "filterPolicy", (a, n) => { a.FilterPolicy = n.CreateAny(); } },
51+
{ "filterPolicyScope", (a, n) => { a.FilterPolicyScope = n.GetScalarValue().GetEnumFromDisplayName<FilterPolicyScope>(); } },
5152
{ "rawMessageDelivery", (a, n) => { a.RawMessageDelivery = n.GetBooleanValue(); } },
5253
{ "redrivePolicy", (a, n) => { a.RedrivePolicy = n.ParseMapWithExtensions(this.redrivePolicyFixedFields); } },
5354
{ "deliveryPolicy", (a, n) => { a.DeliveryPolicy = n.ParseMapWithExtensions(this.deliveryPolicyFixedFields); } },
5455
{ "displayName", (a, n) => { a.DisplayName = n.GetScalarValue(); } },
5556
};
5657

57-
private FixedFieldMap<FilterPolicy> filterPolicyFixedFields => new()
58-
{
59-
{ "attributes", (a, n) => { a.Attributes = n.CreateAny(); } },
60-
};
61-
6258
private FixedFieldMap<RedrivePolicy> redrivePolicyFixedFields => new()
6359
{
6460
{ "deadLetterQueue", (a, n) => { a.DeadLetterQueue = n.ParseMapWithExtensions(identifierFixFields); } },

test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,18 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes()
164164
x-identifierExtension:
165165
identifierXPropertyName: identifierXPropertyValue
166166
filterPolicy:
167-
attributes:
168-
store:
169-
- asyncapi_corp
170-
contact: dec.kolakowski
171-
event:
172-
- anything-but: order_cancelled
173-
order_key:
174-
transient: by_area
175-
customer_interests:
176-
- rugby
177-
- football
178-
- baseball
179-
x-filterPolicyExtension:
180-
filterPolicyXPropertyName: filterPolicyXPropertyValue
167+
store:
168+
- asyncapi_corp
169+
contact: dec.kolakowski
170+
event:
171+
- anything-but: order_cancelled
172+
order_key:
173+
transient: by_area
174+
customer_interests:
175+
- rugby
176+
- football
177+
- baseball
178+
filterPolicyScope: MessageAttributes
181179
rawMessageDelivery: false
182180
redrivePolicy:
183181
deadLetterQueue:
@@ -250,47 +248,35 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes()
250248
},
251249
},
252250
},
253-
FilterPolicy = new FilterPolicy()
254-
{
255-
Attributes = new AsyncApiObject()
251+
FilterPolicy = new AsyncApiObject()
252+
{
253+
{ "store", new AsyncApiArray() { new AsyncApiAny("asyncapi_corp") } },
254+
{ "contact", new AsyncApiAny("dec.kolakowski") },
256255
{
257-
{ "store", new AsyncApiArray() { new AsyncApiAny("asyncapi_corp") } },
258-
{ "contact", new AsyncApiAny("dec.kolakowski") },
259-
{
260-
"event", new AsyncApiArray()
261-
{
262-
new AsyncApiObject()
263-
{
264-
{ "anything-but", new AsyncApiAny("order_cancelled") },
265-
},
266-
}
267-
},
256+
"event", new AsyncApiArray()
268257
{
269-
"order_key", new AsyncApiObject()
258+
new AsyncApiObject()
270259
{
271-
{ "transient", new AsyncApiAny("by_area") },
272-
}
273-
},
260+
{ "anything-but", new AsyncApiAny("order_cancelled") },
261+
},
262+
}
263+
},
264+
{
265+
"order_key", new AsyncApiObject()
274266
{
275-
"customer_interests", new AsyncApiArray()
276-
{
277-
new AsyncApiAny("rugby"),
278-
new AsyncApiAny("football"),
279-
new AsyncApiAny("baseball"),
280-
}
281-
},
267+
{ "transient", new AsyncApiAny("by_area") },
268+
}
282269
},
283-
Extensions = new Dictionary<string, IAsyncApiExtension>()
284270
{
271+
"customer_interests", new AsyncApiArray()
285272
{
286-
"x-filterPolicyExtension",
287-
new AsyncApiObject()
288-
{
289-
{ "filterPolicyXPropertyName", new AsyncApiAny("filterPolicyXPropertyValue") },
290-
}
291-
},
273+
new AsyncApiAny("rugby"),
274+
new AsyncApiAny("football"),
275+
new AsyncApiAny("baseball"),
276+
}
292277
},
293278
},
279+
FilterPolicyScope = FilterPolicyScope.MessageAttributes,
294280
RawMessageDelivery = false,
295281
RedrivePolicy = new RedrivePolicy()
296282
{

0 commit comments

Comments
 (0)