Skip to content

Commit 2bb1203

Browse files
committed
Update logic to guard against null exceptions
1 parent 80a02a2 commit 2bb1203

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -113,11 +113,11 @@ public static IOpenApiAny LoadAny(ParseNode node)
113113

114114
private static IOpenApiExtension LoadExtension(string name, ParseNode node)
115115
{
116-
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser))
116+
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser) && parser(
117+
OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()),
118+
OpenApiSpecVersion.OpenApi2_0) is { } result)
117119
{
118-
return parser(
119-
OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()),
120-
OpenApiSpecVersion.OpenApi2_0);
120+
return result;
121121
}
122122
else
123123
{

src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ public static IOpenApiAny LoadAny(ParseNode node)
171171

172172
private static IOpenApiExtension LoadExtension(string name, ParseNode node)
173173
{
174-
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser))
174+
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser) && parser(
175+
OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()),
176+
OpenApiSpecVersion.OpenApi3_0) is { } result)
175177
{
176-
return parser(
177-
OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()),
178-
OpenApiSpecVersion.OpenApi3_0);
178+
return result;
179179
}
180180
else
181181
{

0 commit comments

Comments
 (0)