in src/Microsoft.OpenApi.OData.Reader/PathItem/RefPathItemHandler.cs [36:92]
protected override void SetOperations(OpenApiPathItem item)
{
IEdmEntitySet entitySet = NavigationSource as IEdmEntitySet;
IEdmVocabularyAnnotatable target = entitySet;
if (target == null)
{
target = NavigationSource as IEdmSingleton;
}
string navigationPropertyPath = String.Join("/",
Path.Segments.Where(s => !(s is ODataKeySegment || s is ODataNavigationSourceSegment)).Select(e => e.Identifier));
NavigationRestrictionsType navigation = Context.Model.GetRecord<NavigationRestrictionsType>(target, CapabilitiesConstants.NavigationRestrictions);
NavigationPropertyRestriction restriction = navigation?.RestrictedProperties?.FirstOrDefault(r => r.NavigationProperty == navigationPropertyPath);
// verify using individual first
if (restriction != null && restriction.Navigability != null && restriction.Navigability.Value == NavigationType.None)
{
return;
}
if (restriction == null || restriction.Navigability == null)
{
// if the individual has not navigability setting, use the global navigability setting
if (navigation != null && navigation.Navigability != null && navigation.Navigability.Value == NavigationType.None)
{
// Default navigability for all navigation properties of the annotation target.
// Individual navigation properties can override this value via `RestrictedProperties/Navigability`.
return;
}
}
// So far, we only consider the non-containment
Debug.Assert(!NavigationProperty.ContainsTarget);
// Create the ref
if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
{
ODataSegment penultimateSegment = Path.Segments.Reverse().Skip(1).First();
if (penultimateSegment is ODataKeySegment)
{
// Collection-valued: DELETE ~/entityset/{key}/collection-valued-Nav/{key}/$ref
AddDeleteOperation(item, restriction);
}
else
{
AddReadOperation(item, restriction);
AddInsertOperation(item, restriction);
}
}
else
{
AddReadOperation(item, restriction);
AddUpdateOperation(item, restriction);
AddDeleteOperation(item, restriction);
}
}