Skip to content

Commit

Permalink
Merge pull request #2492 from microsoftgraph/2453-missing-ms-learn-ap…
Browse files Browse the repository at this point in the history
…i-docs-examples-for-powershell-commands

Rectifies metadata path information for paths containing Microsoft.Graph prefix in nested segments.
  • Loading branch information
timayabi2020 authored Jan 8, 2024
2 parents 0a1566f + 78366a8 commit 1ebab54
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
17 changes: 12 additions & 5 deletions src/Authentication/Authentication/custom/common/GraphUri.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,21 @@ function GraphUri_RemoveNamespaceFromActionFunction {
$ActionFunctionFQNPattern = "\/Microsoft.Graph.(.*)$"

$NewUri = $Uri
# Remove FQN in action/function names.
# Remove FQN in paths.
if ($Uri -match $ActionFunctionFQNPattern) {
$MatchedUriSegment = $Matches.0
$SegmentBuilder = ""
# Trim nested namespace segments.
$NestedNamespaceSegments = $Matches.1 -split "\."
# Remove trailing '()' from functions.
$LastSegment = $NestedNamespaceSegments[-1] -replace "\(\)", ""
$NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), "/$LastSegment"
$NestedNamespaceSegments = $Matches.1 -split "/"
foreach($Segment in $NestedNamespaceSegments){
# Remove microsoft.graph prefix and trailing '()' from functions.
$Segment = $segment.Replace("microsoft.graph.","").Replace("()", "")
# Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience
$ResourceObj = $Segment.Split(".")
$Segment = $ResourceObj[$ResourceObj.Count-1]
$SegmentBuilder += "/$Segment"
}
$NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
}

return $NewUri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95132,7 +95132,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders",
"OutputType": "IMicrosoftGraphIdentityProviderBase",
"Method": "GET",
"ApiVersion": "beta",
Expand Down Expand Up @@ -95208,7 +95208,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"OutputType": null,
"Method": "GET",
"ApiVersion": "beta",
Expand All @@ -95220,7 +95220,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count",
"OutputType": null,
"Method": "GET",
"ApiVersion": "beta",
Expand Down Expand Up @@ -305344,7 +305344,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"OutputType": null,
"Method": "POST",
"ApiVersion": "beta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Describe "Find-MgGraphCommand Command" {
$MgCommand.Command | Should -Be @("Get-MgReportSharePointActivityUserCount", "Get-MgBetaReportSharePointActivityUserCount")
} | Should -Not -Throw
}
It 'Should find commands for uri woth /me segments' {
It 'Should find commands for uri with /me segments' {
{
$MgCommand = Find-MgGraphCommand -Uri "/me/events/"
$MgCommand | Should -HaveCount 4
Expand All @@ -150,7 +150,7 @@ Describe "Find-MgGraphCommand Command" {
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent")
} | Should -Not -Throw
}
It 'Should find commands for uri woth /me segments' {
It 'Should find commands for uri with /me segments' {
{
$MgCommand = Find-MgGraphCommand -Uri "https://graph.microsoft.com/v1.0/me/events/"
$MgCommand | Should -HaveCount 4
Expand All @@ -162,6 +162,18 @@ Describe "Find-MgGraphCommand Command" {
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent")
} | Should -Not -Throw
}
It 'Should find commands for uri with Microsoft.Graph prefix in nested segments' {
{
$MgCommand = Find-MgGraphCommand -Uri "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/microsoft.graph.externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/microsoft.graph.onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders"
$MgCommand | Should -HaveCount 1
$MgCommand.Command | Select-Object -Unique | should -HaveCount 1
$MgCommand.Method | Select-Object -Unique | should -HaveCount 1
$MgCommand.APIVersion | Select-Object -Unique | should -HaveCount 1
$MgCommand.Variants | Select-Object -Unique | should -HaveCount 1
$MgCommand.URI | Select-Object -Unique | Should -Be "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders"
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("Get-MgBetaIdentityAuthenticationEventFlowAsOnAuthenticationMethodLoadStartExternalUserSelfServiceSignUpIdentityProvider")
} | Should -Not -Throw
}
}

Context "FindByCommand" {
Expand Down
18 changes: 12 additions & 6 deletions tools/PostGeneration/NewCommandMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ $ApiVersion | ForEach-Object {
$Method = $Matches.2
$Uri = $Matches.3

# Remove FQN in action/function names.
# Remove FQN in paths.
if ($Uri -match $ActionFunctionFQNPattern) {
$MatchedUriSegment = $Matches.0
$SegmentBuilder = ""
# Trim nested namespace segments.
$NestedNamespaceSegments = $Matches.1 -split "\."
# Remove trailing '()' from functions.
$LastSegment = $NestedNamespaceSegments[-1] -replace "\(\)", ""
$Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), "/$LastSegment"
$NestedNamespaceSegments = $Matches.1 -split "/"
foreach($Segment in $NestedNamespaceSegments){
# Remove microsoft.graph prefix and trailing '()' from functions.
$Segment = $segment.Replace("microsoft.graph.","").Replace("()", "")
# Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience
$ResourceObj = $Segment.Split(".")
$Segment = $ResourceObj[$ResourceObj.Count-1]
$SegmentBuilder += "/$Segment"
}
$Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
}

$MappingValue = @{
Command = $CommandName
Variants = [System.Collections.ArrayList]@($VariantName)
Expand Down

0 comments on commit 1ebab54

Please sign in to comment.