File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed
src/Microsoft.OpenApi/Services
test/Microsoft.OpenApi.Readers.Tests/V31Tests Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -376,7 +376,10 @@ public bool Contains(string location)
376
376
// Prevent infinite recursion in case of circular references
377
377
if ( visitedSchemas . Contains ( schema ) )
378
378
{
379
- return null ;
379
+ if ( schema is OpenApiSchemaReference openApiSchemaReference )
380
+ throw new InvalidOperationException ( $ "Circular reference detected while resolving schema: { openApiSchemaReference . Reference . ReferenceV3 } ") ;
381
+ else
382
+ throw new InvalidOperationException ( $ "Circular reference detected while resolving schema") ;
380
383
}
381
384
visitedSchemas . Push ( schema ) ;
382
385
// Traverse schema object to resolve subschemas
Original file line number Diff line number Diff line change @@ -502,9 +502,9 @@ public void ExitsEarlyOnCyclicalReferences()
502
502
document . RegisterComponents ( ) ;
503
503
504
504
var tagsSchemaRef = Assert . IsType < OpenApiSchemaReference > ( categorySchema . Properties [ "tags" ] ) ;
505
- Assert . Null ( tagsSchemaRef . Items ) ;
505
+ Assert . Throws < InvalidOperationException > ( ( ) => tagsSchemaRef . Items ) ;
506
506
Assert . Equal ( "#/components/schemas/Category/properties/parent/properties/tags" , tagsSchemaRef . Reference . ReferenceV3 ) ;
507
- Assert . Null ( tagsSchemaRef . Target ) ;
507
+ Assert . Throws < InvalidOperationException > ( ( ) => tagsSchemaRef . Target ) ;
508
508
509
509
var parentSchemaRef = Assert . IsType < OpenApiSchemaReference > ( categorySchema . Properties [ "parent" ] ) ;
510
510
Assert . Equal ( "#/components/schemas/Category" , parentSchemaRef . Reference . ReferenceV3 ) ;
You can’t perform that action at this time.
0 commit comments