private bool AppendBoundOperationOnNavigationSourcePath()

in src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs [608:644]


        private bool AppendBoundOperationOnNavigationSourcePath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
        {
            bool found = false;

            if (_allNavigationSourcePaths.TryGetValue(bindingEntityType, out IList<ODataPath> value))
            {
                bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);

                foreach (var subPath in value)
                {
                    var lastPathSegment = subPath.LastOrDefault();
                    var secondLastPathSegment = subPath.Count > 1 ? subPath.ElementAt(subPath.Count - 2) : null;
                    if (subPath.Kind == ODataPathKind.TypeCast &&
                        !isCollection &&
                        secondLastPathSegment != null &&
                        secondLastPathSegment is not ODataKeySegment &&
                        (secondLastPathSegment is not ODataNavigationSourceSegment navSource || navSource.NavigationSource is not IEdmSingleton) &&
                        (secondLastPathSegment is not ODataNavigationPropertySegment navProp || navProp.NavigationProperty.Type.IsCollection()))
                    {// we don't want to add operations bound to single elements on type cast segments under collections, only under the key segment, singletons and nav props bound to singles.
                        continue;
                    }
                    else if ((lastPathSegment is not ODataTypeCastSegment castSegment ||
                                castSegment.StructuredType == bindingEntityType ||
                                bindingEntityType.InheritsFrom(castSegment.StructuredType)) && // we don't want to add operations from the parent types under type cast segments because they already are present without the cast
                        ((isCollection && subPath.Kind == ODataPathKind.EntitySet) ||
                            (!isCollection && !_oDataPathKindsToSkipForOperationsWhenSingle.Contains(subPath.Kind))))
                    {
                        ODataPath newPath = subPath.Clone();
                        newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
                        AppendPath(newPath);
                        found = true;
                    }
                }
            }

            return found;
        }