Skip to content

Commit 9c7f3c4

Browse files
Merge pull request #1036 from microsoft/mk/resolve-null-reference-exception
Add validation for null schema values during V2 response header deserialization
2 parents cc98657 + b1b68f5 commit 9c7f3c4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 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;
@@ -139,8 +139,12 @@ internal static partial class OpenApiV2Deserializer
139139
{
140140
OpenApiConstants.Default,
141141
new AnyFieldMapParameter<OpenApiHeader>(
142-
p => p.Schema.Default,
143-
(p, v) => p.Schema.Default = v,
142+
p => p.Schema?.Default,
143+
(p, v) =>
144+
{
145+
if(p.Schema == null) return;
146+
p.Schema.Default = v;
147+
},
144148
p => p.Schema)
145149
}
146150
};
@@ -151,8 +155,12 @@ internal static partial class OpenApiV2Deserializer
151155
{
152156
OpenApiConstants.Enum,
153157
new AnyListFieldMapParameter<OpenApiHeader>(
154-
p => p.Schema.Enum,
155-
(p, v) => p.Schema.Enum = v,
158+
p => p.Schema?.Enum,
159+
(p, v) =>
160+
{
161+
if(p.Schema == null) return;
162+
p.Schema.Enum = v;
163+
},
156164
p => p.Schema)
157165
},
158166
};

0 commit comments

Comments
 (0)