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
7 changes: 4 additions & 3 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,17 @@ private void RetrieveNavigationPropertyPaths(
visitedNavigationProperties.Push(navPropFullyQualifiedName);

// Check whether a collection-valued navigation property should be indexed by key value(s).
// Find indexability annotation annotated directly via NavigationPropertyRestriction.
bool? annotatedIndexability = _model.GetBoolean(navigationProperty, CapabilitiesConstants.IndexableByKey);
bool indexableByKey = true;

if (restriction?.IndexableByKey != null)
{
indexableByKey = (bool)restriction.IndexableByKey;
}
else if (_model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(navigationProperty, CapabilitiesConstants.IndexableByKey).FirstOrDefault() is IEdmVocabularyAnnotation indexabilityAnnotation && indexabilityAnnotation.Value is IEdmBooleanValue booleanValue)
else if (annotatedIndexability != null)
{
// Find indexability annotation annotated directly via NavigationPropertyRestriction
indexableByKey = booleanValue.Value;
indexableByKey = annotatedIndexability.Value;
}

if (indexableByKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// ------------------------------------------------------------
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
Expand Down Expand Up @@ -158,6 +159,8 @@ protected override void SetParameters(OpenApiOperation operation)
}
}
}

AppendSystemQueryOptions(function, operation);
}
}

Expand Down Expand Up @@ -200,6 +203,57 @@ protected override void AppendCustomParameters(OpenApiOperation operation)
}
}

private void AppendSystemQueryOptions(IEdmFunction function, OpenApiOperation operation)
{
if (function.ReturnType.IsCollection())
{
// $top
if (Context.CreateTop(function) is OpenApiParameter topParameter)
{
operation.Parameters.AppendParameter(topParameter);
}

// $skip
if (Context.CreateSkip(function) is OpenApiParameter skipParameter)
{
operation.Parameters.AppendParameter(skipParameter);
}

// $search
if (Context.CreateSearch(function) is OpenApiParameter searchParameter)
{
operation.Parameters.AppendParameter(searchParameter);
}

// $filter
if (Context.CreateFilter(function) is OpenApiParameter filterParameter)
{
operation.Parameters.AppendParameter(filterParameter);
}

// $count
if (Context.CreateCount(function) is OpenApiParameter countParameter)
{
operation.Parameters.AppendParameter(countParameter);
}

if (function.ReturnType?.Definition?.AsElementType() is IEdmEntityType entityType)
{
// $select
if (Context.CreateSelect(function, entityType) is OpenApiParameter selectParameter)
{
operation.Parameters.AppendParameter(selectParameter);
}

// $orderby
if (Context.CreateOrderBy(function, entityType) is OpenApiParameter orderbyParameter)
{
operation.Parameters.AppendParameter(orderbyParameter);
}
}
}
}

/// <inheritdoc/>
protected override void SetCustomLinkRelType()
{
Expand All @@ -211,9 +265,8 @@ protected override void SetCustomLinkRelType()
}
}


/// <inheritdoc/>
protected override void SetExternalDocs(OpenApiOperation operation)
/// <inheritdoc/>
protected override void SetExternalDocs(OpenApiOperation operation)
{
if (Context.Settings.ShowExternalDocs && Context.Model.GetLinkRecord(EdmOperation, CustomLinkRel) is Link externalDocs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public void CreateOperationForEdmFunctionReturnsCorrectOperationHierarchicalClas
Assert.Equal($"{entitySetName}.Functions", tag.Name);

Assert.NotNull(operation.Parameters);
Assert.Equal(1, operation.Parameters.Count);
Assert.Equal(new string[] { "id" }, operation.Parameters.Select(p => p.Name));
Assert.Equal(6, operation.Parameters.Count); // id, top, skip, count, search, filter
Assert.Contains("id", operation.Parameters.Select(x => x.Name).FirstOrDefault());

Assert.Null(operation.RequestBody);

Expand Down
Loading