Skip to content

Commit 80e7d84

Browse files
committed
Throw an exception if referenced schema does not exist
1 parent 6c88daa commit 80e7d84

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ public JsonSchema ResolveJsonSchemaReference(Uri reference, string description =
277277
}
278278
else
279279
{
280-
return null;
280+
var referenceId = reference.OriginalString.Split('/').LastOrDefault();
281+
throw new OpenApiException(string.Format(Properties.SRResource.InvalidReferenceId, referenceId));
281282
}
282283
}
283284

@@ -349,7 +350,7 @@ private void ResolveJsonSchemaList(IList<JsonSchema> list, Action<List<JsonSchem
349350
for (int i = 0; i < list.Count; i++)
350351
{
351352
var entity = list[i];
352-
var reference = entity.GetRef();
353+
var reference = entity?.GetRef();
353354
if (reference != null)
354355
{
355356
list[i] = ResolveJsonSchemaReference(reference);

0 commit comments

Comments
 (0)