Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,25 +393,26 @@ internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, Op

return segmentName;
}

/// <summary>
/// Checks whether an operation is allowed on a model element.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="edmOperation">The target operation.</param>
/// <param name="annotatable">The model element.</param>
/// <param name="operationAllowed">Optional: Default is true.
/// The operation will be allowed by default if the annotation Org.OData.Core.V1.RequiresExplicitBinding is undefined for the given operation. </param>
/// <returns>true if the operation is allowed, otherwise false.</returns>
internal static bool IsOperationAllowed(IEdmModel model, IEdmOperation edmOperation, IEdmVocabularyAnnotatable annotatable)
internal static bool IsOperationAllowed(IEdmModel model, IEdmOperation edmOperation, IEdmVocabularyAnnotatable annotatable, bool operationAllowed = true)
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(edmOperation, nameof(edmOperation));
Utils.CheckArgumentNull(annotatable, nameof(annotatable));

var requiresExplicitBinding = model.FindVocabularyAnnotations(edmOperation).FirstOrDefault(x => x.Term.Name == CapabilitiesConstants.RequiresExplicitBindingName);

if (requiresExplicitBinding == null)
{
return true;
return operationAllowed;
}

var boundOperations = model.GetCollection(annotatable, CapabilitiesConstants.ExplicitOperationBindings)?.ToList();
Expand Down
16 changes: 3 additions & 13 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ secondLastPathSegment is not ODataKeySegment &&
if (annotatable != null && !EdmModelHelper.IsOperationAllowed(_model, edmOperation, annotatable))
{
continue;
}
}
}

ODataPath newPath = subPath.Clone();
Expand All @@ -824,13 +824,8 @@ private void AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOpera
foreach (var path in value.Where(x => !_pathKindToSkipForNavigationProperties.Contains(x.Kind)))
{
ODataNavigationPropertySegment npSegment = path.Segments.Last(s => s is ODataNavigationPropertySegment) as ODataNavigationPropertySegment;

if (!npSegment.NavigationProperty.ContainsTarget)
{
continue;
}

if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty))
if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty, npSegment.NavigationProperty.ContainsTarget))
{
continue;
}
Expand Down Expand Up @@ -954,12 +949,7 @@ private void AppendBoundOperationOnDerivedNavigationPropertyPath(
continue;
}

if (!npSegment.NavigationProperty.ContainsTarget)
{
continue;
}

if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty))
if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty, npSegment.NavigationProperty.ContainsTarget))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.5.0-preview4</Version>
<Version>1.5.0-preview5</Version>
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
Expand All @@ -25,6 +25,7 @@
- Updates README #13, #253, #40
- Fixes casing in default propertyName for `innerError` in the `ErrorMainSchema`
- Adds support for `x-ms-enum-flags` extension for flagged enums
- Use containment together with RequiresExplicitBinding annotation to check whether to append bound operations to navigation properties #430
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down