diff --git a/src/Authentication/Authentication/custom/common/GraphUri.ps1 b/src/Authentication/Authentication/custom/common/GraphUri.ps1 index 1c5a34bf51e..c52e66aac79 100644 --- a/src/Authentication/Authentication/custom/common/GraphUri.ps1 +++ b/src/Authentication/Authentication/custom/common/GraphUri.ps1 @@ -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 diff --git a/src/Authentication/Authentication/custom/common/MgCommandMetadata.json b/src/Authentication/Authentication/custom/common/MgCommandMetadata.json index 2c9c429b2b9..41114d97d04 100644 --- a/src/Authentication/Authentication/custom/common/MgCommandMetadata.json +++ b/src/Authentication/Authentication/custom/common/MgCommandMetadata.json @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 b/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 index d170fcf9511..eefdf6f7a03 100644 --- a/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 +++ b/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 @@ -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 @@ -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 @@ -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" { diff --git a/tools/PostGeneration/NewCommandMetadata.ps1 b/tools/PostGeneration/NewCommandMetadata.ps1 index c273d259b0f..9a2e375dc89 100644 --- a/tools/PostGeneration/NewCommandMetadata.ps1 +++ b/tools/PostGeneration/NewCommandMetadata.ps1 @@ -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)