Skip to content

Commit 1ebab54

Browse files
authored
Merge pull request #2492 from microsoftgraph/2453-missing-ms-learn-api-docs-examples-for-powershell-commands
Rectifies metadata path information for paths containing Microsoft.Graph prefix in nested segments.
2 parents 0a1566f + 78366a8 commit 1ebab54

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
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[$ResourceObj.Count-1]
118+
$SegmentBuilder += "/$Segment"
119+
}
120+
$NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
114121
}
115122

116123
return $NewUri

src/Authentication/Authentication/custom/common/MgCommandMetadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95132,7 +95132,7 @@
9513295132
},
9513395133
{
9513495134
"Module": "Beta.Identity.SignIns",
95135-
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders",
95135+
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders",
9513695136
"OutputType": "IMicrosoftGraphIdentityProviderBase",
9513795137
"Method": "GET",
9513895138
"ApiVersion": "beta",
@@ -95208,7 +95208,7 @@
9520895208
},
9520995209
{
9521095210
"Module": "Beta.Identity.SignIns",
95211-
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
95211+
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
9521295212
"OutputType": null,
9521395213
"Method": "GET",
9521495214
"ApiVersion": "beta",
@@ -95220,7 +95220,7 @@
9522095220
},
9522195221
{
9522295222
"Module": "Beta.Identity.SignIns",
95223-
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count",
95223+
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count",
9522495224
"OutputType": null,
9522595225
"Method": "GET",
9522695226
"ApiVersion": "beta",
@@ -305344,7 +305344,7 @@
305344305344
},
305345305345
{
305346305346
"Module": "Beta.Identity.SignIns",
305347-
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
305347+
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
305348305348
"OutputType": null,
305349305349
"Method": "POST",
305350305350
"ApiVersion": "beta",

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: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ $ApiVersion | ForEach-Object {
5858
$Method = $Matches.2
5959
$Uri = $Matches.3
6060

61-
# Remove FQN in action/function names.
61+
# Remove FQN in paths.
6262
if ($Uri -match $ActionFunctionFQNPattern) {
6363
$MatchedUriSegment = $Matches.0
64+
$SegmentBuilder = ""
6465
# Trim nested namespace segments.
65-
$NestedNamespaceSegments = $Matches.1 -split "\."
66-
# Remove trailing '()' from functions.
67-
$LastSegment = $NestedNamespaceSegments[-1] -replace "\(\)", ""
68-
$Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), "/$LastSegment"
66+
$NestedNamespaceSegments = $Matches.1 -split "/"
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[$ResourceObj.Count-1]
73+
$SegmentBuilder += "/$Segment"
74+
}
75+
$Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
6976
}
70-
7177
$MappingValue = @{
7278
Command = $CommandName
7379
Variants = [System.Collections.ArrayList]@($VariantName)

0 commit comments

Comments
 (0)