Skip to content

Commit 5e5c41e

Browse files
committed
- adds defensive programing to avoid dependency on null entity type
Signed-off-by: Vincent Biret <[email protected]>
1 parent 9255901 commit 5e5c41e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static bool IsAssignableFrom(this IEdmEntityType baseType, IEdmEntityType
157157
Utils.CheckArgumentNull(baseType, nameof(baseType));
158158
Utils.CheckArgumentNull(subtype, nameof(subtype));
159159

160-
if (baseType.TypeKind != subtype.TypeKind)
160+
if (baseType == null || subtype == null || baseType.TypeKind != subtype.TypeKind)
161161
{
162162
return false;
163163
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ private void AppendPath(ODataPath path)
135135
case ODataPathKind.EntitySet:
136136
case ODataPathKind.Singleton:
137137
case ODataPathKind.MediaEntity:
138-
ODataNavigationSourceSegment navigationSourceSegment = (ODataNavigationSourceSegment)path.FirstSegment;
139-
if (!_allNavigationSourcePaths.TryGetValue(navigationSourceSegment.EntityType, out IList<ODataPath> nsList))
138+
if (path.FirstSegment is ODataNavigationSourceSegment navigationSourceSegment)
140139
{
141-
nsList = new List<ODataPath>();
142-
_allNavigationSourcePaths[navigationSourceSegment.EntityType] = nsList;
140+
if(!_allNavigationSourcePaths.TryGetValue(navigationSourceSegment.EntityType, out IList<ODataPath> nsList))
141+
{
142+
nsList = new List<ODataPath>();
143+
_allNavigationSourcePaths[navigationSourceSegment.EntityType] = nsList;
144+
}
145+
nsList.Add(path);
143146
}
144-
145-
nsList.Add(path);
146147
break;
147148

148149
case ODataPathKind.NavigationProperty:

0 commit comments

Comments
 (0)