Skip to content

Commit d53557a

Browse files
committed
refactor: Update binding serialization and testing for various protocols
This commit updates the serialization logic across several bindings and corresponding test cases to align with newer API versions and improve data handling. In src/ByteBard.AsyncAPI.Bindings/IBMMQ/IBMMQMessageBinding.cs, the `Expiry` property type is updated from `int?` to `long?`, and the mapping in `FixedFieldMap` is adjusted to use `GetLongValue()`. In src/ByteBard.AsyncAPI.Bindings/IBMMQ/IBMMQServerBinding.cs, the serialization logic for `multiEndpointServer` is updated to use the strongly typed property `bool`. In src/ByteBard.AsyncAPI.Bindings/Queue.cs, the serialization of `isPartitioned` and `exclusive` properties is updated to use the strongly typed `bool` type. In src/ByteBard.AsyncAPI.Bindings/Topic.cs, the serialization of `durablePermitted` and `lastMsgRetained` properties is updated to use the strongly typed `bool` type. In src/ByteBard.AsyncAPI.Bindings/MQTT5/MQTT5ServerBinding.cs, the serialization logic for `SerializeProperties
1 parent 9939813 commit d53557a

9 files changed

Lines changed: 79 additions & 18 deletions

File tree

‎src/ByteBard.AsyncAPI.Bindings/IBMMQ/IBMMQMessageBinding.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class IBMMQMessageBinding : MessageBinding<IBMMQMessageBinding>
99
public string Type { get; set; }
1010
public string Headers { get; set; }
1111
public string Description { get; set; }
12-
public int? Expiry { get; set; }
12+
public long? Expiry { get; set; }
1313

1414
public override string BindingKey => "ibmmq";
1515

@@ -19,7 +19,7 @@ public class IBMMQMessageBinding : MessageBinding<IBMMQMessageBinding>
1919
{ "type", (a, n) => { a.Type = n.GetScalarValue(); } },
2020
{ "headers", (a, n) => { a.Headers = n.GetScalarValue(); } },
2121
{ "description", (a, n) => { a.Description = n.GetScalarValue(); } },
22-
{ "expiry", (a, n) => { a.Expiry = n.GetIntegerValue(); } },
22+
{ "expiry", (a, n) => { a.Expiry = n.GetLongValue(); } },
2323
};
2424

2525
public override void SerializeV2(IAsyncApiWriter writer) => this.SerializeV3(writer);

‎src/ByteBard.AsyncAPI.Bindings/IBMMQ/IBMMQServerBinding.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
3434
writer.WriteOptionalProperty("groupId", this.GroupId);
3535
writer.WriteOptionalProperty("ccdtQueueManagerName", this.CcdtQueueManagerName);
3636
writer.WriteOptionalProperty("cipherSpec", this.CipherSpec);
37-
writer.WriteOptionalProperty("multiEndpointServer", this.MultiEndpointServer);
37+
writer.WriteOptionalProperty<bool>("multiEndpointServer", this.MultiEndpointServer);
3838
writer.WriteOptionalProperty("heartBeatInterval", this.HeartBeatInterval);
3939
writer.WriteOptionalProperty("bindingVersion", this.BindingVersion);
4040
writer.WriteExtensions(this.Extensions);

‎src/ByteBard.AsyncAPI.Bindings/IBMMQ/Queue.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public void Serialize(IAsyncApiWriter writer)
1313
{
1414
writer.WriteStartObject();
1515
writer.WriteOptionalProperty("objectName", this.ObjectName);
16-
writer.WriteOptionalProperty("isPartitioned", this.IsPartitioned);
17-
writer.WriteOptionalProperty("exclusive", this.Exclusive);
16+
writer.WriteOptionalProperty<bool>("isPartitioned", this.IsPartitioned);
17+
writer.WriteOptionalProperty<bool>("exclusive", this.Exclusive);
1818
writer.WriteEndObject();
1919
}
2020
}

‎src/ByteBard.AsyncAPI.Bindings/IBMMQ/Topic.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public void Serialize(IAsyncApiWriter writer)
1515
writer.WriteStartObject();
1616
writer.WriteOptionalProperty("string", this.StringValue);
1717
writer.WriteOptionalProperty("objectName", this.ObjectName);
18-
writer.WriteOptionalProperty("durablePermitted", this.DurablePermitted);
19-
writer.WriteOptionalProperty("lastMsgRetained", this.LastMsgRetained);
18+
writer.WriteOptionalProperty<bool>("durablePermitted", this.DurablePermitted);
19+
writer.WriteOptionalProperty<bool>("lastMsgRetained", this.LastMsgRetained);
2020
writer.WriteEndObject();
2121
}
2222
}

‎src/ByteBard.AsyncAPI.Bindings/MQTT5/MQTT5ServerBinding.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class MQTT5ServerBinding : ServerBinding<MQTT5ServerBinding>
2424
public override void SerializeV2(IAsyncApiWriter writer) => this.SerializeProperties(writer, AsyncApiVersion.AsyncApi2_0);
2525
public override void SerializeV3(IAsyncApiWriter writer) => this.SerializeProperties(writer, AsyncApiVersion.AsyncApi3_0);
2626

27-
public override void SerializeProperties(IAsyncApiWriter writer) => this.SerializeProperties(writer, AsyncApiVersion.AsyncApi2_0);
27+
public override void SerializeProperties(IAsyncApiWriter writer) => this.SerializeProperties(writer, AsyncApiVersion.AsyncApi3_0);
2828

2929
private void SerializeProperties(IAsyncApiWriter writer, AsyncApiVersion version)
3030
{

‎test/ByteBard.AsyncAPI.Tests/Bindings/AnypointMQ/AnypointMQBindings_Should.cs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public void ChannelBinding_RoundTripsNestedPropertiesAndOmittedVersion(AsyncApiV
1818
var yaml = original.SerializeAsYaml(version);
1919
yaml.Should().Contain("destination: orders").And.Contain("destinationType: queue").And.NotContain("bindingVersion");
2020
var settings = new AsyncApiReaderSettings { Bindings = new[] { new AnypointMQChannelBinding() } };
21-
var parsed = new AsyncApiStringReader(settings).ReadFragment<AsyncApiChannel>(yaml, version, out _);
21+
var parsed = new AsyncApiStringReader(settings).ReadFragment<AsyncApiChannel>(yaml, version, out var diagnostics);
22+
diagnostics.Errors.Should().BeEmpty();
2223

2324
parsed.Bindings["anypointmq"].Should().BeEquivalentTo(original.Bindings["anypointmq"]);
2425
}
@@ -37,7 +38,8 @@ public void MessageBinding_RoundTripsHeadersSchema(AsyncApiVersion version)
3738
var yaml = original.SerializeAsYaml(version);
3839
yaml.Should().Contain("headers:").And.Contain("traceId:").And.Contain("bindingVersion: 0.1.0");
3940
var settings = new AsyncApiReaderSettings { Bindings = new[] { new AnypointMQMessageBinding() } };
40-
var parsed = new AsyncApiStringReader(settings).ReadFragment<AsyncApiMessage>(yaml, version, out _);
41+
var parsed = new AsyncApiStringReader(settings).ReadFragment<AsyncApiMessage>(yaml, version, out var diagnostics);
42+
diagnostics.Errors.Should().BeEmpty();
4143

4244
parsed.Bindings["anypointmq"].Should().BeEquivalentTo(original.Bindings["anypointmq"]);
4345
}

‎test/ByteBard.AsyncAPI.Tests/Bindings/GooglePubSub/GooglePubSubBindings_Should.cs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public void GooglePubSubBindings_RoundTripShape(AsyncApiVersion version)
3535
.And.Contain("allowedPersistenceRegions:")
3636
.And.Contain("firstRevisionId: '1'");
3737
var settings = new AsyncApiReaderSettings { Bindings = Parsers };
38-
var parsedChannel = new AsyncApiStringReader(settings).ReadFragment<AsyncApiChannel>(channelYaml, version, out _);
38+
var parsedChannel = new AsyncApiStringReader(settings).ReadFragment<AsyncApiChannel>(channelYaml, version, out var channelDiagnostics);
39+
channelDiagnostics.Errors.Should().BeEmpty();
3940
parsedChannel.Should().BeEquivalentTo(channel);
4041

4142
var message = new AsyncApiMessage();
@@ -47,7 +48,8 @@ public void GooglePubSubBindings_RoundTripShape(AsyncApiVersion version)
4748
});
4849
var messageYaml = message.SerializeAsYaml(version);
4950
messageYaml.Should().Contain("orderingKey: customer-7").And.Contain("projects/p/schemas/orders");
50-
var parsedMessage = new AsyncApiStringReader(settings).ReadFragment<AsyncApiMessage>(messageYaml, version, out _);
51+
var parsedMessage = new AsyncApiStringReader(settings).ReadFragment<AsyncApiMessage>(messageYaml, version, out var messageDiagnostics);
52+
messageDiagnostics.Errors.Should().BeEmpty();
5153
parsedMessage.Should().BeEquivalentTo(message);
5254
}
5355
}

‎test/ByteBard.AsyncAPI.Tests/Bindings/IBMMQ/IBMMQBindings_Should.cs‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,56 @@ public void IBMMQBindings_RoundTripAndOmitUnsetValues(AsyncApiVersion version)
3636
channel.Bindings.Add(new IBMMQChannelBinding
3737
{
3838
DestinationType = "queue", MaxMsgLength = 0,
39-
Queue = new Queue { ObjectName = "ORDERS", IsPartitioned = false, Exclusive = true },
39+
Queue = new Queue { ObjectName = "ORDERS", IsPartitioned = false, Exclusive = false },
4040
});
4141
var channelYaml = channel.SerializeAsYaml(version);
42-
channelYaml.Should().Contain("isPartitioned: false").And.Contain("maxMsgLength: 0").And.NotContain("topic:");
42+
channelYaml.Should().Contain("isPartitioned: false").And.Contain("exclusive: false").And.Contain("maxMsgLength: 0").And.NotContain("topic:");
4343
new AsyncApiStringReader(new AsyncApiReaderSettings { Bindings = Parsers })
4444
.ReadFragment<AsyncApiChannel>(channelYaml, version, out _).Should().BeEquivalentTo(channel);
4545

4646
var topicChannel = new AsyncApiChannel();
4747
topicChannel.Bindings.Add(new IBMMQChannelBinding
4848
{
4949
DestinationType = "topic",
50-
Topic = new Topic { StringValue = "orders/#", ObjectName = "ORDERS.TOPIC", DurablePermitted = false, LastMsgRetained = true },
50+
Topic = new Topic { StringValue = "orders/#", ObjectName = "ORDERS.TOPIC", DurablePermitted = false, LastMsgRetained = false },
5151
});
5252
var topicYaml = topicChannel.SerializeAsYaml(version);
53-
topicYaml.Should().Contain("string: orders/#").And.NotContain("queue:");
53+
topicYaml.Should().Contain("string: orders/#").And.Contain("durablePermitted: false").And.Contain("lastMsgRetained: false").And.NotContain("queue:");
5454
new AsyncApiStringReader(new AsyncApiReaderSettings { Bindings = Parsers })
5555
.ReadFragment<AsyncApiChannel>(topicYaml, version, out _).Should().BeEquivalentTo(topicChannel);
5656

5757
var message = new AsyncApiMessage();
58-
message.Bindings.Add(new IBMMQMessageBinding { Type = "binary", Headers = "STRING", Description = "event headers", Expiry = 0 });
58+
message.Bindings.Add(new IBMMQMessageBinding { Type = "binary", Headers = "STRING", Description = "event headers", Expiry = 2592000000L });
5959
var messageYaml = message.SerializeAsYaml(version);
60-
messageYaml.Should().Contain("headers: STRING").And.Contain("expiry: 0");
60+
messageYaml.Should().Contain("headers: STRING").And.Contain("expiry: 2592000000");
6161
new AsyncApiStringReader(new AsyncApiReaderSettings { Bindings = Parsers })
6262
.ReadFragment<AsyncApiMessage>(messageYaml, version, out _).Should().BeEquivalentTo(message);
6363

64+
var zeroExpiryMessage = new AsyncApiMessage();
65+
zeroExpiryMessage.Bindings.Add(new IBMMQMessageBinding { Expiry = 0 });
66+
var zeroExpiryYaml = zeroExpiryMessage.SerializeAsYaml(version);
67+
zeroExpiryYaml.Should().Contain("expiry: 0");
68+
new AsyncApiStringReader(new AsyncApiReaderSettings { Bindings = Parsers })
69+
.ReadFragment<AsyncApiMessage>(zeroExpiryYaml, version, out _).Should().BeEquivalentTo(zeroExpiryMessage);
70+
6471
var absent = new AsyncApiServer();
6572
absent.Bindings.Add(new IBMMQServerBinding());
6673
var absentYaml = absent.SerializeAsYaml(version);
6774
absentYaml.Should().NotContain("multiEndpointServer").And.NotContain("heartBeatInterval").And.NotContain("bindingVersion");
75+
76+
var absentChannel = new AsyncApiChannel();
77+
absentChannel.Bindings.Add(new IBMMQChannelBinding { Queue = new Queue() });
78+
var absentChannelYaml = absentChannel.SerializeAsYaml(version);
79+
absentChannelYaml.Should().NotContain("isPartitioned").And.NotContain("exclusive");
80+
new AsyncApiStringReader(new AsyncApiReaderSettings { Bindings = Parsers })
81+
.ReadFragment<AsyncApiChannel>(absentChannelYaml, version, out _).Should().BeEquivalentTo(absentChannel);
82+
83+
var absentTopicChannel = new AsyncApiChannel();
84+
absentTopicChannel.Bindings.Add(new IBMMQChannelBinding { Topic = new Topic() });
85+
var absentTopicYaml = absentTopicChannel.SerializeAsYaml(version);
86+
absentTopicYaml.Should().NotContain("durablePermitted").And.NotContain("lastMsgRetained");
87+
new AsyncApiStringReader(new AsyncApiReaderSettings { Bindings = Parsers })
88+
.ReadFragment<AsyncApiChannel>(absentTopicYaml, version, out _).Should().BeEquivalentTo(absentTopicChannel);
6889
}
6990
}
7091
}

‎test/ByteBard.AsyncAPI.Tests/Bindings/ROS2/ROS2Bindings_Should.cs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,41 @@ public void ServerBinding_OmitsUnsetFieldsAndWritesExplicitZero(AsyncApiVersion
7474
diagnostics.Warnings.Should().BeEmpty();
7575
parsed.Bindings["ros2"].Should().BeEquivalentTo(binding);
7676
}
77+
78+
[TestCase(AsyncApiVersion.AsyncApi2_0)]
79+
[TestCase(AsyncApiVersion.AsyncApi3_0)]
80+
public void ServerBinding_RoundTripsUpperBoundaryDomainId(AsyncApiVersion version)
81+
{
82+
var binding = new ROS2ServerBinding { DomainId = 231 };
83+
var server = new AsyncApiServer { Host = "localhost", Protocol = "ros2" };
84+
server.Bindings.Add(binding);
85+
86+
var actual = server.SerializeAsYaml(version);
87+
actual.Should().Contain("domainId: 231");
88+
89+
var settings = new AsyncApiReaderSettings { Bindings = new[] { new ROS2ServerBinding() } };
90+
var parsed = new AsyncApiStringReader(settings).ReadFragment<AsyncApiServer>(actual, version, out var diagnostics);
91+
diagnostics.Errors.Should().BeEmpty();
92+
diagnostics.Warnings.Should().BeEmpty();
93+
parsed.Bindings["ros2"].Should().BeEquivalentTo(binding);
94+
}
95+
96+
[TestCase(AsyncApiVersion.AsyncApi2_0)]
97+
[TestCase(AsyncApiVersion.AsyncApi3_0)]
98+
public void ServerBinding_OmitsUnsetDomainId(AsyncApiVersion version)
99+
{
100+
var binding = new ROS2ServerBinding();
101+
var server = new AsyncApiServer { Host = "localhost", Protocol = "ros2" };
102+
server.Bindings.Add(binding);
103+
104+
var actual = server.SerializeAsYaml(version);
105+
actual.Should().NotContain("domainId:");
106+
107+
var settings = new AsyncApiReaderSettings { Bindings = new[] { new ROS2ServerBinding() } };
108+
var parsed = new AsyncApiStringReader(settings).ReadFragment<AsyncApiServer>(actual, version, out var diagnostics);
109+
diagnostics.Errors.Should().BeEmpty();
110+
diagnostics.Warnings.Should().BeEmpty();
111+
parsed.Bindings["ros2"].Should().BeEquivalentTo(binding);
112+
}
77113
}
78114
}

0 commit comments

Comments
 (0)