Skip to content

Commit d0ec4f3

Browse files
authored
Adds $value segment to paths with entity types with base types with HasStream=true (#358)
* Check whether base type has stream before adding $value segment * Update tests * Update release notes
1 parent feae089 commit d0ec4f3

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ private void RetrieveMediaEntityStreamPaths(IEdmEntityType entityType, ODataPath
391391
}
392392
}
393393

394-
/* Create a /$value path only if entity has stream and
394+
/* Append a $value segment only if entity (or base type) has stream and
395395
* does not contain a structural property named Content
396396
*/
397-
if (createValuePath && entityType.HasStream)
397+
if (createValuePath && (entityType.HasStream || ((entityType.BaseType as IEdmEntityType)?.HasStream ?? false)))
398398
{
399399
currentPath.Push(new ODataStreamContentSegment());
400400
AppendPath(currentPath.Clone());

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Checks whether path exists before adding it to the paths dictionary #343
2727
- Strips namespace prefix from operation segments and aliases type cast segments #348
2828
- Return response status code 2XX for PUT operations of stream properties when UseSuccessStatusCodeRange is enabled #310
29+
- Adds $value segment to paths with entity types with base types with HasStream=true #314
2930
</PackageReleaseNotes>
3031
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3132
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,18 @@ public void GetPathsForGraphBetaModelReturnsAllPaths()
5252

5353
// Assert
5454
Assert.NotNull(paths);
55+
Assert.Equal(18054, paths.Count());
56+
AssertGraphBetaModelPaths(paths);
57+
}
58+
59+
private void AssertGraphBetaModelPaths(IEnumerable<ODataPath> paths)
60+
{
61+
// Test that $count and microsoft.graph.count() segments are not both created for the same path.
5562
Assert.Null(paths.FirstOrDefault(p => p.GetPathItemName().Equals("/drives({id})/items({id1})/workbook/tables/$count")));
5663
Assert.NotNull(paths.FirstOrDefault(p => p.GetPathItemName().Equals("/drives({id})/items({id1})/workbook/tables/microsoft.graph.count()")));
57-
Assert.Equal(18024, paths.Count());
64+
65+
// Test that $value segments are created for entity types with base types with HasStream="true"
66+
Assert.NotNull(paths.FirstOrDefault(p => p.GetPathItemName().Equals("/me/chats({id})/messages({id1})/hostedContents({id2})/$value")));
5867
}
5968

6069
[Fact]
@@ -75,7 +84,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()
7584

7685
// Assert
7786
Assert.NotNull(paths);
78-
Assert.Equal(18675, paths.Count());
87+
Assert.Equal(18705, paths.Count());
7988
}
8089

8190
[Fact]

0 commit comments

Comments
 (0)