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
66 changes: 33 additions & 33 deletions src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,22 @@ s is ODataOperationSegment ||
previousTypeCastSegmentId = "As" + Utils.UpperFirstChar(schemaElement.Name);
items.Add(previousTypeCastSegmentId);
}
else if (segment is ODataOperationSegment operationSegment)
{
// Navigation property generated via composable function
items.Add(operationSegment.Identifier);
else if (segment is ODataOperationSegment operationSegment)
{
// Navigation property generated via composable function
items.Add(operationSegment.Identifier);
}
else if (segment is ODataKeySegment keySegment && keySegment.IsAlternateKey)
{
// We'll consider alternate keys in the operation id to eliminate potential duplicates with operation id of primary path
if (segment == segments.Last())
{
items.Add("By" + string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x))));
}
else
{
items.Add(keySegment.Identifier);
}
else if (segment is ODataKeySegment keySegment && keySegment.IsAlternateKey)
{
// We'll consider alternate keys in the operation id to eliminate potential duplicates with operation id of primary path
if (segment == segments.Last())
{
items.Add("By" + string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x))));
}
else
{
items.Add(keySegment.Identifier);
}
}
}

Expand Down Expand Up @@ -366,29 +366,29 @@ internal static string GenerateODataTypeCastPathOperationIdPrefix(ODataPath path
}
else if (secondLastSegment is ODataKeySegment keySegment)
{
if (isIndexedCollValuedNavProp)
{
operationId = GenerateNavigationPropertyPathOperationId(path, "Get");
if (isIndexedCollValuedNavProp)
{
operationId = GenerateNavigationPropertyPathOperationId(path, "Get");
}
else
{
string entityTypeName = keySegment.EntityType.Name;
string getPrefix = includeListOrGetPrefix ? "Get" : null;
string operationName = $"{getPrefix}{Utils.UpperFirstChar(entityTypeName)}";
if (keySegment.IsAlternateKey)
{
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
operationName = $"{operationName}By{alternateKeyName}";
}
operationId = (entitySet != null) ? entitySet.Name : singleton.Name;
operationId += $".{entityTypeName}.{operationName}";
}
else
{
string entityTypeName = keySegment.EntityType.Name;
string getPrefix = includeListOrGetPrefix ? "Get" : null;
string operationName = $"{getPrefix}{Utils.UpperFirstChar(entityTypeName)}";
if (keySegment.IsAlternateKey)
{
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
operationName = $"{operationName}By{alternateKeyName}";
}
operationId = (entitySet != null) ? entitySet.Name : singleton.Name;
operationId += $".{entityTypeName}.{operationName}";
}
}
else if (secondLastSegment is ODataNavigationSourceSegment)
{
operationId = (entitySet != null)
? entitySet.Name + "." + entitySet.EntityType().Name + $".{(includeListOrGetPrefix ? "List" : null)}" + Utils.UpperFirstChar(entitySet.EntityType().Name)
: singleton.Name + "." + singleton.EntityType().Name + $".{(includeListOrGetPrefix ? "Get" : null)}" + Utils.UpperFirstChar(singleton.EntityType().Name);
? entitySet.Name + "." + entitySet.EntityType.Name + $".{(includeListOrGetPrefix ? "List" : null)}" + Utils.UpperFirstChar(entitySet.EntityType.Name)
: singleton.Name + "." + singleton.EntityType.Name + $".{(includeListOrGetPrefix ? "Get" : null)}" + Utils.UpperFirstChar(singleton.EntityType.Name);
}

return operationId;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.OData.Reader/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ internal static IEdmEntityType EntityTypeFromPathSegment(this ODataSegment segme
case ODataNavigationPropertySegment navPropSegment:
return navPropSegment.EntityType;
case ODataNavigationSourceSegment navSourceSegment when navSourceSegment.NavigationSource is IEdmEntitySet entitySet:
return entitySet.EntityType();
return entitySet.EntityType;
case ODataNavigationSourceSegment navSourceSegment when navSourceSegment.NavigationSource is IEdmSingleton singleton:
return singleton.EntityType();
return singleton.EntityType;
case ODataKeySegment keySegment:
return keySegment.EntityType;
case ODataOperationSegment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal static class EdmVocabularyAnnotationExtensions
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
value = model.GetBoolean(entityType, term);
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public static string GetString(this IEdmModel model, IEdmVocabularyAnnotatable t
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
value = model.GetString(entityType, term);
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ public static T GetRecord<T>(this IEdmModel model, IEdmVocabularyAnnotatable tar
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
value = model.GetRecord<T>(entityType, term);
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ public static IEnumerable<string> GetCollection(this IEdmModel model, IEdmVocabu
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
value = model.GetCollection(entityType, term);
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ public static IEnumerable<T> GetCollection<T>(this IEdmModel model, IEdmVocabula
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
value = model.GetCollection<T>(entityType, term);
}
}
Expand Down
45 changes: 4 additions & 41 deletions src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public static IDictionary<IEdmEntityType, IList<IEdmNavigationSource>> LoadAllNa
{
Action<IEdmNavigationSource, IDictionary<IEdmEntityType, IList<IEdmNavigationSource>>> action = (ns, dic) =>
{
if (!dic.TryGetValue(ns.EntityType(), out IList<IEdmNavigationSource> value))
if (!dic.TryGetValue(ns.EntityType, out IList<IEdmNavigationSource> value))
{
value = new List<IEdmNavigationSource>();
dic[ns.EntityType()] = value;
dic[ns.EntityType] = value;
}

value.Add(ns);
Expand Down Expand Up @@ -145,43 +145,6 @@ public static IEnumerable<IEdmComplexType> FindAllBaseTypes(this IEdmComplexType
}
}

/// <summary>
/// Checks if the <paramref name="baseType"/> is assignable to <paramref name="subtype"/>.
/// In other words, if <paramref name="subtype"/> is a subtype of <paramref name="baseType"/> or not.
/// </summary>
/// <param name="baseType">Type of the base type.</param>
/// <param name="subtype">Type of the sub type.</param>
/// <returns>true, if the <paramref name="baseType"/> is assignable to <paramref name="subtype"/>. Otherwise returns false.</returns>
[Obsolete]
public static bool IsAssignableFrom(this IEdmEntityType baseType, IEdmEntityType subtype)
{
Utils.CheckArgumentNull(baseType, nameof(baseType));
Utils.CheckArgumentNull(subtype, nameof(subtype));

if (baseType.TypeKind != subtype.TypeKind)
{
return false;
}

if (subtype.IsEquivalentTo(baseType))
{
return true;
}

IEdmStructuredType structuredSubType = subtype;
while (structuredSubType != null)
{
if (structuredSubType.IsEquivalentTo(baseType))
{
return true;
}

structuredSubType = structuredSubType.BaseType;
}

return false;
}

/// <summary>
/// Check whether the operation is overload in the model.
/// </summary>
Expand Down Expand Up @@ -215,8 +178,8 @@ public static bool OperationTargetsMultiplePaths(this IEdmModel model, IEdmOpera

IEdmTypeReference bindingParameterType = operation.Parameters.First().Type;

return model.EntityContainer.EntitySets().Select(static x => x.EntityType())
.Concat(model.EntityContainer.Singletons().Select(static x => x.EntityType()))
return model.EntityContainer.EntitySets().Select(static x => x.EntityType)
.Concat(model.EntityContainer.Singletons().Select(static x => x.EntityType))
.Where(x => x.FullName().Equals(bindingParameterType.FullName(), StringComparison.OrdinalIgnoreCase)).Count() > 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ODataNavigationSourceSegment(IEdmNavigationSource navigationSource)
public IEdmNavigationSource NavigationSource { get; }

/// <inheritdoc />
public override IEdmEntityType EntityType => NavigationSource.EntityType();
public override IEdmEntityType EntityType => NavigationSource.EntityType;

/// <inheritdoc />
public override string Identifier { get => NavigationSource.Name; }
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private void RetrieveNavigationSourcePaths(IEdmNavigationSource navigationSource
AppendPath(path.Clone());

IEdmEntitySet entitySet = navigationSource as IEdmEntitySet;
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
CountRestrictionsType count = null;
bool? indexableByKey = false;

Expand Down Expand Up @@ -923,14 +923,14 @@ private List<IEdmEntityType> GetAllEntitiesForOperation(IEdmTypeReference bindin
var firstEntityType = bindingType.AsEntity().EntityDefinition();

bool filter(IEdmNavigationSource z) =>
z.EntityType() != firstEntityType &&
z.EntityType().FindAllBaseTypes().Contains(firstEntityType);
z.EntityType != firstEntityType &&
z.EntityType.FindAllBaseTypes().Contains(firstEntityType);

return new IEdmEntityType[] { firstEntityType }
.Union(_model.EntityContainer.EntitySets()
.Where(filter).Select(x => x.EntityType())) //Search all EntitySets
.Where(filter).Select(x => x.EntityType)) //Search all EntitySets
.Union(_model.EntityContainer.Singletons()
.Where(filter).Select(x => x.EntityType())) //Search all singletons
.Where(filter).Select(x => x.EntityType)) //Search all singletons
.Distinct()
.ToList();
}
Expand Down Expand Up @@ -1082,7 +1082,7 @@ private void AppendBoundOperationOnDerived(
}
else
{
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataKeySegment(ns.EntityType()),
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataKeySegment(ns.EntityType),
new ODataTypeCastSegment(bindingEntityType , _model),
new ODataOperationSegment(edmOperation, isEscapedFunction, _model));
AppendPath(newPath);
Expand Down
5 changes: 0 additions & 5 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ public string GetPathHash(OpenApiConvertSettings settings, ODataPath path = defa
/// <returns>The path item name.</returns>
public abstract string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters);

/// <summary>
/// Provides any deprecation information for the segment.
/// </summary>
[Obsolete("This property never returned any value or was used by the library.")]
public Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiDeprecationExtension Deprecation { get; set; }
/// <summary>
/// Returns the list of <see cref="IEdmVocabularyAnnotatable"/> this segment refers to.
/// </summary>
Expand Down
Loading