Skip to content

Commit aaa82b3

Browse files
authored
Use containment together with RequiresExplicitBinding annotation to check whether to append bound operations to navigation properties (#430)
* Refactor method * Refactor use of containment when checking whether to append operation on path * Update release notes
1 parent d9474cf commit aaa82b3

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,25 +393,26 @@ internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, Op
393393

394394
return segmentName;
395395
}
396-
396+
397397
/// <summary>
398398
/// Checks whether an operation is allowed on a model element.
399399
/// </summary>
400400
/// <param name="model">The Edm model.</param>
401401
/// <param name="edmOperation">The target operation.</param>
402402
/// <param name="annotatable">The model element.</param>
403+
/// <param name="operationAllowed">Optional: Default is true.
404+
/// The operation will be allowed by default if the annotation Org.OData.Core.V1.RequiresExplicitBinding is undefined for the given operation. </param>
403405
/// <returns>true if the operation is allowed, otherwise false.</returns>
404-
internal static bool IsOperationAllowed(IEdmModel model, IEdmOperation edmOperation, IEdmVocabularyAnnotatable annotatable)
406+
internal static bool IsOperationAllowed(IEdmModel model, IEdmOperation edmOperation, IEdmVocabularyAnnotatable annotatable, bool operationAllowed = true)
405407
{
406408
Utils.CheckArgumentNull(model, nameof(model));
407409
Utils.CheckArgumentNull(edmOperation, nameof(edmOperation));
408410
Utils.CheckArgumentNull(annotatable, nameof(annotatable));
409411

410412
var requiresExplicitBinding = model.FindVocabularyAnnotations(edmOperation).FirstOrDefault(x => x.Term.Name == CapabilitiesConstants.RequiresExplicitBindingName);
411-
412413
if (requiresExplicitBinding == null)
413414
{
414-
return true;
415+
return operationAllowed;
415416
}
416417

417418
var boundOperations = model.GetCollection(annotatable, CapabilitiesConstants.ExplicitOperationBindings)?.ToList();

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ secondLastPathSegment is not ODataKeySegment &&
802802
if (annotatable != null && !EdmModelHelper.IsOperationAllowed(_model, edmOperation, annotatable))
803803
{
804804
continue;
805-
}
805+
}
806806
}
807807

808808
ODataPath newPath = subPath.Clone();
@@ -824,13 +824,8 @@ private void AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOpera
824824
foreach (var path in value.Where(x => !_pathKindToSkipForNavigationProperties.Contains(x.Kind)))
825825
{
826826
ODataNavigationPropertySegment npSegment = path.Segments.Last(s => s is ODataNavigationPropertySegment) as ODataNavigationPropertySegment;
827-
828-
if (!npSegment.NavigationProperty.ContainsTarget)
829-
{
830-
continue;
831-
}
832827

833-
if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty))
828+
if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty, npSegment.NavigationProperty.ContainsTarget))
834829
{
835830
continue;
836831
}
@@ -954,12 +949,7 @@ private void AppendBoundOperationOnDerivedNavigationPropertyPath(
954949
continue;
955950
}
956951

957-
if (!npSegment.NavigationProperty.ContainsTarget)
958-
{
959-
continue;
960-
}
961-
962-
if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty))
952+
if (!EdmModelHelper.IsOperationAllowed(_model, edmOperation, npSegment.NavigationProperty, npSegment.NavigationProperty.ContainsTarget))
963953
{
964954
continue;
965955
}

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.5.0-preview4</Version>
18+
<Version>1.5.0-preview5</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
@@ -25,6 +25,7 @@
2525
- Updates README #13, #253, #40
2626
- Fixes casing in default propertyName for `innerError` in the `ErrorMainSchema`
2727
- Adds support for `x-ms-enum-flags` extension for flagged enums
28+
- Use containment together with RequiresExplicitBinding annotation to check whether to append bound operations to navigation properties #430
2829
</PackageReleaseNotes>
2930
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3031
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

0 commit comments

Comments
 (0)