in src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs [49:118]
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;
}
}
// containment: Get / (Post - Collection | Patch - Single)
// non-containment: Get
AddGetOperation(item, restriction);
if (NavigationProperty.ContainsTarget)
{
if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
{
if (LastSegmentIsKeySegment)
{
// Need to check this scenario is valid or not?
UpdateRestrictionsType update = restriction?.UpdateRestrictions;
if (update == null || update.IsUpdatable)
{
AddOperation(item, OperationType.Patch);
}
}
else
{
InsertRestrictionsType insert = restriction?.InsertRestrictions;
if (insert == null || insert.IsInsertable)
{
AddOperation(item, OperationType.Post);
}
}
}
else
{
UpdateRestrictionsType update = restriction?.UpdateRestrictions;
if (update == null || update.IsUpdatable)
{
AddOperation(item, OperationType.Patch);
}
}
}
AddDeleteOperation(item, restriction);
}