Skip to content

Commit ab3fe1b

Browse files
Circular refs as errors
Report circular references as an error, rather than throwing an exception.
1 parent 1f7d5e5 commit ab3fe1b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/OpenApiDocumentIntegrationTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,20 @@ public override void Visit(IOpenApiSchema schema)
129129

130130
private void ValidateSchemaReference(OpenApiSchemaReference reference)
131131
{
132-
if (reference.RecursiveTarget is not null)
132+
try
133133
{
134+
if (reference.RecursiveTarget is not null)
135+
{
136+
return;
137+
}
138+
}
139+
catch (InvalidOperationException ex)
140+
{
141+
// Thrown if a circular reference is detected
142+
context.Enter($"{PathString[2..]}/{OpenApiSchemaKeywords.RefKeyword}");
143+
context.CreateError(ruleName, ex.Message);
144+
context.Exit();
145+
134146
return;
135147
}
136148

0 commit comments

Comments
 (0)