Skip to content

Commit 1f7d5e5

Browse files
Improve test
- Fix typo. - Improve reported path. - Find circular references.
1 parent b375ed4 commit 1f7d5e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,36 @@ public override void Visit(IOpenApiSchema schema)
129129

130130
private void ValidateSchemaReference(OpenApiSchemaReference reference)
131131
{
132+
if (reference.RecursiveTarget is not null)
133+
{
134+
return;
135+
}
136+
132137
var id = reference.Reference.ReferenceV3;
133138

134139
if (id is { Length: > 0 } && !IsValidSchemaReference(id, document))
135140
{
136141
var isValid = false;
137142

138-
// Sometimes ReferenceV3 is not a JSON valid JSON pointer, but the $ref
143+
// Sometimes ReferenceV3 is not a valid JSON pointer, but the $ref
139144
// associated with it still points to a valid location in the document.
140145
// In these cases, we need to find it manually to verify that fact before
141146
// generating a warning that the schema reference is indeed invalid.
142147
var parent = Find(PathString, document);
143148
var @ref = parent[OpenApiSchemaKeywords.RefKeyword];
149+
var path = PathString[2..]; // Trim off the leading "#/" as the context is already at the root
144150

145151
if (@ref is not null && @ref.GetValueKind() is System.Text.Json.JsonValueKind.String &&
146152
@ref.GetValue<string>() is { Length: > 0 } refId)
147153
{
148154
id = refId;
155+
path += $"/{OpenApiSchemaKeywords.RefKeyword}";
149156
isValid = IsValidSchemaReference(id, document);
150157
}
151158

152159
if (!isValid)
153160
{
154-
context.Enter(PathString[2..]); // Trim off the leading "#/" as the context is already at the root
161+
context.Enter(path);
155162
context.CreateWarning(ruleName, $"The schema reference '{id}' does not point to an existing schema.");
156163
context.Exit();
157164
}

0 commit comments

Comments
 (0)