Skip to content

Commit e01ae3b

Browse files
committed
Made updates as per PR review
1 parent 73e5686 commit e01ae3b

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/Authentication/Authentication/custom/common/GraphUri.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,21 @@ function GraphUri_RemoveNamespaceFromActionFunction {
103103
$ActionFunctionFQNPattern = "\/Microsoft.Graph.(.*)$"
104104

105105
$NewUri = $Uri
106-
# Remove FQN in action/function names.
106+
# Remove FQN in paths.
107107
if ($Uri -match $ActionFunctionFQNPattern) {
108108
$MatchedUriSegment = $Matches.0
109+
$SegmentBuilder = ""
109110
# Trim nested namespace segments.
110-
$NestedNamespaceSegments = $Matches.1 -split "\."
111-
# Remove trailing '()' from functions.
112-
$LastSegment = $NestedNamespaceSegments[-1] -replace "\(\)", ""
113-
$NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), "/$LastSegment"
111+
$NestedNamespaceSegments = $Matches.1 -split "/"
112+
foreach($Segment in $NestedNamespaceSegments){
113+
# Remove microsoft.graph prefix and trailing '()' from functions.
114+
$Segment = $segment.Replace("microsoft.graph.","").Replace("()", "")
115+
# Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience
116+
$ResourceObj = $Segment.Split(".")
117+
$Segment = $ResourceObj.Count -gt 1 ? $ResourceObj[$ResourceObj.Count-1] : $Segment
118+
$SegmentBuilder += "/$Segment"
119+
}
120+
$NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
114121
}
115122

116123
return $NewUri

src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Describe "Find-MgGraphCommand Command" {
138138
$MgCommand.Command | Should -Be @("Get-MgReportSharePointActivityUserCount", "Get-MgBetaReportSharePointActivityUserCount")
139139
} | Should -Not -Throw
140140
}
141-
It 'Should find commands for uri woth /me segments' {
141+
It 'Should find commands for uri with /me segments' {
142142
{
143143
$MgCommand = Find-MgGraphCommand -Uri "/me/events/"
144144
$MgCommand | Should -HaveCount 4
@@ -150,7 +150,7 @@ Describe "Find-MgGraphCommand Command" {
150150
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent")
151151
} | Should -Not -Throw
152152
}
153-
It 'Should find commands for uri woth /me segments' {
153+
It 'Should find commands for uri with /me segments' {
154154
{
155155
$MgCommand = Find-MgGraphCommand -Uri "https://graph.microsoft.com/v1.0/me/events/"
156156
$MgCommand | Should -HaveCount 4
@@ -162,6 +162,18 @@ Describe "Find-MgGraphCommand Command" {
162162
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent")
163163
} | Should -Not -Throw
164164
}
165+
It 'Should find commands for uri with Microsoft.Graph prefix in nested segments' {
166+
{
167+
$MgCommand = Find-MgGraphCommand -Uri "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/microsoft.graph.externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/microsoft.graph.onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders"
168+
$MgCommand | Should -HaveCount 1
169+
$MgCommand.Command | Select-Object -Unique | should -HaveCount 1
170+
$MgCommand.Method | Select-Object -Unique | should -HaveCount 1
171+
$MgCommand.APIVersion | Select-Object -Unique | should -HaveCount 1
172+
$MgCommand.Variants | Select-Object -Unique | should -HaveCount 1
173+
$MgCommand.URI | Select-Object -Unique | Should -Be "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders"
174+
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("Get-MgBetaIdentityAuthenticationEventFlowAsOnAuthenticationMethodLoadStartExternalUserSelfServiceSignUpIdentityProvider")
175+
} | Should -Not -Throw
176+
}
165177
}
166178

167179
Context "FindByCommand" {

tools/PostGeneration/NewCommandMetadata.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ $ApiVersion | ForEach-Object {
6464
$SegmentBuilder = ""
6565
# Trim nested namespace segments.
6666
$NestedNamespaceSegments = $Matches.1 -split "/"
67-
# Remove microsoft.graph prefix and remove trailing '()' from functions.
68-
foreach($segment in $NestedNamespaceSegments){
69-
$segment = $segment.Replace("microsoft.graph.","").Replace("()", "")
70-
$SegmentBuilder += "/$segment"
67+
foreach($Segment in $NestedNamespaceSegments){
68+
# Remove microsoft.graph prefix and trailing '()' from functions.
69+
$Segment = $segment.Replace("microsoft.graph.","").Replace("()", "")
70+
# Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience
71+
$ResourceObj = $Segment.Split(".")
72+
$Segment = $ResourceObj.Count -gt 1 ? $ResourceObj[$ResourceObj.Count-1] : $Segment
73+
$SegmentBuilder += "/$Segment"
7174
}
7275
$Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
7376
}

0 commit comments

Comments
 (0)