|
8 | 8 | using ByteBard.AsyncAPI.Models; |
9 | 9 | using ByteBard.AsyncAPI.Models.Interfaces; |
10 | 10 | using ByteBard.AsyncAPI.Readers; |
| 11 | + using ByteBard.AsyncAPI.Validations; |
11 | 12 | using NUnit.Framework; |
12 | 13 |
|
13 | 14 | public class AsyncApiChannel_Should : TestBase |
@@ -251,6 +252,68 @@ public void V3_AsyncApiChannel_WithServers_Reserializes() |
251 | 252 | reserialized.Should().BePlatformAgnosticEquivalentTo(yaml); |
252 | 253 | } |
253 | 254 |
|
| 255 | + [TestCase("a~1b", "#/servers/a~01b")] |
| 256 | + [TestCase("a/b", "#/servers/a~1b")] |
| 257 | + public void V2_AsyncApiChannel_WithServerNameNeedingEscape_Reserializes(string serverName, string expectedReference) |
| 258 | + { |
| 259 | + var yaml = |
| 260 | + $""" |
| 261 | + asyncapi: 2.6.0 |
| 262 | + info: |
| 263 | + title: test spec |
| 264 | + version: 1.0.0 |
| 265 | + servers: |
| 266 | + {serverName}: |
| 267 | + url: example.com |
| 268 | + protocol: kafka |
| 269 | + channels: |
| 270 | + mychannel: |
| 271 | + servers: |
| 272 | + - {serverName} |
| 273 | + """; |
| 274 | + |
| 275 | + var document = new AsyncApiStringReader(new AsyncApiReaderSettings { RuleSet = ValidationRuleSet.GetEmptyRuleSet() }).Read(yaml, out var diag); |
| 276 | + |
| 277 | + diag.Errors.Should().BeEmpty(); |
| 278 | + var server = document.Channels.First().Value.Servers.Single(); |
| 279 | + server.Reference.Reference.Should().Be(expectedReference); |
| 280 | + server.Host.Should().Be("example.com"); |
| 281 | + |
| 282 | + var reserialized = document.SerializeAsYaml(AsyncApiVersion.AsyncApi2_0); |
| 283 | + |
| 284 | + reserialized.Should().BePlatformAgnosticEquivalentTo(yaml); |
| 285 | + } |
| 286 | + |
| 287 | + [Test] |
| 288 | + public void V3_AsyncApiChannel_WithEscapedServerReference_ResolvesServer() |
| 289 | + { |
| 290 | + var yaml = |
| 291 | + """ |
| 292 | + asyncapi: 3.1.0 |
| 293 | + info: |
| 294 | + title: test spec |
| 295 | + version: 1.0.0 |
| 296 | + servers: |
| 297 | + a/b: |
| 298 | + host: example.com |
| 299 | + protocol: kafka |
| 300 | + channels: |
| 301 | + mychannel: |
| 302 | + servers: |
| 303 | + - $ref: '#/servers/a~1b' |
| 304 | + components: { } |
| 305 | + """; |
| 306 | + |
| 307 | + var document = new AsyncApiStringReader(new AsyncApiReaderSettings { RuleSet = ValidationRuleSet.GetEmptyRuleSet() }).Read(yaml, out var diag); |
| 308 | + |
| 309 | + diag.Errors.Should().BeEmpty(); |
| 310 | + document.Channels.First().Value.Servers.Single().Host.Should().Be("example.com"); |
| 311 | + |
| 312 | + var reserialized = document.SerializeAsYaml(AsyncApiVersion.AsyncApi3_0); |
| 313 | + |
| 314 | + reserialized.Should().BePlatformAgnosticEquivalentTo(yaml); |
| 315 | + } |
| 316 | + |
254 | 317 | [Test] |
255 | 318 | public void V3_AsyncApiChannel_WithServerReference_SerializesReference() |
256 | 319 | { |
|
0 commit comments