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)
218
218
219
219
try
220
220
{
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 ;
222
228
}
223
229
catch ( AsyncApiException ex )
224
230
{
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ namespace LEGO.AsyncAPI.Tests
6
6
using System . Collections . Generic ;
7
7
using System . Linq ;
8
8
using System . Text . Json . Nodes ;
9
+ using FluentAssertions ;
9
10
using LEGO . AsyncAPI . Exceptions ;
10
11
using LEGO . AsyncAPI . Models ;
11
12
using LEGO . AsyncAPI . Models . Interfaces ;
@@ -336,6 +337,32 @@ public void Read_WithBasicPlusSecuritySchemeDeserializes()
336
337
Assert . AreEqual ( "Provide your username and password for SASL/SCRAM authentication" , scheme . Value . Description ) ;
337
338
}
338
339
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
+
339
366
[ Test ]
340
367
public void Read_WithBasicPlusOAuthFlowDeserializes ( )
341
368
{
You can’t perform that action at this time.
0 commit comments