Skip to content
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
14 changes: 10 additions & 4 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -285,7 +291,7 @@ private void RetrieveNavigationSourcePaths(IEdmNavigationSource navigationSource
}
}

if (entitySet != null)
if (entitySet != null && (indexableByKey ?? true))
{
path.Pop(); // end of entity
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.6.5</Version>
<Version>1.6.6</Version>
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
<PackageReleaseNotes>
- Use annotations with path as target to dermine whether to add an operation #535
- Adds support for IndexableByKey restrictions annotations on entity sets #541
</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 @@ -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 = @"<Annotation Term=""Org.OData.Capabilities.V1.IndexableByKey"" Bool=""{0}"" />";
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)]
Expand Down