Skip to content

Commit 21e5d64

Browse files
Temporarily remove typecasts from TargetPath used for fetching annotations until we have a fix in the Edm library
1 parent 80116ad commit 21e5d64

File tree

4 files changed

+12
-36
lines changed

4 files changed

+12
-36
lines changed

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -280,28 +280,6 @@ public static IEnumerable<T> GetCollection<T>(this IEdmModel model, IEdmVocabula
280280
});
281281
}
282282

283-
/// <summary>
284-
/// Gets the collection of record value (a complex type) for the given targetPath.
285-
/// </summary>
286-
/// <typeparam name="T">The CLR mapping type.</typeparam>
287-
/// <param name="model">The Edm model.</param>
288-
/// <param name="targetPath">The string representation of the Edm target path.</param>
289-
/// <param name="qualifiedName">The Term qualified name.</param>
290-
/// <returns></returns>
291-
public static IEnumerable<T> GetCollection<T>(this IEdmModel model, string targetPath, string qualifiedName)
292-
where T : IRecord, new()
293-
{
294-
Utils.CheckArgumentNull(model, nameof(model));
295-
Utils.CheckArgumentNull(targetPath, nameof(targetPath));
296-
Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName));
297-
298-
IEdmTargetPath target = model.GetTargetPath(targetPath);
299-
if (target == null)
300-
return null;
301-
302-
return model.GetCollection<T>(target, qualifiedName);
303-
}
304-
305283
/// <summary>
306284
/// Gets the links record value (a complex type) for the given <see cref="IEdmVocabularyAnnotatable"/>.
307285
/// </summary>
@@ -329,7 +307,11 @@ public static Link GetLinkRecord(this IEdmModel model, string targetPath, string
329307
Utils.CheckArgumentNull(model, nameof(model));
330308
Utils.CheckArgumentNull(targetPath, nameof(targetPath));
331309

332-
return model.GetCollection<Link>(targetPath, CoreConstants.Links)?.FirstOrDefault(x => x.Rel == linkRel);
310+
IEdmTargetPath target = model.GetTargetPath(targetPath);
311+
if (target == null)
312+
return null;
313+
314+
return model.GetLinkRecord(target, linkRel);
333315
}
334316

335317
/// <summary>

src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyBaseOperationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ internal abstract class ComplexPropertyBaseOperationHandler : OperationHandler
1717
/// <inheritdoc/>
1818
protected override void Initialize(ODataContext context, ODataPath path)
1919
{
20+
base.Initialize(context, path);
2021
ComplexPropertySegment = path.LastSegment as ODataComplexPropertySegment ?? throw Error.ArgumentNull(nameof(path));
21-
base.SetTargetPath();
2222
}
2323

2424
/// <inheritdoc/>

src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,6 @@ protected override void SetExternalDocs(OpenApiOperation operation)
129129
}
130130
}
131131

132-
/// <inheritdoc/>
133-
protected override void SetTargetPath()
134-
{
135-
base.SetTargetPath();
136-
if (Path.LastSegment is ODataRefSegment)
137-
{
138-
int lastIndex = TargetPath.LastIndexOf('/');
139-
TargetPath = lastIndex > 0 ? TargetPath.Substring(0, lastIndex) : TargetPath;
140-
}
141-
}
142-
143132
/// <summary>
144133
/// Retrieves the CRUD restrictions annotations for the navigation property
145134
/// in context, given a capability annotation term.

src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,16 @@ protected virtual void SetCustomLinkRelType()
303303
protected virtual void SetTargetPath()
304304
{
305305
var targetPath = new StringBuilder(Context.Model.EntityContainer.FullName());
306-
foreach (var segment in Path.Segments.Where(segment => segment is not ODataKeySegment))
306+
307+
bool skipLastSegment = Path.LastSegment is ODataRefSegment;
308+
foreach (var segment in Path.Segments.Where(segment => segment is not ODataKeySegment
309+
&& segment is not ODataTypeCastSegment // TODO: Presence of type casts in the TargetPath is currently throwing exceptions in Edm lib. Remove after update.
310+
&& !(skipLastSegment && segment == Path.LastSegment)))
307311
{
308312
targetPath.Append($"/{segment.Identifier}");
309313
}
310314
TargetPath = targetPath.ToString();
311315
}
316+
312317
}
313318
}

0 commit comments

Comments
 (0)