From d97b80b52b8ff5db5485224b78dc1ac705d7e182 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 20 Mar 2023 14:26:39 +0300 Subject: [PATCH 1/3] Check whether base type has stream before adding $value segment --- src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index 90f8f240..32c59801 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()); From c1e2ba1473f24e8515eb0e82acbf26c03daf6f4e Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 20 Mar 2023 15:03:42 +0300 Subject: [PATCH 2/3] Update tests --- .../Edm/ODataPathProviderTests.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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] From d3846b30cf598232664beafbd35b5c55ec0259c8 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 20 Mar 2023 15:10:53 +0300 Subject: [PATCH 3/3] Update release notes --- .../Microsoft.OpenAPI.OData.Reader.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 b194e40c..70eb71a0 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -15,7 +15,7 @@ netstandard2.0 Microsoft.OpenApi.OData true - 1.3.0-preview2 + 1.3.0-preview3 This package contains the codes you need to convert OData CSDL to Open API Document of Model. © Microsoft Corporation. All rights reserved. Microsoft OpenApi OData EDM @@ -25,6 +25,7 @@ - Skips adding a $count path if a similar count() function path exists #347 - Checks whether path exists before adding it to the paths dictionary #343 - Strips namespace prefix from operation segments and aliases type cast segments #348 +- Adds $value segment to paths with entity types with base types with HasStream=true #314 Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk