@@ -72,26 +72,50 @@ public void Reference()
7272 }
7373
7474 [ Test ]
75- public void ResolveExternalReference ( )
75+ public void ExternalFragmentReference_ResolvesFragtment ( )
7676 {
77+ var externalJson =
78+ """
79+ {
80+ "servers": [
81+ {
82+ "url": "wss://production.gigantic-server.com:443",
83+ "protocol": "wss",
84+ "protocolVersion": "1.0.0",
85+ "description": "The production API server",
86+ "variables": {
87+ "username": {
88+ "default": "demo",
89+ "description": "This value is assigned by the service provider"
90+ },
91+ "password": {
92+ "default": "demo",
93+ "description": "This value is assigned by the service provider"
94+ }
95+ }
96+ }
97+ ]
98+ }
99+ """ ;
100+
77101 var json =
78102 """
79- {
80- "asyncapi": "2.6.0",
81- "info": { },
82- "servers": {
83- "production": {
84- "$ref": "https://gist.githubusercontent.com/VisualBean/7dc9607d735122483e1bb7005ff3ad0e/raw/458729e4d56636ef3bb34762f4a5731ea5043bdf/servers .json#/servers/0"
85- }
86- }
87- }
88- """ ;
89-
90- var doc = new AsyncApiStringReader ( new AsyncApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting . ResolveAllReferences } ) . Read ( json , out var diag ) ;
103+ {
104+ "asyncapi": "2.6.0",
105+ "info": { },
106+ "servers": {
107+ "production": {
108+ "$ref": "whatever/whatever .json#/servers/0"
109+ }
110+ }
111+ }
112+ """ ;
113+
114+ var doc = new AsyncApiStringReader ( new AsyncApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting . ResolveAllReferences , ExternalReferenceLoader = new MockStringLoader ( externalJson ) } ) . Read ( json , out var diag ) ;
91115 var reference = doc . Servers . First ( ) . Value as AsyncApiServerReference ;
92- // reference.Reference.Id .Should().Be("whatever ");
93- // reference.Reference.HostDocument .Should().Be(doc );
94- // reference.Reference.IsFragment. Should().BeTrue( );
116+ reference . Reference . FragmentId . Should ( ) . Be ( "/servers/0 " ) ;
117+ reference . Reference . IsFragment . Should ( ) . BeTrue ( ) ;
118+ reference . Url . Should ( ) . Be ( "wss://production.gigantic-server.com:443" ) ;
95119 }
96120
97121
@@ -416,70 +440,80 @@ public void AsyncApiReference_WithExternalResourcesInterface_DeserializesCorrect
416440 [ Test ]
417441 public void AsyncApiReference_WithExternalAvroResource_DeserializesCorrectly ( )
418442 {
443+ var avroPayload =
444+ """
445+ {
446+ "type": "record",
447+ "name": "thecodebuzz_schema",
448+ "namespace": "thecodebuzz.avro",
449+ "fields": [
450+ {
451+ "name": "username",
452+ "type": "string",
453+ "doc": "Name of the user account on Thecodebuzz.com"
454+ },
455+ {
456+ "name": "email",
457+ "type": "string",
458+ "doc": "The email of the user logging message on the blog"
459+ },
460+ {
461+ "name": "timestamp",
462+ "type": "long",
463+ "doc": "time in seconds"
464+ }
465+ ],
466+ "doc:": "A basic schema for storing thecodebuzz blogs messages"
467+ }
468+ """ ;
469+
419470 var yaml = """
420- asyncapi: 2.3 .0
471+ asyncapi: 2.6 .0
421472 info:
422473 title: test
423474 version: 1.0.0
424475 channels:
425476 workspace:
426477 publish:
427478 message:
479+ payload:
480+ $ref: ./some/path/to/external/payload.json
481+ schemaFormat: application/vnd.apache.avro
428482 name: Test
429483 title: Test message
430484 summary: Test.
431- schemaFormat: application/vnd.apache.avro
432- contentType: application/cloudevents+json
433- payload:
434- $ref: "./some/path/to/external/payload.json"
435485 """ ;
436486 var settings = new AsyncApiReaderSettings
437487 {
438488 ReferenceResolution = ReferenceResolutionSetting . ResolveAllReferences ,
439- ExternalReferenceLoader = new MockAvroSchemaLoader ( ) ,
489+ ExternalReferenceLoader = new MockStringLoader ( avroPayload ) ,
440490 } ;
441491 var reader = new AsyncApiStringReader ( settings ) ;
442492 var doc = reader . Read ( yaml , out var diagnostic ) ;
443493 var message = doc . Channels [ "workspace" ] . Publish . Message . First ( ) ;
444494 var payload = message . Payload . As < AsyncApiAvroSchema > ( ) ;
445495 payload . As < AvroRecord > ( ) . Name . Should ( ) . Be ( "thecodebuzz_schema" ) ;
496+
497+ doc . SerializeAsYaml ( AsyncApiVersion . AsyncApi2_0 ) . Should ( )
498+ . BePlatformAgnosticEquivalentTo ( yaml ) ;
499+
446500 }
447501 }
448502
449- public class MockAvroSchemaLoader : IStreamLoader
503+ public class MockStringLoader : IStreamLoader
450504 {
451- const string Payload =
452- """
453- {
454- "type": "record",
455- "name": "thecodebuzz_schema",
456- "namespace": "thecodebuzz.avro",
457- "fields": [
458- {
459- "name": "username",
460- "type": "string",
461- "doc": "Name of the user account on Thecodebuzz.com"
462- },
463- {
464- "name": "email",
465- "type": "string",
466- "doc": "The email of the user logging message on the blog"
467- },
468- {
469- "name": "timestamp",
470- "type": "long",
471- "doc": "time in seconds"
472- }
473- ],
474- "doc:": "A basic schema for storing thecodebuzz blogs messages"
475- }
476- """ ;
505+ public MockStringLoader ( string input )
506+ {
507+ this . input = input ;
508+ }
509+
510+ private readonly string input ;
477511
478512 public Stream Load ( Uri uri )
479513 {
480514 var stream = new MemoryStream ( ) ;
481515 var writer = new StreamWriter ( stream ) ;
482- writer . Write ( Payload ) ;
516+ writer . Write ( this . input ) ;
483517 writer . Flush ( ) ;
484518 stream . Position = 0 ;
485519 return stream ;
@@ -490,6 +524,7 @@ public Task<Stream> LoadAsync(Uri uri)
490524 return Task . FromResult ( this . Load ( uri ) ) ;
491525 }
492526 }
527+
493528 public class MockJsonSchemaLoader : IStreamLoader
494529 {
495530 const string Message =
0 commit comments