@@ -4,6 +4,7 @@ namespace LEGO.AsyncAPI.Tests
4
4
{
5
5
using System . Linq ;
6
6
using FluentAssertions ;
7
+ using LEGO . AsyncAPI . Extensions ;
7
8
using LEGO . AsyncAPI . Models ;
8
9
using LEGO . AsyncAPI . Readers ;
9
10
using NUnit . Framework ;
@@ -313,8 +314,80 @@ public void AsyncApiReference_WithExternalResourcesInterface_DeserializesCorrect
313
314
var payload = message . Payload . As < AsyncApiJsonSchemaPayload > ( ) ;
314
315
payload . Properties . Count . Should ( ) . Be ( 3 ) ;
315
316
}
317
+
318
+ [ Test ]
319
+ public void AvroReference_WithExternalResourcesInterface_DeserializesCorrectly ( )
320
+ {
321
+ var yaml = """
322
+ asyncapi: 2.3.0
323
+ info:
324
+ title: test
325
+ version: 1.0.0
326
+ channels:
327
+ workspace:
328
+ publish:
329
+ message:
330
+ schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
331
+ payload:
332
+ $ref: 'path/to/user-create.avsc/#UserCreate'
333
+ """ ;
334
+ var settings = new AsyncApiReaderSettings
335
+ {
336
+ ReferenceResolution = ReferenceResolutionSetting . ResolveAllReferences ,
337
+ ExternalReferenceReader = new MockExternalAvroReferenceReader ( ) ,
338
+ } ;
339
+ var reader = new AsyncApiStringReader ( settings ) ;
340
+ var doc = reader . Read ( yaml , out var diagnostic ) ;
341
+ var payload = doc . Channels [ "workspace" ] . Publish . Message . First ( ) . Payload ;
342
+ payload . Should ( ) . BeAssignableTo ( typeof ( AsyncApiAvroSchemaPayload ) ) ;
343
+ var avro = payload as AsyncApiAvroSchemaPayload ;
344
+ avro . TryGetAs < AvroRecord > ( out var record ) ;
345
+ record . Name . Should ( ) . Be ( "SomeEvent" ) ;
346
+ }
316
347
}
317
348
349
+ public class MockExternalAvroReferenceReader : IAsyncApiExternalReferenceReader
350
+ {
351
+ public string Load ( string reference )
352
+ {
353
+ return
354
+ """
355
+ {
356
+ "type": "record",
357
+ "name": "SomeEvent",
358
+ "namespace": "my.namspace.for.event",
359
+ "fields": [
360
+ {
361
+ "name": "countryCode",
362
+ "type": "string",
363
+ "doc": "Country of the partner, (e.g. DE)"
364
+ },
365
+ {
366
+ "name": "occurredOn",
367
+ "type": "string",
368
+ "doc": "Timestamp of when action occurred."
369
+ },
370
+ {
371
+ "name": "partnerId",
372
+ "type": "string",
373
+ "doc": "Id of the partner"
374
+ },
375
+ {
376
+ "name": "platformSource",
377
+ "type": "string",
378
+ "doc": "Platform source"
379
+ }
380
+ ],
381
+ "example": {
382
+ "occurredOn": "2023-11-03T09:56.582+00:00",
383
+ "partnerId": "1",
384
+ "platformSource": "Brecht",
385
+ "countryCode": "DE"
386
+ }
387
+ }
388
+ """ ;
389
+ }
390
+ }
318
391
public class MockExternalReferenceReader : IAsyncApiExternalReferenceReader
319
392
{
320
393
public string Load ( string reference )
0 commit comments