Skip to content

Commit

Permalink
cyclic reference fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed Dec 14, 2023
1 parent 273eb92 commit 67bc6c2
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/LEGO.AsyncAPI.Bindings/Sns/Ordering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class Ordering : IAsyncApiExtensible
/// What type of SNS Topic is this?
/// </summary>
public OrderingType Type { get; set; }

/// <summary>
/// True to turn on de-duplication of messages for a channel.
/// </summary>
public bool ContentBasedDeduplication { get; set; }

public IDictionary<string, IAsyncApiExtension> Extensions { get; set; } = new Dictionary<string, IAsyncApiExtension>();

public void Serialize(IAsyncApiWriter writer)
{
if (writer is null)
Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Sns/SnsChannelBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class SnsChannelBinding : ChannelBinding<SnsChannelBinding>
protected override FixedFieldMap<SnsChannelBinding> FixedFieldMap => new()
{
{ "name", (a, n) => { a.Name = n.GetScalarValue(); } },
{ "type", (a, n) => { a.Ordering = n.ParseMapWithExtensions(this.orderingFixedFields); } },
{ "ordering", (a, n) => { a.Ordering = n.ParseMapWithExtensions(this.orderingFixedFields); } },
{ "policy", (a, n) => { a.Policy = n.ParseMapWithExtensions(this.policyFixedFields); } },
{ "tags", (a, n) => { a.Tags = n.CreateSimpleMap(s => s.GetScalarValue()); } },
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/StringOrStringList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class StringOrStringList : IAsyncApiElement
{
public StringOrStringList(AsyncApiAny value)
{
this.Value = value.Node switch
this.Value = value.GetNode() switch
{
JsonArray array => IsValidStringList(array) ? new AsyncApiAny(array) : throw new ArgumentException($"{nameof(StringOrStringList)} value should only contain string items."),
JsonValue jValue => IsString(jValue) ? new AsyncApiAny(jValue) : throw new ArgumentException($"{nameof(StringOrStringList)} should be a string value or a string list."),
Expand Down
4 changes: 2 additions & 2 deletions src/LEGO.AsyncAPI/Models/Any/AsyncAPIArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AsyncApiArray : Collection<AsyncApiAny>, IAsyncApiExtension, IAsync
public static explicit operator AsyncApiArray(AsyncApiAny any)
{
var a = new AsyncApiArray();
if (any.Node is JsonArray arr)
if (any.GetNode() is JsonArray arr)
{
foreach (var item in arr)
{
Expand All @@ -29,7 +29,7 @@ public static implicit operator AsyncApiAny(AsyncApiArray arr)
var jArray = new JsonArray();
foreach (var item in arr)
{
jArray.Add(item.Node);
jArray.Add(item.GetNode());
}

return new AsyncApiAny(jArray);
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI/Models/Any/AsyncAPIObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static implicit operator AsyncApiAny(AsyncApiObject obj)
var jObject = new JsonObject();
foreach (var item in obj)
{
jObject.Add(item.Key, item.Value.Node);
jObject.Add(item.Key, item.Value.GetNode());
}

return new AsyncApiAny(jObject);
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AsyncApiAny(JsonNode node)
/// <value>
/// The node.
/// </value>
public JsonNode Node => this.node;
public JsonNode GetNode() => this.node;

public T GetValue<T>()
{
Expand Down
4 changes: 2 additions & 2 deletions src/LEGO.AsyncAPI/Writers/AsyncApiWriterAnyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public static void WriteAny(this IAsyncApiWriter writer, AsyncApiAny any)
throw new ArgumentNullException(nameof(writer));
}

if (any.Node == null)
if (any.GetNode() == null)
{
writer.WriteNull();
return;
}

var node = any.Node;
var node = any.GetNode();

var element = JsonDocument.Parse(node.ToJsonString()).RootElement;
switch (element.ValueKind)
Expand Down
2 changes: 1 addition & 1 deletion test/LEGO.AsyncAPI.Tests/AsyncApiReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Read_WithExtensionParser_Parses()
";
Func<AsyncApiAny, IAsyncApiExtension> valueExtensionParser = (any) =>
{
if (any.Node is JsonValue value)
if (any.GetNode() is JsonValue value)
{
if (value.GetScalarValue() == "onetwothreefour")
{
Expand Down
11 changes: 5 additions & 6 deletions test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ public void SnsChannelBinding_WithFilledObject_SerializesAndDeserializes()

// Assert
Assert.AreEqual(actual, expected);

var expectedSnsBinding = (SnsChannelBinding)channel.Bindings.Values.First();
expectedSnsBinding.Should().BeEquivalentTo((SnsChannelBinding)binding.Bindings.Values.First());
expectedSnsBinding.Should().BeEquivalentTo((SnsChannelBinding)binding.Bindings.Values.First(), options => options.IgnoringCyclicReferences());
}

[Test]
public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes()
{
Expand Down Expand Up @@ -382,12 +382,11 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes()
settings.Bindings = BindingsCollection.Sns;
var binding = new AsyncApiStringReader(settings).ReadFragment<AsyncApiOperation>(actual, AsyncApiVersion.AsyncApi2_0, out _);


// Assert
Assert.AreEqual(actual, expected);

var expectedSnsBinding = (SnsOperationBinding)operation.Bindings.Values.First();
expectedSnsBinding.Should().BeEquivalentTo((SnsOperationBinding)binding.Bindings.Values.First());
expectedSnsBinding.Should().BeEquivalentTo((SnsOperationBinding)binding.Bindings.Values.First(), options => options.IgnoringCyclicReferences());
}
}
}
6 changes: 1 addition & 5 deletions test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,7 @@ public void AsyncApiMessage_WithFilledObject_Serializes()

// Assert
Assert.AreEqual(expected, actual);
message.Should().BeEquivalentTo(deserializedMessage, options => options.IgnoringCyclicReferences()
.Excluding(message => message.Headers.Examples[0].Node.Parent)
.Excluding(message => message.Traits[0].Headers.Examples[0].Node.Parent)
.Excluding(message => message.Traits[0].Examples[0].Payload.Node.Parent)
.Excluding(message => message.Examples[0].Payload.Node.Parent));
message.Should().BeEquivalentTo(deserializedMessage);
}
}
}
5 changes: 1 addition & 4 deletions test/LEGO.AsyncAPI.Tests/Models/AsyncApiSchema_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,7 @@ public void Deserialize_WithAdvancedSchema_Works()
var actual = new AsyncApiStringReader().ReadFragment<AsyncApiSchema>(json, AsyncApiVersion.AsyncApi2_0, out var _diagnostics);

// Assert
actual.Should().BeEquivalentTo(expected, options => options.IgnoringCyclicReferences()
.Excluding(actual => actual.Properties["property11"].Const.Node.Parent)
.Excluding(actual => actual.Properties["property11"].Const.Node.Root));
_diagnostics.Errors.Should().BeEmpty();
actual.Should().BeEquivalentTo(expected);
}

[Test]
Expand Down

0 comments on commit 67bc6c2

Please sign in to comment.