File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
src/LEGO.AsyncAPI/Services Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -218,7 +218,13 @@ private T ResolveReference<T>(AsyncApiReference reference)
218218
219219 try
220220 {
221- return this . currentDocument . ResolveReference ( reference ) as T ;
221+ var resolvedReference = this . currentDocument . ResolveReference ( reference ) as T ;
222+ if ( resolvedReference == null )
223+ {
224+ throw new AsyncApiException ( $ "Cannot resolve reference '{ reference . Reference } ' to '{ typeof ( T ) . Name } '.") ;
225+ }
226+
227+ return resolvedReference ;
222228 }
223229 catch ( AsyncApiException ex )
224230 {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ namespace LEGO.AsyncAPI.Tests
66 using System . Collections . Generic ;
77 using System . Linq ;
88 using System . Text . Json . Nodes ;
9+ using FluentAssertions ;
910 using LEGO . AsyncAPI . Exceptions ;
1011 using LEGO . AsyncAPI . Models ;
1112 using LEGO . AsyncAPI . Models . Interfaces ;
@@ -336,6 +337,32 @@ public void Read_WithBasicPlusSecuritySchemeDeserializes()
336337 Assert . AreEqual ( "Provide your username and password for SASL/SCRAM authentication" , scheme . Value . Description ) ;
337338 }
338339
340+ [ Test ]
341+ public void Read_WithWrongReference_AddsError ( )
342+ {
343+ var yaml =
344+ """
345+ asyncapi: 2.3.0
346+ info:
347+ title: test
348+ version: 1.0.0
349+ channels:
350+ workspace:
351+ publish:
352+ message:
353+ $ref: '#/components/securitySchemes/saslScram'
354+ components:
355+ securitySchemes:
356+ saslScram:
357+ type: scramSha256
358+ description: Provide your username and password for SASL/SCRAM authentication
359+ """ ;
360+ var reader = new AsyncApiStringReader ( ) ;
361+ var doc = reader . Read ( yaml , out var diagnostic ) ;
362+ diagnostic . Errors . Should ( ) . NotBeEmpty ( ) ;
363+ doc . Channels . Values . First ( ) . Publish . Message . First ( ) . Should ( ) . BeNull ( ) ;
364+ }
365+
339366 [ Test ]
340367 public void Read_WithBasicPlusOAuthFlowDeserializes ( )
341368 {
You can’t perform that action at this time.
0 commit comments