Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@
<EnlistmentRoot Condition="'$(EnlistmentRoot)' == ''">$(MSBuildThisFileDirectory.TrimEnd('\'))</EnlistmentRoot>
</PropertyGroup>

<Import Project="$(EnlistmentRoot)\tool\Build.props" />

</Project>
15 changes: 2 additions & 13 deletions Microsoft.OpenApi.OData.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.OData.Reader", "src\Microsoft.OpenApi.OData.Reader\Microsoft.OpenAPI.OData.Reader.csproj", "{FF3ACD93-19E0-486C-9C0F-FA1C2E7FC8C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenAPI.OData.Reader", "src\Microsoft.OpenApi.OData.Reader\Microsoft.OpenAPI.OData.Reader.csproj", "{FF3ACD93-19E0-486C-9C0F-FA1C2E7FC8C2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.OData.Reader.Tests", "test\Microsoft.OpenAPI.OData.Reader.Tests\Microsoft.OpenAPI.OData.Reader.Tests.csproj", "{90A98718-75EB-4E2B-A51E-66ACF66F15B4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenAPI.OData.Reader.Tests", "test\Microsoft.OpenAPI.OData.Reader.Tests\Microsoft.OpenAPI.OData.Reader.Tests.csproj", "{90A98718-75EB-4E2B-A51E-66ACF66F15B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OoasUtil", "src\OoasUtil\OoasUtil.csproj", "{2D06C660-B550-432C-8062-D4070F7C371F}"
EndProject
Expand All @@ -16,10 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tool", "tool", "{DE8F8E75-A119-4CF3-AFDD-4132B55DAE76}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateDocs", "tool\UpdateDocs\UpdateDocs.csproj", "{AAC31ECB-05F9-444A-9B86-42ECD50AA468}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,18 +38,11 @@ Global
{79B190E8-EDB0-4C03-8FD8-EB48E4807CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79B190E8-EDB0-4C03-8FD8-EB48E4807CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79B190E8-EDB0-4C03-8FD8-EB48E4807CFB}.Release|Any CPU.Build.0 = Release|Any CPU
{AAC31ECB-05F9-444A-9B86-42ECD50AA468}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAC31ECB-05F9-444A-9B86-42ECD50AA468}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAC31ECB-05F9-444A-9B86-42ECD50AA468}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAC31ECB-05F9-444A-9B86-42ECD50AA468}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AE22713-F94E-45CA-81F4-0806CA195B69}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AAC31ECB-05F9-444A-9B86-42ECD50AA468} = {DE8F8E75-A119-4CF3-AFDD-4132B55DAE76}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
/// <param name="pathItem">The value to be added.</param>
/// <returns>true when the key and/or value are successfully added/updated to the dictionary;
/// false when the dictionary already contains the specified key, and nothing gets added.</returns>
internal static bool TryAddPath(this IDictionary<string, OpenApiPathItem> pathItems,

Check failure on line 335 in src/Microsoft.OpenApi.OData.Reader/Common/Utils.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=microsoft_OpenAPI.NET.OData&issues=AZ2JLkn-pWqvzbqKF_il&open=AZ2JLkn-pWqvzbqKF_il&pullRequest=809
ODataContext context,
ODataPath path,
OpenApiPathItem pathItem)
Expand Down Expand Up @@ -372,6 +372,13 @@

if (derivedTypes?.Any() ?? false)
{
if (boundEntityType != null && boundEntityType == operationEntityType)
{
// The operation's binding type exactly matches the entity set's type,
// so this is a more specific overload than whatever was added first.
pathItems[pathName] = pathItem;
return true;
}
if (boundEntityType != null && !derivedTypes.Contains(boundEntityType))
{
Debug.WriteLine($"Duplicate paths present but entity type of binding parameter '{operationEntityType}' " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Tests;
using Xunit;

Expand Down Expand Up @@ -921,6 +922,76 @@ private static IEdmModel GetNavPropModel(string annotation)
return GetEdmModel(template);
}

[Fact]
public void GetPathsForDerivedTypeDeltaFunctionUsesCorrectReturnType()
{
// Arrange – mirrors the Graph scenario:
// directoryObject (base) has delta with RequiresExplicitBinding
// servicePrincipal (derived) has its own delta
// agentIdentity (derived from servicePrincipal) causes servicePrincipal to have derived types
// Bug: TryAddPath kept the base-type delta for /servicePrincipals/delta() because
// servicePrincipal has derived types.
string csdl = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
<edmx:DataServices>
<Schema Namespace=""NS"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<EntityType Name=""directoryObject"">
<Key>
<PropertyRef Name=""id"" />
</Key>
<Property Name=""id"" Type=""Edm.String"" Nullable=""false"" />
</EntityType>
<EntityType Name=""servicePrincipal"" BaseType=""NS.directoryObject"">
<Property Name=""appId"" Type=""Edm.String"" />
</EntityType>
<EntityType Name=""agentIdentity"" BaseType=""NS.servicePrincipal"">
<Property Name=""blueprintId"" Type=""Edm.String"" />
</EntityType>
<Function Name=""delta"" IsBound=""true"">
<Parameter Name=""bindingParameter"" Type=""Collection(NS.directoryObject)"" />
<ReturnType Type=""Collection(NS.directoryObject)"" />
<Annotation Term=""Org.OData.Core.V1.RequiresExplicitBinding"" />
</Function>
<Function Name=""delta"" IsBound=""true"">
<Parameter Name=""bindingParameter"" Type=""Collection(NS.servicePrincipal)"" />
<ReturnType Type=""Collection(NS.servicePrincipal)"" />
</Function>
<EntityContainer Name=""Default"">
<EntitySet Name=""directoryObjects"" EntityType=""NS.directoryObject"" />
<EntitySet Name=""servicePrincipals"" EntityType=""NS.servicePrincipal"" />
</EntityContainer>
<Annotations Target=""NS.directoryObject"">
<Annotation Term=""Org.OData.Core.V1.ExplicitOperationBindings"">
<Collection>
<String>NS.delta</String>
</Collection>
</Annotation>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>";

bool result = CsdlReader.TryParse(XElement.Parse(csdl).CreateReader(), out IEdmModel model, out _);
Assert.True(result);

var settings = new OpenApiConvertSettings();
OpenApiDocument doc = model.ConvertToOpenApi(settings);

// Assert – the /servicePrincipals/NS.delta() path should exist and its response
// should reference NS.servicePrincipal, not NS.directoryObject
Assert.True(doc.Paths.ContainsKey("/servicePrincipals/NS.delta()"),
$"Expected path not found. Available: {string.Join(", ", doc.Paths.Keys)}");

var pathItem = doc.Paths["/servicePrincipals/NS.delta()"];
var getOp = pathItem.Operations[OperationType.Get];
Assert.NotNull(getOp);

// The response schema title should reference servicePrincipal, not directoryObject
var responseKey = getOp.Responses.Keys.First();
var response = getOp.Responses[responseKey];
var schema = response.Content["application/json"].Schema;
Assert.Contains("servicePrincipal", schema.Title);
Comment thread
gavinbarron marked this conversation as resolved.
}

private static IEdmModel GetEdmModel(string schema)
{
bool parsed = SchemaReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(schema)) }, out IEdmModel parsedModel, out IEnumerable<EdmError> errors);
Expand Down
105 changes: 0 additions & 105 deletions tool/After.Common.targets

This file was deleted.

27 changes: 0 additions & 27 deletions tool/Before.Common.targets

This file was deleted.

30 changes: 0 additions & 30 deletions tool/Build.props

This file was deleted.

14 changes: 0 additions & 14 deletions tool/GetNugetPackageMetadata.proj

This file was deleted.

34 changes: 0 additions & 34 deletions tool/PoliCheck/RunPoliCheck.ps1

This file was deleted.

Loading
Loading