Skip to content

Commit 104b4cb

Browse files
committed
- fixes a null reference exception for complex type segments
Signed-off-by: Vincent Biret <[email protected]>
1 parent 9255901 commit 104b4cb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 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:
@@ -440,7 +441,8 @@ private bool ShouldExpandNavigationProperty(IEdmNavigationProperty navigationPro
440441
IEdmEntityType navEntityType = navigationProperty.ToEntityType();
441442
foreach (ODataSegment segment in currentPath)
442443
{
443-
if (navEntityType.IsAssignableFrom(segment.EntityType))
444+
if (segment.EntityType != null &&
445+
navEntityType.IsAssignableFrom(segment.EntityType))
444446
{
445447
return false;
446448
}

0 commit comments

Comments
 (0)