Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds $value segment to paths with entity types with base types with HasStream=true #358

Merged
merged 4 commits into from
Mar 21, 2023
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
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ private void RetrieveMediaEntityStreamPaths(IEdmEntityType entityType, ODataPath
}
}

/* Create a /$value path only if entity has stream and
/* Append a $value segment only if entity (or base type) has stream and
* does not contain a structural property named Content
*/
if (createValuePath && entityType.HasStream)
if (createValuePath && (entityType.HasStream || ((entityType.BaseType as IEdmEntityType)?.HasStream ?? false)))
{
currentPath.Push(new ODataStreamContentSegment());
AppendPath(currentPath.Clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Checks whether path exists before adding it to the paths dictionary #343
- Strips namespace prefix from operation segments and aliases type cast segments #348
- Return response status code 2XX for PUT operations of stream properties when UseSuccessStatusCodeRange is enabled #310
- Adds $value segment to paths with entity types with base types with HasStream=true #314
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ public void GetPathsForGraphBetaModelReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(18054, paths.Count());
AssertGraphBetaModelPaths(paths);
}

private void AssertGraphBetaModelPaths(IEnumerable<ODataPath> paths)
{
// Test that $count and microsoft.graph.count() segments are not both created for the same path.
Assert.Null(paths.FirstOrDefault(p => p.GetPathItemName().Equals("/drives({id})/items({id1})/workbook/tables/$count")));
Assert.NotNull(paths.FirstOrDefault(p => p.GetPathItemName().Equals("/drives({id})/items({id1})/workbook/tables/microsoft.graph.count()")));
Assert.Equal(18024, paths.Count());

// Test that $value segments are created for entity types with base types with HasStream="true"
Assert.NotNull(paths.FirstOrDefault(p => p.GetPathItemName().Equals("/me/chats({id})/messages({id1})/hostedContents({id2})/$value")));
}

[Fact]
Expand All @@ -75,7 +84,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(18675, paths.Count());
Assert.Equal(18705, paths.Count());
}

[Fact]
Expand Down