Skip to content

Commit 349df82

Browse files
authored
Merge pull request #107 from microsoftgraph/namespace-segment-fix
Namespace segment fix + update to .NET 10
2 parents 8f0bb68 + b44dccb commit 349df82

5 files changed

Lines changed: 35 additions & 19 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup .NET
1717
uses: actions/setup-dotnet@v5
1818
with:
19-
dotnet-version: 9.x
19+
dotnet-version: 10.x
2020
- name: Restore dependencies
2121
run: dotnet restore
2222
- name: Build

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"request": "launch",
88
"preLaunchTask": "build",
99
// If you have changed target frameworks, make sure to update the program path.
10-
"program": "${workspaceFolder}/src/bin/Debug/net9.0/CheckCloudSupport.dll",
10+
"program": "${workspaceFolder}/src/bin/Debug/net10.0/CheckCloudSupport.dll",
1111
"args": [
1212
"--open-api",
1313
"C:/Source/Repos/msgraph-metadata/schemas/openapi/v1.0",
@@ -33,7 +33,7 @@
3333
"request": "launch",
3434
"preLaunchTask": "build",
3535
// If you have changed target frameworks, make sure to update the program path.
36-
"program": "${workspaceFolder}/src/bin/Debug/net9.0/CheckCloudSupport.dll",
36+
"program": "${workspaceFolder}/src/bin/Debug/net10.0/CheckCloudSupport.dll",
3737
"args": [
3838
"--open-api",
3939
"C:/Source/Repos/msgraph-metadata/schemas/openapi/beta",
@@ -59,7 +59,7 @@
5959
"request": "launch",
6060
"preLaunchTask": "build",
6161
// If you have changed target frameworks, make sure to update the program path.
62-
"program": "${workspaceFolder}/src/bin/Debug/net9.0/CheckCloudSupport.dll",
62+
"program": "${workspaceFolder}/src/bin/Debug/net10.0/CheckCloudSupport.dll",
6363
"args": [
6464
"--help"
6565
],

src/CheckCloudSupport.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -14,10 +14,10 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="Markdig" Version="0.44.0" />
17-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.10" />
18-
<PackageReference Include="Microsoft.OpenApi" Version="2.3.9" />
19-
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0" />
20-
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="2.3.9" />
17+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" />
18+
<PackageReference Include="Microsoft.OpenApi" Version="3.0.1" />
19+
<PackageReference Include="Microsoft.OpenApi.OData" Version="3.0.0" />
20+
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="3.0.1" />
2121
<PackageReference Include="Stylecop.Analyzers" Version="1.2.0-beta.556">
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2323
<PrivateAssets>all</PrivateAssets>

src/Extensions/OpenApiUrlTreeNodeExtensions.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,45 @@ public static class OpenApiUrlTreeNodeExtensions
3535
OpenApiUrlTreeNode result = parentNode;
3636
foreach (var segment in pathParts)
3737
{
38+
var segmentToMatch = segment;
3839
OpenApiUrlTreeNode? nextNode = null;
3940

40-
if (segment == "{id}")
41+
if (segmentToMatch == "{id}")
4142
{
4243
nextNode = result.Children.FirstOrDefault(c => c.Value.Segment.StartsWith('{') &&
4344
c.Value.Segment.EndsWith('}') && c.Value.Segment.Contains("id", StringComparison.InvariantCultureIgnoreCase)).Value;
4445
}
4546
else
4647
{
47-
var matchNodes = result.Children.Where(c => c.Value.Segment.IsEqualIgnoringCase(segment) ||
48-
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segment}") ||
49-
c.Value.Segment.IsEqualIgnoringCase($"{segment}()") ||
50-
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segment}()"));
48+
var matchNodes = result.Children.Where(c => c.Value.Segment.IsEqualIgnoringCase(segmentToMatch) ||
49+
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segmentToMatch}") ||
50+
c.Value.Segment.IsEqualIgnoringCase($"{segmentToMatch}()") ||
51+
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segmentToMatch}()"));
52+
53+
if (matchNodes?.Count() == 0 &&
54+
segmentToMatch.StartsWith("microsoft.graph", StringComparison.InvariantCultureIgnoreCase))
55+
{
56+
// OpenAPI docs sometimes leave off the "microsoft." prefix
57+
var trimmedSegment = segmentToMatch.Replace("microsoft.", string.Empty, StringComparison.InvariantCultureIgnoreCase);
58+
59+
matchNodes = result.Children.Where(c => c.Value.Segment.IsEqualIgnoringCase(trimmedSegment) ||
60+
c.Value.Segment.IsEqualIgnoringCase($"{trimmedSegment}()"));
61+
62+
if (matchNodes?.Count() >= 1)
63+
{
64+
segmentToMatch = trimmedSegment;
65+
}
66+
}
5167

5268
if (matchNodes?.Count() > 1)
5369
{
5470
var matchCount = matchNodes.Count();
5571
}
5672

57-
nextNode = result.Children.FirstOrDefault(c => c.Value.Segment.IsEqualIgnoringCase(segment) ||
58-
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segment}")).Value ??
59-
result.Children.FirstOrDefault(c => c.Value.Segment.IsEqualIgnoringCase($"{segment}()") ||
60-
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segment}()")).Value;
73+
nextNode = result.Children.FirstOrDefault(c => c.Value.Segment.IsEqualIgnoringCase(segmentToMatch) ||
74+
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segmentToMatch}")).Value ??
75+
result.Children.FirstOrDefault(c => c.Value.Segment.IsEqualIgnoringCase($"{segmentToMatch}()") ||
76+
c.Value.Segment.IsEqualIgnoringCase($"{graphNamespace}.{segmentToMatch}()")).Value;
6177
}
6278

6379
if (nextNode == null)

test/CheckCloudSupportTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

0 commit comments

Comments
 (0)