diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
index 0a2197f38..3bde84892 100644
--- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
+++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
@@ -245,6 +245,7 @@ private void RetrieveNavigationSourcePaths(IEdmNavigationSource navigationSource
IEdmEntitySet entitySet = navigationSource as IEdmEntitySet;
IEdmEntityType entityType = navigationSource.EntityType();
CountRestrictionsType count = null;
+ bool? indexableByKey = false;
// for entity set, create a path with key and a $count path
if (entitySet != null)
@@ -260,10 +261,15 @@ private void RetrieveNavigationSourcePaths(IEdmNavigationSource navigationSource
if (convertSettings.AddAlternateKeyPaths)
CreateAlternateKeyPath(path, entityType); //~/entitySet/{alternateKeyId}
- path.Push(new ODataKeySegment(entityType)); // ~/entitySet/{id}
- AppendPath(path.Clone());
+ indexableByKey = _model.GetBoolean(targetPath, CapabilitiesConstants.IndexableByKey)
+ ?? _model.GetBoolean(entitySet, CapabilitiesConstants.IndexableByKey);
- CreateTypeCastPaths(path, convertSettings, entityType, entitySet, false); // ~/entitySet/{id}/subType
+ if (indexableByKey ?? true)
+ {
+ path.Push(new ODataKeySegment(entityType)); // ~/entitySet/{id}
+ AppendPath(path.Clone());
+ CreateTypeCastPaths(path, convertSettings, entityType, entitySet, false); // ~/entitySet/{id}/subType
+ }
}
else if (navigationSource is IEdmSingleton singleton)
{ // ~/singleton/subType
@@ -285,7 +291,7 @@ private void RetrieveNavigationSourcePaths(IEdmNavigationSource navigationSource
}
}
- if (entitySet != null)
+ if (entitySet != null && (indexableByKey ?? true))
{
path.Pop(); // end of entity
}
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 c9a505472..de58f91ed 100644
--- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj
+++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj
@@ -15,13 +15,13 @@
netstandard2.0
Microsoft.OpenApi.OData
true
- 1.6.5
+ 1.6.6
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
https://github.com/Microsoft/OpenAPI.NET.OData
- - Use annotations with path as target to dermine whether to add an operation #535
+ - Adds support for IndexableByKey restrictions annotations on entity sets #541
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 da7b256a1..2c01862f8 100644
--- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs
+++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs
@@ -119,6 +119,34 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()
Assert.NotNull(paths);
Assert.Equal(17631, paths.Count());
}
+
+ [Theory]
+ [InlineData(true)]
+ [InlineData(false)]
+ public void GetEntitySetPathsWithIndexableByKeyAnnotationWorks(bool indexable)
+ {
+ // Arrange
+ string indexableAnnotation = @"";
+ indexableAnnotation = string.Format(indexableAnnotation, indexable);
+ IEdmModel model = GetInheritanceModel(indexableAnnotation);
+ ODataPathProvider provider = new();
+ var settings = new OpenApiConvertSettings();
+
+ // Act & Assert
+ var paths = provider.GetPaths(model, settings);
+ Assert.NotNull(paths);
+
+ if (indexable)
+ {
+ Assert.Equal(3, paths.Count());
+ Assert.Contains("/Customers({ID})", paths.Select(p => p.GetPathItemName()));
+ }
+ else
+ {
+ Assert.Equal(2, paths.Count());
+ Assert.DoesNotContain("/Customers({ID})", paths.Select(p => p.GetPathItemName()));
+ }
+ }
[Theory]
[InlineData(true, true)]