diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index 0c9b8276..868fd881 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -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()); diff --git a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj index 89bd34d7..d2b1b7de 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -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 Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs index 868120c9..ab810ce0 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs @@ -52,9 +52,18 @@ public void GetPathsForGraphBetaModelReturnsAllPaths() // Assert Assert.NotNull(paths); + Assert.Equal(18054, paths.Count()); + AssertGraphBetaModelPaths(paths); + } + + private void AssertGraphBetaModelPaths(IEnumerable 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] @@ -75,7 +84,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths() // Assert Assert.NotNull(paths); - Assert.Equal(18675, paths.Count()); + Assert.Equal(18705, paths.Count()); } [Fact]