From 74e3fd919db9567bf4c618c0ebd8cf95f6f91b2f Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Tue, 18 Apr 2023 01:01:38 +0300 Subject: [PATCH 01/10] Updated script to improve on example imports and updates --- .../HandWrittenExamplesByContentDeveloper.csv | 105 +++++++++++++++++ tools/ExamplesGenerator.ps1 | 107 +++++++++++++----- 2 files changed, 186 insertions(+), 26 deletions(-) create mode 100644 examplesreport/HandWrittenExamplesByContentDeveloper.csv diff --git a/examplesreport/HandWrittenExamplesByContentDeveloper.csv b/examplesreport/HandWrittenExamplesByContentDeveloper.csv new file mode 100644 index 00000000000..76fa6991872 --- /dev/null +++ b/examplesreport/HandWrittenExamplesByContentDeveloper.csv @@ -0,0 +1,105 @@ +CmdletName,ModuleName,ExampleCountV1,ExampleCountBeta +Add-MgApplicationPassword,Microsoft.Graph.Applications,2,2 +Get-MgApplication,Microsoft.Graph.Applications,5,5 +Get-MgGroupAppRoleAssignment,Microsoft.Graph.Applications,1,1 +Get-MgServicePrincipal,Microsoft.Graph.Applications,5,5 +Get-MgServicePrincipalAppRoleAssignment,Microsoft.Graph.Applications,1,1 +Get-MgServicePrincipalOwner,Microsoft.Graph.Applications,1,1 +Get-MgUserAppRoleAssignment,Microsoft.Graph.Applications,1,1 +New-MgApplication,Microsoft.Graph.Applications,1,1 +New-MgApplicationOwnerByRef,Microsoft.Graph.Applications,1,1 +New-MgGroupAppRoleAssignment,Microsoft.Graph.Applications,1,1 +New-MgServicePrincipal,Microsoft.Graph.Applications,1,1 +New-MgServicePrincipalOwnerByRef,Microsoft.Graph.Applications,1,1 +New-MgUserAppRoleAssignment,Microsoft.Graph.Applications,1,1 +Remove-MgApplication,Microsoft.Graph.Applications,1,1 +Remove-MgServicePrincipalAppRoleAssignment,Microsoft.Graph.Applications,1,1 +Remove-MgUserAppRoleAssignment,Microsoft.Graph.Applications,1,1 +Update-MgApplication,Microsoft.Graph.Applications,1,1 +Update-MgServicePrincipal,Microsoft.Graph.Applications,1,1 +Get-MgRoleManagementDirectoryRoleAssignmentSchedule,Microsoft.Graph.DeviceManagement.Enrolment,0,2 +Get-MgRoleManagementDirectoryRoleAssignmentScheduleInstance,Microsoft.Graph.DeviceManagement.Enrolment,0,2 +Get-MgRoleManagementDirectoryRoleAssignmentScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,2 +Get-MgRoleManagementDirectoryRoleEligibilitySchedule,Microsoft.Graph.DeviceManagement.Enrolment,0,2 +Get-MgRoleManagementDirectoryRoleEligibilityScheduleInstance,Microsoft.Graph.DeviceManagement.Enrolment,0,2 +Get-MgRoleManagementDirectoryRoleEligibilityScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,2 +New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,3 +New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,3 +Get-MgGroup,Microsoft.Graph.Groups,5,5 +Get-MgGroupMember,Microsoft.Graph.Groups,1,1 +Get-MgGroupOwner,Microsoft.Graph.Groups,1,1 +New-MgGroup,Microsoft.Graph.Groups,1,1 +New-MgGroupMember,Microsoft.Graph.Groups,1,1 +New-MgGroupOwnerByRef,Microsoft.Graph.Groups,1,1 +Remove-MgGroup,Microsoft.Graph.Groups,1,1 +Update-MgGroup,Microsoft.Graph.Groups,1,1 +Get-MgContact,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Get-MgDirectoryDeletedItem,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Get-MgDirectoryRole,Microsoft.Graph.Identity.DirectoryManagement,2,2 +Get-MgDirectoryRoleMember,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Get-MgDomain,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Get-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Get-MgSubscribedSku,Microsoft.Graph.Identity.DirectoryManagement,1,1 +New-MgDirectoryRoleMemberByRef,Microsoft.Graph.Identity.DirectoryManagement,1,1 +New-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Remove-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Update-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 +Get-MgAdministrativeUnit,Microsoft.Graph.Identity.DirectoryManagement,0,1 +Remove-MgAdministrativeUnit,Microsoft.Graph.Identity.DirectoryManagement,0,1 +Update-MgAdministrativeUnit,Microsoft.Graph.Identity.DirectoryManagement,0,1 +Get-MgEntitlementManagementAccessPackage,Microsoft.Graph.Identity.Governance,2,2 +Get-MgEntitlementManagementAccessPackageAssignmentPolicy,Microsoft.Graph.Identity.Governance,0,1 +Get-MgEntitlementManagementAccessPackageCatalog,Microsoft.Graph.Identity.Governance,0,2 +Get-MgEntitlementManagementSetting,Microsoft.Graph.Identity.Governance,1,1 +New-MgEntitlementManagementAccessPackage,Microsoft.Graph.Identity.Governance,1,1 +New-MgEntitlementManagementAccessPackageAssignmentPolicy,Microsoft.Graph.Identity.Governance,0,1 +Remove-MgEntitlementManagementAccessPackage,Microsoft.Graph.Identity.Governance,1,1 +Remove-MgEntitlementManagementAccessPackageAssignmentPolicy,Microsoft.Graph.Identity.Governance,0,1 +Get-MgEntitlementManagementAccessPackageAssignmentRequest,Microsoft.Graph.Identity.Governance,0,2 +Get-MgEntitlementManagementAccessPackageCatalogAccessPackageResource,Microsoft.Graph.Identity.Governance,0,2 +Get-MgEntitlementManagementAccessPackageCatalogAccessPackageResourceRole,Microsoft.Graph.Identity.Governance,0,2 +Get-MgEntitlementManagementAccessPackageResourceRequest,Microsoft.Graph.Identity.Governance,0,2 +New-MgEntitlementManagementAccessPackageAssignmentRequest,Microsoft.Graph.Identity.Governance,0,2 +New-MgEntitlementManagementAccessPackageResourceRequest,Microsoft.Graph.Identity.Governance,0,1 +New-MgEntitlementManagementAccessPackageResourceRoleScope,Microsoft.Graph.Identity.Governance,0,1 +Confirm-MgRiskyUserCompromised,Microsoft.Graph.Identity.SignIns,0,1 +Get-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,2,2 +Get-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,2,2 +Get-MgRiskDetection,Microsoft.Graph.Identity.SignIns,0,4 +Get-MgRiskyUser,Microsoft.Graph.Identity.SignIns,0,2 +Get-MgRiskyUserHistory,Microsoft.Graph.Identity.SignIns,0,2 +New-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,2,2 +New-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,2,2 +Remove-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,1,1 +Remove-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,1,1 +Update-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,1,1 +Update-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,1,1 +Get-MgUser,Microsoft.Graph.Users,6,6 +Get-MgUserCreatedObject,Microsoft.Graph.Users,1,1 +Get-MgUserDirectReport,Microsoft.Graph.Users,1,1 +Get-MgUserLicenseDetail,Microsoft.Graph.Users,1,1 +Get-MgUserManager,Microsoft.Graph.Users,1,1 +Get-MgUserPhoto,Microsoft.Graph.Users,1,1 +New-MgUser,Microsoft.Graph.Users,1,1 +Remove-MgUser,Microsoft.Graph.Users,2,2 +Set-MgUserManagerByRef,Microsoft.Graph.Users,1,1 +Update-MgUser,Microsoft.Graph.Users,1,1 +Set-MgUserLicense,Microsoft.Graph.Users.Actions,6,6 +New-MgInvitation,Microsoft.Graph.Identity.SignIns,2,0 +Get-MgUserOauth2PermissionGrant,Microsoft.Graph.Users,1,0 +Remove-MgUserManagerByRef,Microsoft.Graph.Users,1,0 +Get-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,2,2 +Get-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 +Get-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 +New-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,1,1 +New-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 +New-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 +Remove-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,1,1 +Remove-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 +Remove-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 +Update-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,1,1 +Update-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 +Update-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 +New-MgEntitlementManagementAssignmentPolicy,Microsoft.Graph.Identity.Governance,1,0 +Get-MgEntitlementManagementCatalog,Microsoft.Graph.Identity.Governance,2,0 +Remove-MgEntitlementManagementAssignmentPolicy,Microsoft.Graph.Identity.Governance,1,0 diff --git a/tools/ExamplesGenerator.ps1 b/tools/ExamplesGenerator.ps1 index f3148c718e9..c66674e9348 100644 --- a/tools/ExamplesGenerator.ps1 +++ b/tools/ExamplesGenerator.ps1 @@ -2,7 +2,13 @@ # Licensed under the MIT License. Param( $ModulesToGenerate = @(), - [string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "..\config\ModulesMapping.jsonc") + $HandWrittenCommands = @(), + [hashtable]$V1CommandList= @{}, + [hashtable]$BetaCommandList= @{}, + [string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "..\config\ModulesMapping.jsonc"), + [string] $HandWrittenDocPath = (Join-Path $PSScriptRoot "..\examplesreport\HandWrittenExamplesByContentDeveloper.csv"), + [string] $ExamplesToBeReviewed = (Join-Path $PSScriptRoot "..\examplesreport\ExamplesToBeReviewed.csv"), + $MetaDataJsonFile = (Join-Path $PSScriptRoot "../src/Authentication/Authentication/custom/common/MgCommandMetadata.json") ) function Start-Generator { Param( @@ -85,23 +91,18 @@ function Get-Files { if ($ModuleManifestFileContent | Select-String -pattern $Command) { #Extract URI path - $Uripaths = Find-MgGraphCommand -Command $Command $UriPath = $null - if (-not([string]::IsNullOrEmpty($Uripaths))) { - if ($Uripaths.APIVersion.Contains($GraphProfile)) { - if ($Uripaths.Length -gt 1) { - $UriPath = $UriPaths.URI[0].ToString() - } - else { - $UriPath = $UriPaths.URI.ToString() - } - } - - if ($UriPath) { - $Method = $UriPaths.Method - Get-ExternalDocsUrl -GraphProfile $GraphProfile -Url -UriPath $UriPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method -Module $Module - } + if($GraphProfile -eq "beta"){ + $UriPath = $BetaCommandList[$Command] + }else{ + $UriPath = $V1CommandList[$Command] } + + if ($UriPath) { + $Method = $UriPaths.Method + Get-ExternalDocsUrl -GraphProfile $GraphProfile -Url -UriPath $UriPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method -Module $Module + } + } } @@ -135,7 +136,7 @@ function Get-ExternalDocsUrl { if (-not([string]::IsNullOrEmpty($ManualExternalDocsUrl))) { - Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ManualExternalDocsUrl -Command $Command -GraphProfilePath $GraphProfilePath + Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ManualExternalDocsUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath } } @@ -177,7 +178,7 @@ function Get-ExternalDocsUrl { $externalDocUrl = $path[$UriPath].put.externalDocs.url } if (-not([string]::IsNullOrEmpty($externalDocUrl))) { - Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $externalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath + Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $externalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath } } @@ -194,6 +195,7 @@ function Start-WebScrapping { [string] $ExternalDocUrl = "https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=powershell", [ValidateNotNullOrEmpty()] [string] $Command = "Get-MgUser", + [string] $UriPath, [string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0") ) $ExampleFile = "$GraphProfilePath/$Command.md" @@ -225,7 +227,7 @@ function Start-WebScrapping { } - Update-ExampleFile -GraphProfile $GraphProfile -HeaderList $HeaderList -ExampleList $ExampleList -ExampleFile $ExampleFile -Description $Description + Update-ExampleFile -GraphProfile $GraphProfile -HeaderList $HeaderList -ExampleList $ExampleList -ExampleFile $ExampleFile -Description $Description -Command $Command -ExternalDocUrl $ExternalDocUrl -UriPath $UriPath } function Update-ExampleFile { @@ -235,42 +237,50 @@ function Update-ExampleFile { [System.Collections.ArrayList] $HeaderList, [System.Collections.ArrayList] $ExampleList, [string] $ExampleFile, - [string] $Description + [string] $UriPath, + [string] $Description, + [string] $Command = "Get-MgUser", + [ValidateNotNullOrEmpty()] + [string] $ExternalDocUrl = "https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=powershell" ) $Content = Get-Content -Path $ExampleFile $SearchText = "{{ Add description here }}" + $SearchTextForNewImports = "{{ Add description here }}" $ReplaceEverything = $False if ($HeaderList.Count -eq 0) { for ($d = 0; $d -lt $ExampleList.Count; $d++) { $sum = $d + 1 - $HeaderList.Add("Example " + $sum + ": Code snippet".Trim()) + $HL = $HeaderList.Add("Example " + $sum + ": Code snippet".Trim()) } } if ($HeaderList.Count -ne $ExampleList.Count) { $HeaderList.Clear() for ($d = 0; $d -lt $ExampleList.Count; $d++) { $sum = $d + 1 - $HeaderList.Add("Example " + $sum + ": Code snippet".Trim()) + $H = $HeaderList.Add("Example " + $sum + ": Code snippet".Trim()) } } - if ($Content | Select-String -pattern $SearchText) { + if (($Content | Select-String -pattern $SearchText) -or ($Content | Select-String -pattern $SearchTextForNewImports)) { $ReplaceEverything = $True - #Start-Sleep 5 - } $headCount = $HeaderList.Count - $exampleCount = $ExampleList.Count + $exampleCount = $ExampleList.Count + $wrongExamplesCount = 0; if ($ReplaceEverything -and $exampleCount -gt 0 -and $headCount -eq $exampleCount) { Clear-Content $ExampleFile -Force for ($d = 0; $d -lt $headerList.Count; $d++) { $codeValue = $exampleList[$d].Trim() + if($codeValue.Contains($Command)){ $titleValue = "### " + $headerList[$d].Trim() $code = "``````powershell`r$codeValue`r`n``````" $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" Add-Content -Path $ExampleFile -Value $totalText + }else{ + $wrongExamplesCount++ + } } git config --global user.email "timwamalwa@gmail.com" git config --global user.name "Timothy Wamalwa" @@ -287,7 +297,52 @@ function Update-ExampleFile { } + if($wrongExamplesCount -gt 0){ + Write-Host "Logging this as an anormally Command " $Command "External Docs" $ExternalDocUrl + $DefaultBoilerPlate = "### Example 1: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n### Example 2: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n" + + Add-Content -Path $ExampleFile -Value $DefaultBoilerPlate.Trim() + #Log api path api version and equivalent external doc url giving wron examples + + #Create file if it doesn't exist + if (-not (Test-Path $ExamplesToBeReviewed)) { + "Command, ExternalDocsUrl, ApiVersion, OpenApiPath" | Out-File -FilePath $ExamplesToBeReviewed -Encoding ASCII + } + + $File = Get-Content $ExamplesToBeReviewed + $containsWord = $File | % { $_ -match "$Command, $ExternalDocUrl, $GraphProfile, $UriPath" } + if ($containsWord -contains $true) { + #Skip adding to csv + } + else { + "$Command, $ExternalDocUrl, $GraphProfile, $UriPath" | Out-File -FilePath $ExamplesToBeReviewed -Append -Encoding ASCII + } + } + +} +Import-Csv $HandWrittenDocPath | +ForEach-Object{ + $HandWrittenCommands += $_.CmdletName +} +$JsonContent = Get-Content -Path $MetaDataJsonFile +$DeserializedContent = $JsonContent | ConvertFrom-Json +foreach($Data in $DeserializedContent) +{ + if($Data.ApiVersion -eq "beta") + { + + if((-not($Data.Variants[0].Contains("List")))){ + $Beta = $BetaCommandList.Add($Data.Command, $Data.Uri) + } + } + + if($Data.ApiVersion -eq "v1.0") + { + if((-not($Data.Variants[0].Contains("List")))){ + $V1 = $V1CommandList.Add($Data.Command, $Data.Uri) + } + } } if (!(Get-Module "powershell-yaml" -ListAvailable -ErrorAction SilentlyContinue)) { Install-Module "powershell-yaml" -AcceptLicense -Scope CurrentUser -Force From 03d13738b6dc47070b56b92379eceacddb28bd5f Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Tue, 18 Apr 2023 01:33:56 +0300 Subject: [PATCH 02/10] Added check for handwritten commands --- config/ModulesMapping.jsonc | 76 ++++++++++++++++++------------------- tools/ExamplesGenerator.ps1 | 30 +++++---------- 2 files changed, 48 insertions(+), 58 deletions(-) diff --git a/config/ModulesMapping.jsonc b/config/ModulesMapping.jsonc index 81fdd5aa996..066e744cdd1 100644 --- a/config/ModulesMapping.jsonc +++ b/config/ModulesMapping.jsonc @@ -1,41 +1,41 @@ { - "Applications": "^applicationTemplates\\.|^applications\\.|^servicePrincipals\\.|^onPremisesPublishingProfiles\\.|^users.appRoleAssignment$|^groups.appRoleAssignment$", - "Bookings": "^solutions\\.|^bookingBusinesses\\.|^bookingCurrencies\\.", - "Calendar": "^places\\.|^users.calendar$|^users.calendarGroup$|^users.event$|^groups.calendar$|^groups.event$", - "ChangeNotifications": "^subscriptions\\.", - "CloudCommunications": "^users.onlineMeeting$|^users.presence$|^communications\\.", - "Compliance": "^compliance\\.", - "CrossDeviceExperiences": "^users.userActivity$|^users.device$", - "Devices.CloudPrint": "^print\\.", - "Devices.CorporateManagement": "^deviceAppManagement\\.|^officeConfiguration\\.|^users.mobileAppIntentAndState$|^users.mobileAppTroubleshootingEvent$|^users.windowsInformationProtectionDeviceRegistration$|^users.managedAppRegistration$|^users.managedDevice$|^users.deviceManagementTroubleshootingEvent$|^users.deviceEnrollmentConfiguration$", - "Devices.ServiceAnnouncement": "^admin.serviceAnnouncement$|^admin.Actions$|^admin.Functions$", - "DeviceManagement": "^deviceManagement.(deviceCompliancePolicy.*|deviceManagementConfigurationPolicy.*|deviceManagementCompliancePolicy.*|deviceManagementConfigurationSettingDefinition.*|deviceConfiguration.*|managedDevice.*|managementCondition.*|microsoftTunnel.*|userExperienceAnalytics.*|windowsInformationProtection.*|deviceManagement|deviceManagement(DerivedCredentialSettings|Intent|ResourceAccessProfileBase|Script|SettingCategory|SettingDefinition|Template|TroubleshootingEvent)|androidForWork(AppConfigurationSchema|Settings)|androidManagedStore(AccountEnterpriseSettings|AppConfigurationSchema)|deviceAndAppManagementAssignmentFilter|deviceCategory|advancedThreatProtectionOnboardingStateSummary|dataSharingConsent|detectedApp|deviceHealthScript|deviceShellScript|embeddedSIMActivationCodePool|groupPolicyConfiguration|macOSSoftwareUpdateAccountSummary|mobileAppTroubleshootingEvent|notificationMessageTemplate|remoteActionAudit|softwareUpdateStatusSummary|windowsMalwareInformation)$", - "DeviceManagement.Administration": "^deviceManagement.(virtualEndpoint.*|.*Partner.*|.*Certificate.*|.*role.*|deviceManagement(DomainJoinConnector|ExchangeConnector|ExchangeOnPremisesPolicy)|groupPolicy(Category|Definition|DefinitionFile|MigrationReport|ObjectFile|UploadedDefinitionFile)|auditEvent|cartToClassAssociation|comanagementEligibleDevice|deviceAndAppManagementRoleAssignment|intuneBrandingProfile|iosUpdateDeviceStatus|mobileThreatDefenseConnector|ndesConnector|resourceOperation|restrictedAppsViolation|termsAndConditions)", - "DeviceManagement.Enrolment": "^deviceManagement.(.*Enrollment.*|.*Autopilot.*|.*depOnboarding.*|importedDeviceIdentity|onPremisesConditionalAccessSettings|windowsFeatureUpdateProfile)$|^roleManagement\\.", - "DeviceManagement.Actions": "^deviceManagement.Actions$", - "DeviceManagement.Functions": "^deviceManagement.Functions$", - "DirectoryObjects": "^directoryObjects\\.", - "Education": "^education\\.", - "Files": "^drives\\.|^shares\\.|^users.drive$|^groups.drive$", - "Financials": "^financials\\.", - "Groups": "^groups.group$|^groups.directoryObject$|^groups.conversation$|^groups.endpoint$|^groups.extension$|^groups.groupLifecyclePolicy$|^groups.resourceSpecificPermissionGrant$|^groups.profilePhoto$|^groups.conversationThread$|^groupLifecyclePolicies\\.|^users.group$|^groups.directorySetting$|^groups.Actions$|^groups.Functions$", - "Identity.DirectoryManagement": "^administrativeUnits\\.|^contacts\\.|^devices\\.|^domains\\.|^directoryRoles\\.|^directoryRoleTemplates\\.|^directorySettingTemplates\\.|^settings\\.|^subscribedSkus\\.|^contracts\\.|^directory\\.|^users.scopedRoleMembership$|^organization.organization$|^organization.organizationalBranding$|^organization.organizationSettings$|^organization.Actions$|^organization.extension$", - "Identity.Governance": "^accessReviews\\.|^businessFlowTemplates\\.|^programs\\.|^programControls\\.|^programControlTypes\\.|^privilegedRoles\\.|^privilegedRoleAssignments\\.|^privilegedRoleAssignmentRequests\\.|^privilegedApproval\\.|^privilegedOperationEvents\\.|^privilegedAccess\\.|^agreements\\.|^users.agreementAcceptance$|^identityGovernance\\.", - "Identity.SignIns": "^organization.certificateBasedAuthConfiguration$|^invitations\\.|^identityProviders\\.|^oauth2PermissionGrants\\.|^identityProtection\\.|^dataPolicyOperations\\.|^identity\\.|^trustFramework\\.|^informationProtection\\.|^policies\\.|^users.authentication$|^users.informationProtection$", - "Mail": "^users.inferenceClassification$|^users.mailFolder$|^users.message$", - "ManagedTenants": "^tenantRelationships.managedTenant$", - "Notes": "^users.onenote$|^groups.onenote$|^sites.onenote$", - "People": "^users.person$|^users.profile$|^users.officeGraphInsights$|^users.userAnalytics$", - "PersonalContacts": "^users.contactFolder$|^users.contact$", - "Planner": "^planner\\.|^users.plannerUser$|^groups.plannerGroup$", - "Reports": "^reports\\.|^auditLogs\\.|^deviceManagement.deviceManagementReports$", - "SchemaExtensions": "^schemaExtensions\\.", - "Search": "^search\\.|^external\\.", - "Security": "^security\\.", - "Sites": "^sites.site$|^sites.itemAnalytics$|^sites.columnDefinition$|^sites.contentType$|^sites.drive$|^sites.list$|^sites.sitePage$|^sites.permission$|^sites.store$|^users.site$|^groups.site$|^sites.Functions$|^sites.Actions$", - "Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$", + // "Applications": "^applicationTemplates\\.|^applications\\.|^servicePrincipals\\.|^onPremisesPublishingProfiles\\.|^users.appRoleAssignment$|^groups.appRoleAssignment$", + // "Bookings": "^solutions\\.|^bookingBusinesses\\.|^bookingCurrencies\\.", + // "Calendar": "^places\\.|^users.calendar$|^users.calendarGroup$|^users.event$|^groups.calendar$|^groups.event$", + // "ChangeNotifications": "^subscriptions\\.", + // "CloudCommunications": "^users.onlineMeeting$|^users.presence$|^communications\\.", + // "Compliance": "^compliance\\.", + // "CrossDeviceExperiences": "^users.userActivity$|^users.device$", + // "Devices.CloudPrint": "^print\\.", + // "Devices.CorporateManagement": "^deviceAppManagement\\.|^officeConfiguration\\.|^users.mobileAppIntentAndState$|^users.mobileAppTroubleshootingEvent$|^users.windowsInformationProtectionDeviceRegistration$|^users.managedAppRegistration$|^users.managedDevice$|^users.deviceManagementTroubleshootingEvent$|^users.deviceEnrollmentConfiguration$", + // "Devices.ServiceAnnouncement": "^admin.serviceAnnouncement$|^admin.Actions$|^admin.Functions$", + // "DeviceManagement": "^deviceManagement.(deviceCompliancePolicy.*|deviceManagementConfigurationPolicy.*|deviceManagementCompliancePolicy.*|deviceManagementConfigurationSettingDefinition.*|deviceConfiguration.*|managedDevice.*|managementCondition.*|microsoftTunnel.*|userExperienceAnalytics.*|windowsInformationProtection.*|deviceManagement|deviceManagement(DerivedCredentialSettings|Intent|ResourceAccessProfileBase|Script|SettingCategory|SettingDefinition|Template|TroubleshootingEvent)|androidForWork(AppConfigurationSchema|Settings)|androidManagedStore(AccountEnterpriseSettings|AppConfigurationSchema)|deviceAndAppManagementAssignmentFilter|deviceCategory|advancedThreatProtectionOnboardingStateSummary|dataSharingConsent|detectedApp|deviceHealthScript|deviceShellScript|embeddedSIMActivationCodePool|groupPolicyConfiguration|macOSSoftwareUpdateAccountSummary|mobileAppTroubleshootingEvent|notificationMessageTemplate|remoteActionAudit|softwareUpdateStatusSummary|windowsMalwareInformation)$", + // "DeviceManagement.Administration": "^deviceManagement.(virtualEndpoint.*|.*Partner.*|.*Certificate.*|.*role.*|deviceManagement(DomainJoinConnector|ExchangeConnector|ExchangeOnPremisesPolicy)|groupPolicy(Category|Definition|DefinitionFile|MigrationReport|ObjectFile|UploadedDefinitionFile)|auditEvent|cartToClassAssociation|comanagementEligibleDevice|deviceAndAppManagementRoleAssignment|intuneBrandingProfile|iosUpdateDeviceStatus|mobileThreatDefenseConnector|ndesConnector|resourceOperation|restrictedAppsViolation|termsAndConditions)", + // "DeviceManagement.Enrolment": "^deviceManagement.(.*Enrollment.*|.*Autopilot.*|.*depOnboarding.*|importedDeviceIdentity|onPremisesConditionalAccessSettings|windowsFeatureUpdateProfile)$|^roleManagement\\.", + // "DeviceManagement.Actions": "^deviceManagement.Actions$", + // "DeviceManagement.Functions": "^deviceManagement.Functions$", + // "DirectoryObjects": "^directoryObjects\\.", + // "Education": "^education\\.", + // "Files": "^drives\\.|^shares\\.|^users.drive$|^groups.drive$", + // "Financials": "^financials\\.", + // "Groups": "^groups.group$|^groups.directoryObject$|^groups.conversation$|^groups.endpoint$|^groups.extension$|^groups.groupLifecyclePolicy$|^groups.resourceSpecificPermissionGrant$|^groups.profilePhoto$|^groups.conversationThread$|^groupLifecyclePolicies\\.|^users.group$|^groups.directorySetting$|^groups.Actions$|^groups.Functions$", + // "Identity.DirectoryManagement": "^administrativeUnits\\.|^contacts\\.|^devices\\.|^domains\\.|^directoryRoles\\.|^directoryRoleTemplates\\.|^directorySettingTemplates\\.|^settings\\.|^subscribedSkus\\.|^contracts\\.|^directory\\.|^users.scopedRoleMembership$|^organization.organization$|^organization.organizationalBranding$|^organization.organizationSettings$|^organization.Actions$|^organization.extension$", + // "Identity.Governance": "^accessReviews\\.|^businessFlowTemplates\\.|^programs\\.|^programControls\\.|^programControlTypes\\.|^privilegedRoles\\.|^privilegedRoleAssignments\\.|^privilegedRoleAssignmentRequests\\.|^privilegedApproval\\.|^privilegedOperationEvents\\.|^privilegedAccess\\.|^agreements\\.|^users.agreementAcceptance$|^identityGovernance\\.", + // "Identity.SignIns": "^organization.certificateBasedAuthConfiguration$|^invitations\\.|^identityProviders\\.|^oauth2PermissionGrants\\.|^identityProtection\\.|^dataPolicyOperations\\.|^identity\\.|^trustFramework\\.|^informationProtection\\.|^policies\\.|^users.authentication$|^users.informationProtection$", + // "Mail": "^users.inferenceClassification$|^users.mailFolder$|^users.message$", + // "ManagedTenants": "^tenantRelationships.managedTenant$", + // "Notes": "^users.onenote$|^groups.onenote$|^sites.onenote$", + // "People": "^users.person$|^users.profile$|^users.officeGraphInsights$|^users.userAnalytics$", + // "PersonalContacts": "^users.contactFolder$|^users.contact$", + // "Planner": "^planner\\.|^users.plannerUser$|^groups.plannerGroup$", + // "Reports": "^reports\\.|^auditLogs\\.|^deviceManagement.deviceManagementReports$", + // "SchemaExtensions": "^schemaExtensions\\.", + // "Search": "^search\\.|^external\\.", + // "Security": "^security\\.", + // "Sites": "^sites.site$|^sites.itemAnalytics$|^sites.columnDefinition$|^sites.contentType$|^sites.drive$|^sites.list$|^sites.sitePage$|^sites.permission$|^sites.store$|^users.site$|^groups.site$|^sites.Functions$|^sites.Actions$", + //"Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$", "Users": "^users.user$|^users.directoryObject$|^users.licenseDetails$|^users.notification$|^users.outlookUser$|^users.profilePhoto$|^users.userSettings$|^users.extension$|^users.oAuth2PermissionGrant$|^users.todo$", - "Users.Actions": "^users.Actions$", - "Users.Functions": "^users.Functions$", - "WindowsUpdates": "^admin.adminWindows$|^admin.Actions$|^admin.Functions$" + // "Users.Actions": "^users.Actions$", + // "Users.Functions": "^users.Functions$", + // "WindowsUpdates": "^admin.adminWindows$|^admin.Actions$|^admin.Functions$" } \ No newline at end of file diff --git a/tools/ExamplesGenerator.ps1 b/tools/ExamplesGenerator.ps1 index c66674e9348..dedcca5a30b 100644 --- a/tools/ExamplesGenerator.ps1 +++ b/tools/ExamplesGenerator.ps1 @@ -23,7 +23,7 @@ function Start-Generator { $GraphMapping = @{ "v1.0" = "examples\v1.0" - "beta" = "examples\v1.0-beta" + #"beta" = "examples\v1.0-beta" } if ($GenerationMode -eq "auto") { $GraphMapping.Keys | ForEach-Object { @@ -131,7 +131,7 @@ function Get-ExternalDocsUrl { [System.Object] $Method = "GET", [string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0") ) - + if(-not($HandWrittenCommands -contains $Command)){ if ($GenerationMode -eq "manual") { if (-not([string]::IsNullOrEmpty($ManualExternalDocsUrl))) { @@ -185,6 +185,7 @@ function Get-ExternalDocsUrl { } } } +} } function Start-WebScrapping { @@ -214,7 +215,7 @@ function Start-WebScrapping { if ($checkPowershell.Contains('lang-powershell')) { $result = $node.InnerHtml $result = $result.Replace('"', '"') - $ExampleList.Add($result) + $L = $ExampleList.Add($result) } } foreach ($header in $headers) { @@ -222,7 +223,7 @@ function Start-WebScrapping { if ($checkPowershell.Contains('Example')) { $result = $header.InnerHtml - $HeaderList.Add($result) + $A = $HeaderList.Add($result) } } @@ -245,7 +246,7 @@ function Update-ExampleFile { ) $Content = Get-Content -Path $ExampleFile - $SearchText = "{{ Add description here }}" + $SearchText = "Example" $SearchTextForNewImports = "{{ Add description here }}" $ReplaceEverything = $False if ($HeaderList.Count -eq 0) { @@ -282,20 +283,6 @@ function Update-ExampleFile { $wrongExamplesCount++ } } - git config --global user.email "timwamalwa@gmail.com" - git config --global user.name "Timothy Wamalwa" - git add $ExampleFile - git commit -m "Examples update on $ExampleFile-$GraphProfile" - } - else { - if ($headCount -ne $exampleCount) { - Write-Host "Mismatch in Title and Snippet count i.e Title ="$headerList.Count " Snippet = "$exampleList.Count - } - else { - Write-Host "No examples found from the reference docs" - } - - } if($wrongExamplesCount -gt 0){ Write-Host "Logging this as an anormally Command " $Command "External Docs" $ExternalDocUrl @@ -318,7 +305,10 @@ function Update-ExampleFile { "$Command, $ExternalDocUrl, $GraphProfile, $UriPath" | Out-File -FilePath $ExamplesToBeReviewed -Append -Encoding ASCII } } - + # git config --global user.email "timwamalwa@gmail.com" + # git config --global user.name "Timothy Wamalwa" + # git add $ExampleFile + # git commit -m "Examples update on $ExampleFile-$GraphProfile" } Import-Csv $HandWrittenDocPath | ForEach-Object{ From e5c009583f73736a4be94cbddc04e8c38ca5c34d Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Wed, 19 Apr 2023 11:06:55 +0300 Subject: [PATCH 03/10] Updated script to support merging of hand written examples with those imported from api reference --- tools/ExamplesGenerator.ps1 | 155 +++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 19 deletions(-) diff --git a/tools/ExamplesGenerator.ps1 b/tools/ExamplesGenerator.ps1 index dedcca5a30b..853789a8d96 100644 --- a/tools/ExamplesGenerator.ps1 +++ b/tools/ExamplesGenerator.ps1 @@ -3,8 +3,11 @@ Param( $ModulesToGenerate = @(), $HandWrittenCommands = @(), - [hashtable]$V1CommandList= @{}, - [hashtable]$BetaCommandList= @{}, + $Available = @(), + [hashtable]$V1CommandGetVariantList= @{}, + [hashtable]$BetaCommandGetVariantList= @{}, + [hashtable]$V1CommandListVariantList= @{}, + [hashtable]$BetaCommandListVariantList= @{}, [string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "..\config\ModulesMapping.jsonc"), [string] $HandWrittenDocPath = (Join-Path $PSScriptRoot "..\examplesreport\HandWrittenExamplesByContentDeveloper.csv"), [string] $ExamplesToBeReviewed = (Join-Path $PSScriptRoot "..\examplesreport\ExamplesToBeReviewed.csv"), @@ -38,7 +41,7 @@ function Start-Generator { $ProfilePathMapping = "examples\v1.0-beta" } $ModulePath = Join-Path $PSScriptRoot "..\src\$GraphModule\$GraphModule\$ProfilePathMapping" - Get-ExternalDocsUrl -ManualExternalDocsUrl $ManualExternalDocsUrl -GenerationMode $GenerationMode -GraphProfilePath $ModulePath -Command $GraphCommand -GraphProfile $ProfilePath -Module -$Module + Get-ExternalDocsUrl -ManualExternalDocsUrl $ManualExternalDocsUrl -GenerationMode $GenerationMode -GraphProfilePath $ModulePath -Command $GraphCommand -GraphProfile $ProfilePath -Module $GraphModule } @@ -93,9 +96,9 @@ function Get-Files { #Extract URI path $UriPath = $null if($GraphProfile -eq "beta"){ - $UriPath = $BetaCommandList[$Command] + $UriPath = $BetaCommandGetVariantList[$Command] }else{ - $UriPath = $V1CommandList[$Command] + $UriPath = $V1CommandGetVariantList[$Command] } if ($UriPath) { @@ -131,12 +134,12 @@ function Get-ExternalDocsUrl { [System.Object] $Method = "GET", [string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0") ) - if(-not($HandWrittenCommands -contains $Command)){ + if ($GenerationMode -eq "manual") { if (-not([string]::IsNullOrEmpty($ManualExternalDocsUrl))) { - Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ManualExternalDocsUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath + Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ManualExternalDocsUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath -Module $Module } } @@ -160,6 +163,16 @@ function Get-ExternalDocsUrl { } $RebuiltPath = $PathRebuild + "microsoft.graph." + $PathToAppend $externalDocUrl = $path[$RebuiltPath].get.externalDocs.url + + if ([string]::IsNullOrEmpty($externalDocUrl)) { + $UriPath2 = $null + if($GraphProfile -eq "beta"){ + $UriPath2 = $BetaCommandListVariantList[$Command] + }else{ + $UriPath2 = $V1CommandListVariantList[$Command] + } + $externalDocUrl = $path[$UriPath2].get.externalDocs.url + } } } if ($MethodName -eq "POST") { @@ -178,14 +191,13 @@ function Get-ExternalDocsUrl { $externalDocUrl = $path[$UriPath].put.externalDocs.url } if (-not([string]::IsNullOrEmpty($externalDocUrl))) { - Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $externalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath + Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $externalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath -Module $Module } } } } } -} } function Start-WebScrapping { @@ -197,6 +209,7 @@ function Start-WebScrapping { [ValidateNotNullOrEmpty()] [string] $Command = "Get-MgUser", [string] $UriPath, + [string] $Module = "Users", [string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0") ) $ExampleFile = "$GraphProfilePath/$Command.md" @@ -227,8 +240,7 @@ function Start-WebScrapping { } } - - Update-ExampleFile -GraphProfile $GraphProfile -HeaderList $HeaderList -ExampleList $ExampleList -ExampleFile $ExampleFile -Description $Description -Command $Command -ExternalDocUrl $ExternalDocUrl -UriPath $UriPath + Update-ExampleFile -GraphProfile $GraphProfile -HeaderList $HeaderList -ExampleList $ExampleList -ExampleFile $ExampleFile -Description $Description -Command $Command -ExternalDocUrl $ExternalDocUrl -UriPath $UriPath -Module $Module } function Update-ExampleFile { @@ -240,6 +252,7 @@ function Update-ExampleFile { [string] $ExampleFile, [string] $UriPath, [string] $Description, + [string] $Module = "Users", [string] $Command = "Get-MgUser", [ValidateNotNullOrEmpty()] [string] $ExternalDocUrl = "https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=powershell" @@ -249,6 +262,7 @@ function Update-ExampleFile { $SearchText = "Example" $SearchTextForNewImports = "{{ Add description here }}" $ReplaceEverything = $False + $ReplaceExistingexamples = $False if ($HeaderList.Count -eq 0) { for ($d = 0; $d -lt $ExampleList.Count; $d++) { $sum = $d + 1 @@ -262,13 +276,14 @@ function Update-ExampleFile { $H = $HeaderList.Add("Example " + $sum + ": Code snippet".Trim()) } } - if (($Content | Select-String -pattern $SearchText) -or ($Content | Select-String -pattern $SearchTextForNewImports)) { + if (($Content | Select-String -pattern $SearchTextForNewImports)) { $ReplaceEverything = $True } $headCount = $HeaderList.Count $exampleCount = $ExampleList.Count - $wrongExamplesCount = 0; + $wrongExamplesCount = 0; + #===========================Importing new examples into files ============================================# if ($ReplaceEverything -and $exampleCount -gt 0 -and $headCount -eq $exampleCount) { Clear-Content $ExampleFile -Force for ($d = 0; $d -lt $headerList.Count; $d++) { @@ -281,14 +296,105 @@ function Update-ExampleFile { Add-Content -Path $ExampleFile -Value $totalText }else{ $wrongExamplesCount++ + } } } + + #===========================Updating existing examples in files ============================================# + if (($Content | Select-String -pattern $SearchText)) { + $ReplaceExistingexamples = $True + } + if ($ReplaceExistingexamples -and $exampleCount -gt 0 -and $headCount -eq $exampleCount) { + #Check existing file + $PatternToSearch = "Import-Module Microsoft.Graph.$Module" + if($HandWrittenCommands -contains $Command){ + $PatternToSearch = $Command + } + $CommandExists = Select-String -Path $ExampleFile -Pattern $PatternToSearch + $NoOfExistingExampleHeaders = 0 + + foreach($Line in $Content){ + if($Line.Contains("### Example")){ + $NoOfExistingExampleHeaders++ + $r = $Available+=$Line.Split(":")[1] + } + } + foreach($v in $Available){ + Write-Host "Available stuff" $v + } + if($CommandExists){ + + $j = 1 + if($HandWrittenCommands -contains $Command){ + for ($d = 0; $d -lt $headerList.Count; $d++) { + $codeValue = $exampleList[$d].Trim() + if($codeValue.Contains($Command)){ + $k = $NoOfExistingExampleHeaders + $j + $j + $titleValue = "### " + $headerList[$d].Replace("Example $j", "Example $k").Trim() + $code = "``````powershell`r$codeValue`r`n``````" + + $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" + $splittedTitleValue = $titleValue.Split(":"); + + if(-not($Available.Contains($splittedTitleValue[1]))){ + Write-Host "Exists ==> " $splittedTitleValue[1] + Add-Content -Path $ExampleFile -Value $totalText + $j++ + } + + }else{ + $wrongExamplesCount++ + + } + } + }else{ + + Clear-Content $ExampleFile -Force + for ($d = 0; $d -lt $headerList.Count; $d++) { + $codeValue = $exampleList[$d].Trim() + if($codeValue.Contains($Command)){ + $titleValue = "### " + $headerList[$d].Trim() + $code = "``````powershell`r$codeValue`r`n``````" + + $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" + Add-Content -Path $ExampleFile -Value $totalText + }else{ + $wrongExamplesCount++ + + } + } + } + Write-Host "Command exists" $PatternToSearch + }else{ + Write-Host "Doesnt exists" $PatternToSearch + + if($exampleList.Contains($PatternToSearch)){ + Clear-Content $ExampleFile -Force + #Replace everything + for ($d = 0; $d -lt $headerList.Count; $d++) { + $codeValue = $exampleList[$d].Trim() + $titleValue = "### " + $headerList[$d].Trim() + $code = "``````powershell`r$codeValue`r`n``````" + + $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" + Add-Content -Path $ExampleFile -Value $totalText + } + + }else{ + Clear-Content $ExampleFile -Force + #Replace everything with boiler plate code + $DefaultBoilerPlate = "### Example 1: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n### Example 2: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n" + Add-Content -Path $ExampleFile -Value $DefaultBoilerPlate.Trim() + } + } + } + + if($wrongExamplesCount -gt 0){ - Write-Host "Logging this as an anormally Command " $Command "External Docs" $ExternalDocUrl - $DefaultBoilerPlate = "### Example 1: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n### Example 2: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n" + - Add-Content -Path $ExampleFile -Value $DefaultBoilerPlate.Trim() #Log api path api version and equivalent external doc url giving wron examples #Create file if it doesn't exist @@ -322,7 +428,9 @@ foreach($Data in $DeserializedContent) { if((-not($Data.Variants[0].Contains("List")))){ - $Beta = $BetaCommandList.Add($Data.Command, $Data.Uri) + $Beta = $BetaCommandGetVariantList.Add($Data.Command, $Data.Uri) + }else{ + $Beta1 = $BetaCommandListVariantList.Add($Data.Command, $Data.Uri) } } @@ -330,7 +438,9 @@ foreach($Data in $DeserializedContent) { if((-not($Data.Variants[0].Contains("List")))){ - $V1 = $V1CommandList.Add($Data.Command, $Data.Uri) + $V1 = $V1CommandGetVariantList.Add($Data.Command, $Data.Uri) + }else{ + $V11 = $V1CommandListVariantList.Add($Data.Command, $Data.Uri) } } } @@ -351,7 +461,14 @@ if ($ModulesToGenerate.Count -eq 0) { $ModulesToGenerate = $ModuleMapping.Keys } -Start-Generator -ModulesToGenerate $ModulesToGenerate -GenerationMode "auto" +#Start-Generator -ModulesToGenerate $ModulesToGenerate -GenerationMode "auto" +#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/directoryobject-getmembergroups?view=graph-rest-1.0" -GraphCommand "Get-MgApplicationMemberGroup" -GraphModule "Applications" -Profile "v1.0" +#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/application-addkey?view=graph-rest-1.0" -GraphCommand "Add-MgApplicationKey" -GraphModule "Applications" -Profile "v1.0" +#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl $null -GraphCommand "Remove-MgUserTodoListTask" -GraphModule "Users" -Profile "v1.0" +#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/todo-list-lists?view=graph-rest-1.0" -GraphCommand "Get-MgUserTodoList" -GraphModule "Users" -Profile "v1.0" +Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/user-get?view=graph-rest-1.0" -GraphCommand "Get-MgUser" -GraphModule "Users" -Profile "v1.0" + + #Comment the above and uncomment the below start command, if you manually want to manually pass ExternalDocs url. #This is for scenarios where the correponding external docs url to the uri path gotten from Find-MgGraph command, is missing on the openapi.yml file for a particular module. From c7b7f238c512a647973a69e2341ff4aa4600c701 Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Wed, 3 May 2023 11:15:19 +0300 Subject: [PATCH 04/10] Updated generator script --- tools/ExamplesGenerator.ps1 | 176 +++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 72 deletions(-) diff --git a/tools/ExamplesGenerator.ps1 b/tools/ExamplesGenerator.ps1 index 853789a8d96..1ce8ca8a4ea 100644 --- a/tools/ExamplesGenerator.ps1 +++ b/tools/ExamplesGenerator.ps1 @@ -145,12 +145,12 @@ function Get-ExternalDocsUrl { } else { if ($UriPath) { - if ($openApiContent.openapi && $openApiContent.info.version) { - foreach ($path in $openApiContent.paths) { + if ($OpenApiContent.openapi && $OpenApiContent.info.version) { + foreach ($Path in $OpenApiContent.paths) { $MethodName = $Method | Out-String - $externalDocUrl = $path[$UriPath].get.externalDocs.url - if ([string]::IsNullOrEmpty($externalDocUrl)) { + $ExternalDocUrl = $Path[$UriPath].get.externalDocs.url + if ([string]::IsNullOrEmpty($ExternalDocUrl)) { $PathSplit = $UriPath.Split("/") $PathToAppend = $PathSplit[$PathSplit.Count - 1] if ($PathToAppend.StartsWith("{") -or $PathToAppend.StartsWith("$")) { @@ -162,36 +162,72 @@ function Get-ExternalDocsUrl { $PathRebuild += $PathSplit[$i] + "/" } $RebuiltPath = $PathRebuild + "microsoft.graph." + $PathToAppend - $externalDocUrl = $path[$RebuiltPath].get.externalDocs.url + $ExternalDocUrl = $Path[$RebuiltPath].get.externalDocs.url - if ([string]::IsNullOrEmpty($externalDocUrl)) { + if ([string]::IsNullOrEmpty($ExternalDocUrl)) { $UriPath2 = $null if($GraphProfile -eq "beta"){ $UriPath2 = $BetaCommandListVariantList[$Command] }else{ $UriPath2 = $V1CommandListVariantList[$Command] } - $externalDocUrl = $path[$UriPath2].get.externalDocs.url + $ExternalDocUrl = $Path[$UriPath2].get.externalDocs.url } } } if ($MethodName -eq "POST") { - $externalDocUrl = $path[$UriPath].post.externalDocs.url + $ExternalDocUrl = $Path[$UriPath].post.externalDocs.url + if ([string]::IsNullOrEmpty($ExternalDocUrl)) { + $UriPath3 = $null + if($GraphProfile -eq "beta"){ + $UriPath3 = $BetaCommandListVariantList[$Command] + }else{ + $UriPath3 = $V1CommandListVariantList[$Command] + } + $ExternalDocUrl = $Path[$UriPath3].post.externalDocs.url + } } if ($MethodName -eq "PATCH") { - $externalDocUrl = $path[$UriPath].patch.externalDocs.url + $ExternalDocUrl = $Path[$UriPath].patch.externalDocs.url + if ([string]::IsNullOrEmpty($ExternalDocUrl)) { + $UriPath4 = $null + if($GraphProfile -eq "beta"){ + $UriPath4 = $BetaCommandListVariantList[$Command] + }else{ + $UriPath4 = $V1CommandListVariantList[$Command] + } + $ExternalDocUrl = $Path[$UriPath4].patch.externalDocs.url + } } if ($MethodName -eq "DELETE") { - $externalDocUrl = $path[$UriPath].delete.externalDocs.url + $ExternalDocUrl = $Path[$UriPath].delete.externalDocs.url + if ([string]::IsNullOrEmpty($ExternalDocUrl)) { + $UriPath5 = $null + if($GraphProfile -eq "beta"){ + $UriPath5 = $BetaCommandListVariantList[$Command] + }else{ + $UriPath5 = $V1CommandListVariantList[$Command] + } + $ExternalDocUrl = $Path[$UriPath5].delete.externalDocs.url + } } if ($MethodName -eq "PUT") { - $externalDocUrl = $path[$UriPath].put.externalDocs.url + $ExternalDocUrl = $Path[$UriPath].put.externalDocs.url + if ([string]::IsNullOrEmpty($ExternalDocUrl)) { + $UriPath6 = $null + if($GraphProfile -eq "beta"){ + $UriPath6 = $BetaCommandListVariantList[$Command] + }else{ + $UriPath6 = $V1CommandListVariantList[$Command] + } + $ExternalDocUrl = $Path[$UriPath6].put.externalDocs.url + } } - if (-not([string]::IsNullOrEmpty($externalDocUrl))) { - Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $externalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath -Module $Module + if (-not([string]::IsNullOrEmpty($ExternalDocUrl))) { + Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ExternalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath -Module $Module } } @@ -213,30 +249,28 @@ function Start-WebScrapping { [string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0") ) $ExampleFile = "$GraphProfilePath/$Command.md" - $url = $ExternalDocUrl - $Description = "This example shows how to use the $Command Cmdlet.`r`n`r`To learn about permissions for this resource, see the [permissions reference](/graph/permissions-reference)." - $WebResponse = Invoke-WebRequest -Uri $url + $WebResponse = Invoke-WebRequest -Uri $ExternalDocUrl $HeaderList = New-Object -TypeName 'System.Collections.ArrayList'; $ExampleList = New-Object -TypeName 'System.Collections.ArrayList'; - $htmlDom = ConvertFrom-Html $WebResponse - $nodes = $htmlDom.SelectNodes('//pre/code') - $headers = $htmlDom.SelectNodes('//h3') - foreach ($node in $nodes) { - $checkPowershell = $node.OuterHtml + $HtmlDom = ConvertFrom-Html $WebResponse + $Nodes = $HtmlDom.SelectNodes('//pre/code') + $Headers = $HtmlDom.SelectNodes('//h3') + foreach ($Node in $Nodes) { + $CheckPowershell = $Node.OuterHtml - if ($checkPowershell.Contains('lang-powershell')) { - $result = $node.InnerHtml - $result = $result.Replace('"', '"') - $L = $ExampleList.Add($result) + if ($CheckPowershell.Contains('lang-powershell')) { + $Result = $Node.InnerHtml + $Result = $Result.Replace('"', '"') + $L = $ExampleList.Add($Result) } } - foreach ($header in $headers) { - $checkPowershell = $header.OuterHtml + foreach ($Header in $Headers) { + $CheckPowershell = $Header.OuterHtml - if ($checkPowershell.Contains('Example')) { - $result = $header.InnerHtml - $A = $HeaderList.Add($result) + if ($CheckPowershell.Contains('Example')) { + $Result = $Header.InnerHtml + $A = $HeaderList.Add($Result) } } @@ -280,22 +314,22 @@ function Update-ExampleFile { $ReplaceEverything = $True } - $headCount = $HeaderList.Count - $exampleCount = $ExampleList.Count - $wrongExamplesCount = 0; + $HeadCount = $HeaderList.Count + $ExampleCount = $ExampleList.Count + $WrongExamplesCount = 0; #===========================Importing new examples into files ============================================# - if ($ReplaceEverything -and $exampleCount -gt 0 -and $headCount -eq $exampleCount) { + if ($ReplaceEverything -and $ExampleCount -gt 0 -and $HeadCount -eq $ExampleCount) { Clear-Content $ExampleFile -Force - for ($d = 0; $d -lt $headerList.Count; $d++) { - $codeValue = $exampleList[$d].Trim() - if($codeValue.Contains($Command)){ - $titleValue = "### " + $headerList[$d].Trim() - $code = "``````powershell`r$codeValue`r`n``````" + for ($d = 0; $d -lt $HeaderList.Count; $d++) { + $CodeValue = $ExampleList[$d].Trim() + if($CodeValue.Contains($Command)){ + $TitleValue = "### " + $HeaderList[$d].Trim() + $Code = "``````powershell`r$CodeValue`r`n``````" - $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" - Add-Content -Path $ExampleFile -Value $totalText + $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" + Add-Content -Path $ExampleFile -Value $TotalText }else{ - $wrongExamplesCount++ + $WrongExamplesCount++ } } @@ -320,66 +354,60 @@ function Update-ExampleFile { $r = $Available+=$Line.Split(":")[1] } } - foreach($v in $Available){ - Write-Host "Available stuff" $v - } if($CommandExists){ $j = 1 if($HandWrittenCommands -contains $Command){ for ($d = 0; $d -lt $headerList.Count; $d++) { - $codeValue = $exampleList[$d].Trim() - if($codeValue.Contains($Command)){ + $CodeValue = $ExampleList[$d].Trim() + if($CodeValue.Contains($Command)){ $k = $NoOfExistingExampleHeaders + $j $j - $titleValue = "### " + $headerList[$d].Replace("Example $j", "Example $k").Trim() - $code = "``````powershell`r$codeValue`r`n``````" + $TitleValue = "### " + $HeaderList[$d].Replace("Example $j", "Example $k").Trim() + $Code = "``````powershell`r$CodeValue`r`n``````" - $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" - $splittedTitleValue = $titleValue.Split(":"); + $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" + $SplittedTitleValue = $TitleValue.Split(":"); - if(-not($Available.Contains($splittedTitleValue[1]))){ - Write-Host "Exists ==> " $splittedTitleValue[1] - Add-Content -Path $ExampleFile -Value $totalText + if(-not($Available.Contains($SplittedTitleValue[1]))){ + Add-Content -Path $ExampleFile -Value $TotalText $j++ } }else{ - $wrongExamplesCount++ + $WrongExamplesCount++ } } }else{ Clear-Content $ExampleFile -Force - for ($d = 0; $d -lt $headerList.Count; $d++) { - $codeValue = $exampleList[$d].Trim() + for ($d = 0; $d -lt $HeaderList.Count; $d++) { + $CodeValue = $ExampleList[$d].Trim() if($codeValue.Contains($Command)){ - $titleValue = "### " + $headerList[$d].Trim() - $code = "``````powershell`r$codeValue`r`n``````" + $TitleValue = "### " + $HeaderList[$d].Trim() + $Code = "``````powershell`r$CodeValue`r`n``````" - $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" - Add-Content -Path $ExampleFile -Value $totalText + $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" + Add-Content -Path $ExampleFile -Value $TotalText }else{ - $wrongExamplesCount++ + $WrongExamplesCount++ } } } - Write-Host "Command exists" $PatternToSearch }else{ - Write-Host "Doesnt exists" $PatternToSearch - if($exampleList.Contains($PatternToSearch)){ + if($ExampleList.Contains($PatternToSearch)){ Clear-Content $ExampleFile -Force #Replace everything - for ($d = 0; $d -lt $headerList.Count; $d++) { - $codeValue = $exampleList[$d].Trim() - $titleValue = "### " + $headerList[$d].Trim() - $code = "``````powershell`r$codeValue`r`n``````" + for ($d = 0; $d -lt $HeaderList.Count; $d++) { + $CodeValue = $ExampleList[$d].Trim() + $TitleValue = "### " + $HeaderList[$d].Trim() + $Code = "``````powershell`r$CodeValue`r`n``````" - $totalText = "$titleValue`r`n`n$code`r`n$description`r`n" - Add-Content -Path $ExampleFile -Value $totalText + $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" + Add-Content -Path $ExampleFile -Value $TotalText } }else{ @@ -392,7 +420,7 @@ function Update-ExampleFile { } - if($wrongExamplesCount -gt 0){ + if($WrongExamplesCount -gt 0){ #Log api path api version and equivalent external doc url giving wron examples @@ -465,7 +493,11 @@ if ($ModulesToGenerate.Count -eq 0) { #Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/directoryobject-getmembergroups?view=graph-rest-1.0" -GraphCommand "Get-MgApplicationMemberGroup" -GraphModule "Applications" -Profile "v1.0" #Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/application-addkey?view=graph-rest-1.0" -GraphCommand "Add-MgApplicationKey" -GraphModule "Applications" -Profile "v1.0" #Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl $null -GraphCommand "Remove-MgUserTodoListTask" -GraphModule "Users" -Profile "v1.0" + #Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/todo-list-lists?view=graph-rest-1.0" -GraphCommand "Get-MgUserTodoList" -GraphModule "Users" -Profile "v1.0" + +#-----------------------------------------------------------------------------# +# Test script for merging examples from api reference with handwritten commands Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/user-get?view=graph-rest-1.0" -GraphCommand "Get-MgUser" -GraphModule "Users" -Profile "v1.0" From 89423b0c26b933552b9f2e0bd41dc34b9a22e550 Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Mon, 22 May 2023 10:18:13 +0300 Subject: [PATCH 05/10] Modified examples generator tool to resolve issue Help for Get-MgUserManagerByRef contains examples for Get-MgUserManager and Get-MgUser #1791 --- .azure-pipelines/weekly-examples-update.yml | 25 +- config/ModulesMapping.jsonc | 76 +++--- tools/ExamplesGenerator.ps1 | 260 ++++++++------------ 3 files changed, 156 insertions(+), 205 deletions(-) diff --git a/.azure-pipelines/weekly-examples-update.yml b/.azure-pipelines/weekly-examples-update.yml index 23e05c5a41f..4f38c431e56 100644 --- a/.azure-pipelines/weekly-examples-update.yml +++ b/.azure-pipelines/weekly-examples-update.yml @@ -2,10 +2,10 @@ trigger: none # disable triggers based on commits. pr: none # disable as a PR gate. -name: 'PowerShellExamplesUpdate Check' +name: 'PowerShellExamplesUpdateV1 Check' schedules: - cron: "0 3 * * FRI" # every Friday at 3AM UTC (off hours for Redmond, Nairobi and Montréal) - displayName: 'PowerShellExamplesUpdate Check' + displayName: 'PowerShellExamplesUpdateV1' branches: include: - dev @@ -28,12 +28,11 @@ resources: ref: dev jobs: -- job: PowerShellExamplesUpdate +- job: PowerShellExamplesUpdateV1 pool: name: ${{ parameters.BuildAgent }} timeoutInMinutes: ${{ parameters.PipelineTimeout }} steps: - - template: ./common-templates/update-sdkversion.yml - task: PowerShell@2 name: "ComputeBranch" @@ -56,13 +55,21 @@ jobs: git status - task: PowerShell@2 - displayName: 'Update Examples From Graph Reference' + displayName: 'Update Examples From API reference - V1' continueOnError: false inputs: targetType: 'filePath' pwsh: true filePath: tools\ExamplesGenerator.ps1 + - task: PublishBuildArtifacts@1 + displayName: 'Publish Examples to be reviewed as artifact' + inputs: + PathtoPublish: 'examplesreport' + ArtifactName: 'ExamplesToBeReviewed' + publishLocation: 'Container' + # StoreAsTar: true + - task: PowerShell@2 displayName: Pushing to github env: @@ -71,10 +78,12 @@ jobs: targetType: inline pwsh: true script: | + git config --global user.email "GraphTooling@service.microsoft.com" + git config --global user.name "Microsoft Graph DevX Tooling" git status git add . - git commit -m "Updating examples" - git push --set-upstream origin $(ComputeBranch.WeeklyExamplesBranch) + git commit -m "Updating v1 examples" + git push --set-upstream https://$(GITHUB_TOKEN)@github.com/microsoftgraph/msgraph-sdk-powershell.git $(ComputeBranch.WeeklyExamplesBranch) git status - template: ./common-templates/create-pr.yml @@ -82,4 +91,4 @@ jobs: BaseBranch: "dev" TargetBranch: $(ComputeBranch.WeeklyExamplesBranch) Title: "[v1] Examples Update" - Body: "This pull request was automatically created by Azure Pipelines. **Important** Check for unexpected deletions or changes in this PR." + Body: "This pull request was automatically created by Azure Pipelines. **Important** Check for unexpected deletions or changes in this PR." \ No newline at end of file diff --git a/config/ModulesMapping.jsonc b/config/ModulesMapping.jsonc index 066e744cdd1..2f654910a2a 100644 --- a/config/ModulesMapping.jsonc +++ b/config/ModulesMapping.jsonc @@ -1,41 +1,41 @@ { - // "Applications": "^applicationTemplates\\.|^applications\\.|^servicePrincipals\\.|^onPremisesPublishingProfiles\\.|^users.appRoleAssignment$|^groups.appRoleAssignment$", - // "Bookings": "^solutions\\.|^bookingBusinesses\\.|^bookingCurrencies\\.", - // "Calendar": "^places\\.|^users.calendar$|^users.calendarGroup$|^users.event$|^groups.calendar$|^groups.event$", - // "ChangeNotifications": "^subscriptions\\.", - // "CloudCommunications": "^users.onlineMeeting$|^users.presence$|^communications\\.", - // "Compliance": "^compliance\\.", - // "CrossDeviceExperiences": "^users.userActivity$|^users.device$", - // "Devices.CloudPrint": "^print\\.", - // "Devices.CorporateManagement": "^deviceAppManagement\\.|^officeConfiguration\\.|^users.mobileAppIntentAndState$|^users.mobileAppTroubleshootingEvent$|^users.windowsInformationProtectionDeviceRegistration$|^users.managedAppRegistration$|^users.managedDevice$|^users.deviceManagementTroubleshootingEvent$|^users.deviceEnrollmentConfiguration$", - // "Devices.ServiceAnnouncement": "^admin.serviceAnnouncement$|^admin.Actions$|^admin.Functions$", - // "DeviceManagement": "^deviceManagement.(deviceCompliancePolicy.*|deviceManagementConfigurationPolicy.*|deviceManagementCompliancePolicy.*|deviceManagementConfigurationSettingDefinition.*|deviceConfiguration.*|managedDevice.*|managementCondition.*|microsoftTunnel.*|userExperienceAnalytics.*|windowsInformationProtection.*|deviceManagement|deviceManagement(DerivedCredentialSettings|Intent|ResourceAccessProfileBase|Script|SettingCategory|SettingDefinition|Template|TroubleshootingEvent)|androidForWork(AppConfigurationSchema|Settings)|androidManagedStore(AccountEnterpriseSettings|AppConfigurationSchema)|deviceAndAppManagementAssignmentFilter|deviceCategory|advancedThreatProtectionOnboardingStateSummary|dataSharingConsent|detectedApp|deviceHealthScript|deviceShellScript|embeddedSIMActivationCodePool|groupPolicyConfiguration|macOSSoftwareUpdateAccountSummary|mobileAppTroubleshootingEvent|notificationMessageTemplate|remoteActionAudit|softwareUpdateStatusSummary|windowsMalwareInformation)$", - // "DeviceManagement.Administration": "^deviceManagement.(virtualEndpoint.*|.*Partner.*|.*Certificate.*|.*role.*|deviceManagement(DomainJoinConnector|ExchangeConnector|ExchangeOnPremisesPolicy)|groupPolicy(Category|Definition|DefinitionFile|MigrationReport|ObjectFile|UploadedDefinitionFile)|auditEvent|cartToClassAssociation|comanagementEligibleDevice|deviceAndAppManagementRoleAssignment|intuneBrandingProfile|iosUpdateDeviceStatus|mobileThreatDefenseConnector|ndesConnector|resourceOperation|restrictedAppsViolation|termsAndConditions)", - // "DeviceManagement.Enrolment": "^deviceManagement.(.*Enrollment.*|.*Autopilot.*|.*depOnboarding.*|importedDeviceIdentity|onPremisesConditionalAccessSettings|windowsFeatureUpdateProfile)$|^roleManagement\\.", - // "DeviceManagement.Actions": "^deviceManagement.Actions$", - // "DeviceManagement.Functions": "^deviceManagement.Functions$", - // "DirectoryObjects": "^directoryObjects\\.", - // "Education": "^education\\.", - // "Files": "^drives\\.|^shares\\.|^users.drive$|^groups.drive$", - // "Financials": "^financials\\.", - // "Groups": "^groups.group$|^groups.directoryObject$|^groups.conversation$|^groups.endpoint$|^groups.extension$|^groups.groupLifecyclePolicy$|^groups.resourceSpecificPermissionGrant$|^groups.profilePhoto$|^groups.conversationThread$|^groupLifecyclePolicies\\.|^users.group$|^groups.directorySetting$|^groups.Actions$|^groups.Functions$", - // "Identity.DirectoryManagement": "^administrativeUnits\\.|^contacts\\.|^devices\\.|^domains\\.|^directoryRoles\\.|^directoryRoleTemplates\\.|^directorySettingTemplates\\.|^settings\\.|^subscribedSkus\\.|^contracts\\.|^directory\\.|^users.scopedRoleMembership$|^organization.organization$|^organization.organizationalBranding$|^organization.organizationSettings$|^organization.Actions$|^organization.extension$", - // "Identity.Governance": "^accessReviews\\.|^businessFlowTemplates\\.|^programs\\.|^programControls\\.|^programControlTypes\\.|^privilegedRoles\\.|^privilegedRoleAssignments\\.|^privilegedRoleAssignmentRequests\\.|^privilegedApproval\\.|^privilegedOperationEvents\\.|^privilegedAccess\\.|^agreements\\.|^users.agreementAcceptance$|^identityGovernance\\.", - // "Identity.SignIns": "^organization.certificateBasedAuthConfiguration$|^invitations\\.|^identityProviders\\.|^oauth2PermissionGrants\\.|^identityProtection\\.|^dataPolicyOperations\\.|^identity\\.|^trustFramework\\.|^informationProtection\\.|^policies\\.|^users.authentication$|^users.informationProtection$", - // "Mail": "^users.inferenceClassification$|^users.mailFolder$|^users.message$", - // "ManagedTenants": "^tenantRelationships.managedTenant$", - // "Notes": "^users.onenote$|^groups.onenote$|^sites.onenote$", - // "People": "^users.person$|^users.profile$|^users.officeGraphInsights$|^users.userAnalytics$", - // "PersonalContacts": "^users.contactFolder$|^users.contact$", - // "Planner": "^planner\\.|^users.plannerUser$|^groups.plannerGroup$", - // "Reports": "^reports\\.|^auditLogs\\.|^deviceManagement.deviceManagementReports$", - // "SchemaExtensions": "^schemaExtensions\\.", - // "Search": "^search\\.|^external\\.", - // "Security": "^security\\.", - // "Sites": "^sites.site$|^sites.itemAnalytics$|^sites.columnDefinition$|^sites.contentType$|^sites.drive$|^sites.list$|^sites.sitePage$|^sites.permission$|^sites.store$|^users.site$|^groups.site$|^sites.Functions$|^sites.Actions$", - //"Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$", + "Applications": "^applicationTemplates\\.|^applications\\.|^servicePrincipals\\.|^onPremisesPublishingProfiles\\.|^users.appRoleAssignment$|^groups.appRoleAssignment$", + "Bookings": "^solutions\\.|^bookingBusinesses\\.|^bookingCurrencies\\.", + "Calendar": "^places\\.|^users.calendar$|^users.calendarGroup$|^users.event$|^groups.calendar$|^groups.event$", + "ChangeNotifications": "^subscriptions\\.", + "CloudCommunications": "^users.onlineMeeting$|^users.presence$|^communications\\.", + "Compliance": "^compliance\\.", + "CrossDeviceExperiences": "^users.userActivity$|^users.device$", + "Devices.CloudPrint": "^print\\.", + "Devices.CorporateManagement": "^deviceAppManagement\\.|^officeConfiguration\\.|^users.mobileAppIntentAndState$|^users.mobileAppTroubleshootingEvent$|^users.windowsInformationProtectionDeviceRegistration$|^users.managedAppRegistration$|^users.managedDevice$|^users.deviceManagementTroubleshootingEvent$|^users.deviceEnrollmentConfiguration$", + "Devices.ServiceAnnouncement": "^admin.serviceAnnouncement$|^admin.Actions$|^admin.Functions$", + "DeviceManagement": "^deviceManagement.(deviceCompliancePolicy.*|deviceManagementConfigurationPolicy.*|deviceManagementCompliancePolicy.*|deviceManagementConfigurationSettingDefinition.*|deviceConfiguration.*|managedDevice.*|managementCondition.*|microsoftTunnel.*|userExperienceAnalytics.*|windowsInformationProtection.*|deviceManagement|deviceManagement(DerivedCredentialSettings|Intent|ResourceAccessProfileBase|Script|SettingCategory|SettingDefinition|Template|TroubleshootingEvent)|androidForWork(AppConfigurationSchema|Settings)|androidManagedStore(AccountEnterpriseSettings|AppConfigurationSchema)|deviceAndAppManagementAssignmentFilter|deviceCategory|advancedThreatProtectionOnboardingStateSummary|dataSharingConsent|detectedApp|deviceHealthScript|deviceShellScript|embeddedSIMActivationCodePool|groupPolicyConfiguration|macOSSoftwareUpdateAccountSummary|mobileAppTroubleshootingEvent|notificationMessageTemplate|remoteActionAudit|softwareUpdateStatusSummary|windowsMalwareInformation)$", + "DeviceManagement.Administration": "^deviceManagement.(virtualEndpoint.*|.*Partner.*|.*Certificate.*|.*role.*|deviceManagement(DomainJoinConnector|ExchangeConnector|ExchangeOnPremisesPolicy)|groupPolicy(Category|Definition|DefinitionFile|MigrationReport|ObjectFile|UploadedDefinitionFile)|auditEvent|cartToClassAssociation|comanagementEligibleDevice|deviceAndAppManagementRoleAssignment|intuneBrandingProfile|iosUpdateDeviceStatus|mobileThreatDefenseConnector|ndesConnector|resourceOperation|restrictedAppsViolation|termsAndConditions)", + "DeviceManagement.Enrolment": "^deviceManagement.(.*Enrollment.*|.*Autopilot.*|.*depOnboarding.*|importedDeviceIdentity|onPremisesConditionalAccessSettings|windowsFeatureUpdateProfile)$|^roleManagement\\.", + "DeviceManagement.Actions": "^deviceManagement.Actions$", + "DeviceManagement.Functions": "^deviceManagement.Functions$", + "DirectoryObjects": "^directoryObjects\\.", + "Education": "^education\\.", + "Files": "^drives\\.|^shares\\.|^users.drive$|^groups.drive$", + "Financials": "^financials\\.", + "Groups": "^groups.group$|^groups.directoryObject$|^groups.conversation$|^groups.endpoint$|^groups.extension$|^groups.groupLifecyclePolicy$|^groups.resourceSpecificPermissionGrant$|^groups.profilePhoto$|^groups.conversationThread$|^groupLifecyclePolicies\\.|^users.group$|^groups.directorySetting$|^groups.Actions$|^groups.Functions$", + "Identity.DirectoryManagement": "^administrativeUnits\\.|^contacts\\.|^devices\\.|^domains\\.|^directoryRoles\\.|^directoryRoleTemplates\\.|^directorySettingTemplates\\.|^settings\\.|^subscribedSkus\\.|^contracts\\.|^directory\\.|^users.scopedRoleMembership$|^organization.organization$|^organization.organizationalBranding$|^organization.organizationSettings$|^organization.Actions$|^organization.extension$", + "Identity.Governance": "^accessReviews\\.|^businessFlowTemplates\\.|^programs\\.|^programControls\\.|^programControlTypes\\.|^privilegedRoles\\.|^privilegedRoleAssignments\\.|^privilegedRoleAssignmentRequests\\.|^privilegedApproval\\.|^privilegedOperationEvents\\.|^privilegedAccess\\.|^agreements\\.|^users.agreementAcceptance$|^identityGovernance\\.", + "Identity.SignIns": "^organization.certificateBasedAuthConfiguration$|^invitations\\.|^identityProviders\\.|^oauth2PermissionGrants\\.|^identityProtection\\.|^dataPolicyOperations\\.|^identity\\.|^trustFramework\\.|^informationProtection\\.|^policies\\.|^users.authentication$|^users.informationProtection$", + "Mail": "^users.inferenceClassification$|^users.mailFolder$|^users.message$", + "ManagedTenants": "^tenantRelationships.managedTenant$", + "Notes": "^users.onenote$|^groups.onenote$|^sites.onenote$", + "People": "^users.person$|^users.profile$|^users.officeGraphInsights$|^users.userAnalytics$", + "PersonalContacts": "^users.contactFolder$|^users.contact$", + "Planner": "^planner\\.|^users.plannerUser$|^groups.plannerGroup$", + "Reports": "^reports\\.|^auditLogs\\.|^deviceManagement.deviceManagementReports$", + "SchemaExtensions": "^schemaExtensions\\.", + "Search": "^search\\.|^external\\.", + "Security": "^security\\.", + "Sites": "^sites.site$|^sites.itemAnalytics$|^sites.columnDefinition$|^sites.contentType$|^sites.drive$|^sites.list$|^sites.sitePage$|^sites.permission$|^sites.store$|^users.site$|^groups.site$|^sites.Functions$|^sites.Actions$", + "Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$", "Users": "^users.user$|^users.directoryObject$|^users.licenseDetails$|^users.notification$|^users.outlookUser$|^users.profilePhoto$|^users.userSettings$|^users.extension$|^users.oAuth2PermissionGrant$|^users.todo$", - // "Users.Actions": "^users.Actions$", - // "Users.Functions": "^users.Functions$", - // "WindowsUpdates": "^admin.adminWindows$|^admin.Actions$|^admin.Functions$" + "Users.Actions": "^users.Actions$", + "Users.Functions": "^users.Functions$", + "WindowsUpdates": "^admin.adminWindows$|^admin.Actions$|^admin.Functions$" } \ No newline at end of file diff --git a/tools/ExamplesGenerator.ps1 b/tools/ExamplesGenerator.ps1 index 1ce8ca8a4ea..7b7c9b72696 100644 --- a/tools/ExamplesGenerator.ps1 +++ b/tools/ExamplesGenerator.ps1 @@ -2,15 +2,14 @@ # Licensed under the MIT License. Param( $ModulesToGenerate = @(), - $HandWrittenCommands = @(), $Available = @(), [hashtable]$V1CommandGetVariantList= @{}, [hashtable]$BetaCommandGetVariantList= @{}, [hashtable]$V1CommandListVariantList= @{}, [hashtable]$BetaCommandListVariantList= @{}, [string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "..\config\ModulesMapping.jsonc"), - [string] $HandWrittenDocPath = (Join-Path $PSScriptRoot "..\examplesreport\HandWrittenExamplesByContentDeveloper.csv"), - [string] $ExamplesToBeReviewed = (Join-Path $PSScriptRoot "..\examplesreport\ExamplesToBeReviewed.csv"), + [string] $FolderForExamplesToBeReviewed = (Join-Path $PSScriptRoot "..\examplesreport"), + [string] $ExamplesToBeReviewed = "ExamplesToBeReviewed.csv", $MetaDataJsonFile = (Join-Path $PSScriptRoot "../src/Authentication/Authentication/custom/common/MgCommandMetadata.json") ) function Start-Generator { @@ -26,7 +25,7 @@ function Start-Generator { $GraphMapping = @{ "v1.0" = "examples\v1.0" - #"beta" = "examples\v1.0-beta" + "beta" = "examples\v1.0-beta" } if ($GenerationMode -eq "auto") { $GraphMapping.Keys | ForEach-Object { @@ -44,7 +43,6 @@ function Start-Generator { Get-ExternalDocsUrl -ManualExternalDocsUrl $ManualExternalDocsUrl -GenerationMode $GenerationMode -GraphProfilePath $ModulePath -Command $GraphCommand -GraphProfile $ProfilePath -Module $GraphModule } - } function Get-FilesByProfile { Param( @@ -80,9 +78,7 @@ function Get-Files { [string] $Module = "Users", [Hashtable] $OpenApiContent ) - $ModuleManifestFile = (Join-Path $PSScriptRoot "..\src\$Module\$Module\Microsoft.Graph.$Module.psd1") - $ModuleManifestFileContent = Get-Content -Path $ModuleManifestFile - + try { if (Test-Path $GraphProfilePath) { @@ -90,9 +86,6 @@ function Get-Files { #Extract command over here $Command = [System.IO.Path]::GetFileNameWithoutExtension($File) - #Check for cmdlet existence from the module manifest file - if ($ModuleManifestFileContent | Select-String -pattern $Command) { - #Extract URI path $UriPath = $null if($GraphProfile -eq "beta"){ @@ -105,8 +98,6 @@ function Get-Files { $Method = $UriPaths.Method Get-ExternalDocsUrl -GraphProfile $GraphProfile -Url -UriPath $UriPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method -Module $Module } - - } } } @@ -134,7 +125,7 @@ function Get-ExternalDocsUrl { [System.Object] $Method = "GET", [string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0") ) - + if ($GenerationMode -eq "manual") { if (-not([string]::IsNullOrEmpty($ManualExternalDocsUrl))) { @@ -145,11 +136,12 @@ function Get-ExternalDocsUrl { } else { if ($UriPath) { + if ($OpenApiContent.openapi && $OpenApiContent.info.version) { foreach ($Path in $OpenApiContent.paths) { $MethodName = $Method | Out-String - - $ExternalDocUrl = $Path[$UriPath].get.externalDocs.url + $ExternalDocUrl = $Path[$UriPath].values.externalDocs.url + if ([string]::IsNullOrEmpty($ExternalDocUrl)) { $PathSplit = $UriPath.Split("/") $PathToAppend = $PathSplit[$PathSplit.Count - 1] @@ -162,8 +154,7 @@ function Get-ExternalDocsUrl { $PathRebuild += $PathSplit[$i] + "/" } $RebuiltPath = $PathRebuild + "microsoft.graph." + $PathToAppend - $ExternalDocUrl = $Path[$RebuiltPath].get.externalDocs.url - + $ExternalDocUrl = $path[$RebuiltPath].get.externalDocs.url if ([string]::IsNullOrEmpty($ExternalDocUrl)) { $UriPath2 = $null if($GraphProfile -eq "beta"){ @@ -171,7 +162,10 @@ function Get-ExternalDocsUrl { }else{ $UriPath2 = $V1CommandListVariantList[$Command] } - $ExternalDocUrl = $Path[$UriPath2].get.externalDocs.url + if(-not([string]::IsNullOrEmpty($UriPath2))){ + $ExternalDocUrl = $Path[$UriPath2].get.externalDocs.url + } + } } } @@ -183,8 +177,10 @@ function Get-ExternalDocsUrl { $UriPath3 = $BetaCommandListVariantList[$Command] }else{ $UriPath3 = $V1CommandListVariantList[$Command] - } - $ExternalDocUrl = $Path[$UriPath3].post.externalDocs.url + } + if(-not([string]::IsNullOrEmpty($UriPath3))){ + $ExternalDocUrl = $Path[$UriPath3].post.externalDocs.url + } } } @@ -197,7 +193,9 @@ function Get-ExternalDocsUrl { }else{ $UriPath4 = $V1CommandListVariantList[$Command] } - $ExternalDocUrl = $Path[$UriPath4].patch.externalDocs.url + if(-not([string]::IsNullOrEmpty($UriPath4))){ + $ExternalDocUrl = $Path[$UriPath4].post.externalDocs.url + } } } @@ -210,10 +208,12 @@ function Get-ExternalDocsUrl { }else{ $UriPath5 = $V1CommandListVariantList[$Command] } - $ExternalDocUrl = $Path[$UriPath5].delete.externalDocs.url + if(-not([string]::IsNullOrEmpty($UriPath5))){ + $ExternalDocUrl = $Path[$UriPath5].post.externalDocs.url + } } } - + if ($MethodName -eq "PUT") { $ExternalDocUrl = $Path[$UriPath].put.externalDocs.url if ([string]::IsNullOrEmpty($ExternalDocUrl)) { @@ -223,14 +223,16 @@ function Get-ExternalDocsUrl { }else{ $UriPath6 = $V1CommandListVariantList[$Command] } - $ExternalDocUrl = $Path[$UriPath6].put.externalDocs.url + if(-not([string]::IsNullOrEmpty($UriPath6))){ + $ExternalDocUrl = $Path[$UriPath6].post.externalDocs.url + } } } if (-not([string]::IsNullOrEmpty($ExternalDocUrl))) { Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ExternalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath -Module $Module } - } + } } } @@ -247,33 +249,36 @@ function Start-WebScrapping { [string] $UriPath, [string] $Module = "Users", [string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0") - ) + ) $ExampleFile = "$GraphProfilePath/$Command.md" + $url = $ExternalDocUrl + $Description = "This example shows how to use the $Command Cmdlet.`r`n`r`To learn about permissions for this resource, see the [permissions reference](/graph/permissions-reference)." - $WebResponse = Invoke-WebRequest -Uri $ExternalDocUrl + $WebResponse = Invoke-WebRequest -Uri $url $HeaderList = New-Object -TypeName 'System.Collections.ArrayList'; $ExampleList = New-Object -TypeName 'System.Collections.ArrayList'; - $HtmlDom = ConvertFrom-Html $WebResponse - $Nodes = $HtmlDom.SelectNodes('//pre/code') - $Headers = $HtmlDom.SelectNodes('//h3') - foreach ($Node in $Nodes) { - $CheckPowershell = $Node.OuterHtml + $htmlDom = ConvertFrom-Html $WebResponse + $nodes = $htmlDom.SelectNodes('//pre/code') + $headers = $htmlDom.SelectNodes('//h3') + foreach ($node in $nodes) { + $checkPowershell = $node.OuterHtml - if ($CheckPowershell.Contains('lang-powershell')) { - $Result = $Node.InnerHtml - $Result = $Result.Replace('"', '"') - $L = $ExampleList.Add($Result) + if ($checkPowershell.Contains('lang-powershell')) { + $result = $node.InnerHtml + $result = $result.Replace('"', '"') + $EL = $ExampleList.Add($result) } } - foreach ($Header in $Headers) { - $CheckPowershell = $Header.OuterHtml + foreach ($header in $headers) { + $checkPowershell = $header.OuterHtml - if ($CheckPowershell.Contains('Example')) { - $Result = $Header.InnerHtml - $A = $HeaderList.Add($Result) + if ($checkPowershell.Contains('Example')) { + $result = $header.InnerHtml + $HL = $HeaderList.Add($result) } } + Update-ExampleFile -GraphProfile $GraphProfile -HeaderList $HeaderList -ExampleList $ExampleList -ExampleFile $ExampleFile -Description $Description -Command $Command -ExternalDocUrl $ExternalDocUrl -UriPath $UriPath -Module $Module } @@ -296,7 +301,6 @@ function Update-ExampleFile { $SearchText = "Example" $SearchTextForNewImports = "{{ Add description here }}" $ReplaceEverything = $False - $ReplaceExistingexamples = $False if ($HeaderList.Count -eq 0) { for ($d = 0; $d -lt $ExampleList.Count; $d++) { $sum = $d + 1 @@ -314,6 +318,7 @@ function Update-ExampleFile { $ReplaceEverything = $True } + $HeadCount = $HeaderList.Count $ExampleCount = $ExampleList.Count $WrongExamplesCount = 0; @@ -334,127 +339,66 @@ function Update-ExampleFile { } } } - - #===========================Updating existing examples in files ============================================# - if (($Content | Select-String -pattern $SearchText)) { - $ReplaceExistingexamples = $True + $PatternToSearch = "Import-Module Microsoft.Graph.$Module" + if($GraphProfile -eq "beta"){ + $PatternToSearch = "Import-Module Microsoft.Graph.Beta.$Module" } - if ($ReplaceExistingexamples -and $exampleCount -gt 0 -and $headCount -eq $exampleCount) { - #Check existing file - $PatternToSearch = "Import-Module Microsoft.Graph.$Module" - if($HandWrittenCommands -contains $Command){ - $PatternToSearch = $Command + if(($Content | Select-String -pattern $SearchText) -and ($Content | Select-String -pattern "This example shows")){ + $ContainsPatternToSearch = $False + foreach($List in $ExampleList){ + if($List.Contains($PatternToSearch)){ + $ContainsPatternToSearch = $True + } } - $CommandExists = Select-String -Path $ExampleFile -Pattern $PatternToSearch - $NoOfExistingExampleHeaders = 0 - - foreach($Line in $Content){ - if($Line.Contains("### Example")){ - $NoOfExistingExampleHeaders++ - $r = $Available+=$Line.Split(":")[1] - } + if($ContainsPatternToSearch){ + Clear-Content $ExampleFile -Force + #Replace everything + for ($d = 0; $d -lt $HeaderList.Count; $d++) { + $CodeValue = $ExampleList[$d].Trim() + $TitleValue = "### " + $HeaderList[$d].Trim() + $Code = "``````powershell`r$CodeValue`r`n``````" + + $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" + Add-Content -Path $ExampleFile -Value $TotalText } - if($CommandExists){ - - $j = 1 - if($HandWrittenCommands -contains $Command){ - for ($d = 0; $d -lt $headerList.Count; $d++) { - $CodeValue = $ExampleList[$d].Trim() - if($CodeValue.Contains($Command)){ - $k = $NoOfExistingExampleHeaders + $j - $j - $TitleValue = "### " + $HeaderList[$d].Replace("Example $j", "Example $k").Trim() - $Code = "``````powershell`r$CodeValue`r`n``````" - - $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" - $SplittedTitleValue = $TitleValue.Split(":"); - - if(-not($Available.Contains($SplittedTitleValue[1]))){ - Add-Content -Path $ExampleFile -Value $TotalText - $j++ - } - - }else{ - $WrongExamplesCount++ - - } - } - }else{ + }else{ Clear-Content $ExampleFile -Force - for ($d = 0; $d -lt $HeaderList.Count; $d++) { - $CodeValue = $ExampleList[$d].Trim() - if($codeValue.Contains($Command)){ - $TitleValue = "### " + $HeaderList[$d].Trim() - $Code = "``````powershell`r$CodeValue`r`n``````" - - $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" - Add-Content -Path $ExampleFile -Value $TotalText - }else{ - $WrongExamplesCount++ - - } - } + #Replace everything with boiler plate code + $DefaultBoilerPlate = "### Example 1: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n### Example 2: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n" + Add-Content -Path $ExampleFile -Value $DefaultBoilerPlate.Trim() } - }else{ - - if($ExampleList.Contains($PatternToSearch)){ - Clear-Content $ExampleFile -Force - #Replace everything - for ($d = 0; $d -lt $HeaderList.Count; $d++) { - $CodeValue = $ExampleList[$d].Trim() - $TitleValue = "### " + $HeaderList[$d].Trim() - $Code = "``````powershell`r$CodeValue`r`n``````" - $TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n" - Add-Content -Path $ExampleFile -Value $TotalText - } - - }else{ - Clear-Content $ExampleFile -Force - #Replace everything with boiler plate code - $DefaultBoilerPlate = "### Example 1: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n### Example 2: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n" - Add-Content -Path $ExampleFile -Value $DefaultBoilerPlate.Trim() - } - } } - - if($WrongExamplesCount -gt 0){ - - + $DefaultBoilerPlate = "### Example 1: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n### Example 2: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n" + Add-Content -Path $ExampleFile -Value $DefaultBoilerPlate.Trim() #Log api path api version and equivalent external doc url giving wron examples + #Create folder and file if it doesn't exist + #The artifact below will be ignored on git. + #You can download the artificat from the generator pipeline - #Create file if it doesn't exist - if (-not (Test-Path $ExamplesToBeReviewed)) { - "Command, ExternalDocsUrl, ApiVersion, OpenApiPath" | Out-File -FilePath $ExamplesToBeReviewed -Encoding ASCII + if(-not(Test-Path -PathType Container $FolderForExamplesToBeReviewed)){ + New-Item -ItemType Directory -Force -Path $FolderForExamplesToBeReviewed + } + if (-not (Test-Path "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed")) { + "Command, ExternalDocsUrl, ApiVersion" | Out-File -FilePath "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed" -Encoding ASCII } - $File = Get-Content $ExamplesToBeReviewed + $File = Get-Content "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed" $containsWord = $File | % { $_ -match "$Command, $ExternalDocUrl, $GraphProfile, $UriPath" } - if ($containsWord -contains $true) { - #Skip adding to csv - } - else { - "$Command, $ExternalDocUrl, $GraphProfile, $UriPath" | Out-File -FilePath $ExamplesToBeReviewed -Append -Encoding ASCII + if (-not($containsWord -contains $true)) { + "$Command, $ExternalDocUrl, $GraphProfile, $UriPath" | Out-File -FilePath "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed" -Append -Encoding ASCII } } - # git config --global user.email "timwamalwa@gmail.com" - # git config --global user.name "Timothy Wamalwa" - # git add $ExampleFile - # git commit -m "Examples update on $ExampleFile-$GraphProfile" -} -Import-Csv $HandWrittenDocPath | -ForEach-Object{ - $HandWrittenCommands += $_.CmdletName -} + +} $JsonContent = Get-Content -Path $MetaDataJsonFile $DeserializedContent = $JsonContent | ConvertFrom-Json foreach($Data in $DeserializedContent) { if($Data.ApiVersion -eq "beta") - { - + { if((-not($Data.Variants[0].Contains("List")))){ $Beta = $BetaCommandGetVariantList.Add($Data.Command, $Data.Uri) }else{ @@ -488,23 +432,21 @@ if ($ModulesToGenerate.Count -eq 0) { [HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable $ModulesToGenerate = $ModuleMapping.Keys } - -#Start-Generator -ModulesToGenerate $ModulesToGenerate -GenerationMode "auto" -#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/directoryobject-getmembergroups?view=graph-rest-1.0" -GraphCommand "Get-MgApplicationMemberGroup" -GraphModule "Applications" -Profile "v1.0" -#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/application-addkey?view=graph-rest-1.0" -GraphCommand "Add-MgApplicationKey" -GraphModule "Applications" -Profile "v1.0" -#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl $null -GraphCommand "Remove-MgUserTodoListTask" -GraphModule "Users" -Profile "v1.0" - -#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/todo-list-lists?view=graph-rest-1.0" -GraphCommand "Get-MgUserTodoList" -GraphModule "Users" -Profile "v1.0" - -#-----------------------------------------------------------------------------# -# Test script for merging examples from api reference with handwritten commands -Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/user-get?view=graph-rest-1.0" -GraphCommand "Get-MgUser" -GraphModule "Users" -Profile "v1.0" - - +Start-Generator -ModulesToGenerate $ModulesToGenerate -GenerationMode "auto" #Comment the above and uncomment the below start command, if you manually want to manually pass ExternalDocs url. #This is for scenarios where the correponding external docs url to the uri path gotten from Find-MgGraph command, is missing on the openapi.yml file for a particular module. -#Ensure that you pass all correct parameters as oer the already existing example - +#Ensure that you pass all correct parameters as per the already existing example #Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/serviceprincipal-post-approleassignedto?view=graph-rest-1.0&tabs=http" -GraphCommand "New-MgServicePrincipalAppRoleAssignedTo" -GraphModule "Applications" -Profile "v1.0" -Write-Host -ForegroundColor Green "-------------Done-------------" + +#The below tests are ran manually. Comment the above Start-Generator with Generation mode set to auto and uncomment the below test +#---------------------------------------------------------------------------------------------------------------------------------# +#1. Test for making corrections and updating auto imported examples. I.e Examples that were not handwritten +#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/directoryobject-getmembergroups?view=graph-rest-beta" -GraphCommand "Get-MgBetaApplicationMemberGroup" -GraphModule "Applications" -Profile "beta" + +#2. Test for ensuring that a handwritten example is not tampered with +#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/user-get?view=graph-rest-1.0" -GraphCommand "Get-MgUser" -GraphModule "Users" -Profile "v1.0" + +#3. Test for updates from api reference +#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/serviceprincipal-post-approleassignedto?view=graph-rest-1.0" -GraphCommand "New-MgServicePrincipalAppRoleAssignedTo" -GraphModule "Applications" -Profile "v1.0" +Write-Host -ForegroundColor Green "-------------Done-------------" \ No newline at end of file From d156f74fb6c321f6c6694266772be5b7b9fc922b Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Mon, 22 May 2023 10:20:49 +0300 Subject: [PATCH 06/10] Deleted folder --- .../HandWrittenExamplesByContentDeveloper.csv | 105 ------------------ 1 file changed, 105 deletions(-) delete mode 100644 examplesreport/HandWrittenExamplesByContentDeveloper.csv diff --git a/examplesreport/HandWrittenExamplesByContentDeveloper.csv b/examplesreport/HandWrittenExamplesByContentDeveloper.csv deleted file mode 100644 index 76fa6991872..00000000000 --- a/examplesreport/HandWrittenExamplesByContentDeveloper.csv +++ /dev/null @@ -1,105 +0,0 @@ -CmdletName,ModuleName,ExampleCountV1,ExampleCountBeta -Add-MgApplicationPassword,Microsoft.Graph.Applications,2,2 -Get-MgApplication,Microsoft.Graph.Applications,5,5 -Get-MgGroupAppRoleAssignment,Microsoft.Graph.Applications,1,1 -Get-MgServicePrincipal,Microsoft.Graph.Applications,5,5 -Get-MgServicePrincipalAppRoleAssignment,Microsoft.Graph.Applications,1,1 -Get-MgServicePrincipalOwner,Microsoft.Graph.Applications,1,1 -Get-MgUserAppRoleAssignment,Microsoft.Graph.Applications,1,1 -New-MgApplication,Microsoft.Graph.Applications,1,1 -New-MgApplicationOwnerByRef,Microsoft.Graph.Applications,1,1 -New-MgGroupAppRoleAssignment,Microsoft.Graph.Applications,1,1 -New-MgServicePrincipal,Microsoft.Graph.Applications,1,1 -New-MgServicePrincipalOwnerByRef,Microsoft.Graph.Applications,1,1 -New-MgUserAppRoleAssignment,Microsoft.Graph.Applications,1,1 -Remove-MgApplication,Microsoft.Graph.Applications,1,1 -Remove-MgServicePrincipalAppRoleAssignment,Microsoft.Graph.Applications,1,1 -Remove-MgUserAppRoleAssignment,Microsoft.Graph.Applications,1,1 -Update-MgApplication,Microsoft.Graph.Applications,1,1 -Update-MgServicePrincipal,Microsoft.Graph.Applications,1,1 -Get-MgRoleManagementDirectoryRoleAssignmentSchedule,Microsoft.Graph.DeviceManagement.Enrolment,0,2 -Get-MgRoleManagementDirectoryRoleAssignmentScheduleInstance,Microsoft.Graph.DeviceManagement.Enrolment,0,2 -Get-MgRoleManagementDirectoryRoleAssignmentScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,2 -Get-MgRoleManagementDirectoryRoleEligibilitySchedule,Microsoft.Graph.DeviceManagement.Enrolment,0,2 -Get-MgRoleManagementDirectoryRoleEligibilityScheduleInstance,Microsoft.Graph.DeviceManagement.Enrolment,0,2 -Get-MgRoleManagementDirectoryRoleEligibilityScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,2 -New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,3 -New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest,Microsoft.Graph.DeviceManagement.Enrolment,0,3 -Get-MgGroup,Microsoft.Graph.Groups,5,5 -Get-MgGroupMember,Microsoft.Graph.Groups,1,1 -Get-MgGroupOwner,Microsoft.Graph.Groups,1,1 -New-MgGroup,Microsoft.Graph.Groups,1,1 -New-MgGroupMember,Microsoft.Graph.Groups,1,1 -New-MgGroupOwnerByRef,Microsoft.Graph.Groups,1,1 -Remove-MgGroup,Microsoft.Graph.Groups,1,1 -Update-MgGroup,Microsoft.Graph.Groups,1,1 -Get-MgContact,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Get-MgDirectoryDeletedItem,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Get-MgDirectoryRole,Microsoft.Graph.Identity.DirectoryManagement,2,2 -Get-MgDirectoryRoleMember,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Get-MgDomain,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Get-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Get-MgSubscribedSku,Microsoft.Graph.Identity.DirectoryManagement,1,1 -New-MgDirectoryRoleMemberByRef,Microsoft.Graph.Identity.DirectoryManagement,1,1 -New-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Remove-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Update-MgDomainFederationConfiguration,Microsoft.Graph.Identity.DirectoryManagement,1,1 -Get-MgAdministrativeUnit,Microsoft.Graph.Identity.DirectoryManagement,0,1 -Remove-MgAdministrativeUnit,Microsoft.Graph.Identity.DirectoryManagement,0,1 -Update-MgAdministrativeUnit,Microsoft.Graph.Identity.DirectoryManagement,0,1 -Get-MgEntitlementManagementAccessPackage,Microsoft.Graph.Identity.Governance,2,2 -Get-MgEntitlementManagementAccessPackageAssignmentPolicy,Microsoft.Graph.Identity.Governance,0,1 -Get-MgEntitlementManagementAccessPackageCatalog,Microsoft.Graph.Identity.Governance,0,2 -Get-MgEntitlementManagementSetting,Microsoft.Graph.Identity.Governance,1,1 -New-MgEntitlementManagementAccessPackage,Microsoft.Graph.Identity.Governance,1,1 -New-MgEntitlementManagementAccessPackageAssignmentPolicy,Microsoft.Graph.Identity.Governance,0,1 -Remove-MgEntitlementManagementAccessPackage,Microsoft.Graph.Identity.Governance,1,1 -Remove-MgEntitlementManagementAccessPackageAssignmentPolicy,Microsoft.Graph.Identity.Governance,0,1 -Get-MgEntitlementManagementAccessPackageAssignmentRequest,Microsoft.Graph.Identity.Governance,0,2 -Get-MgEntitlementManagementAccessPackageCatalogAccessPackageResource,Microsoft.Graph.Identity.Governance,0,2 -Get-MgEntitlementManagementAccessPackageCatalogAccessPackageResourceRole,Microsoft.Graph.Identity.Governance,0,2 -Get-MgEntitlementManagementAccessPackageResourceRequest,Microsoft.Graph.Identity.Governance,0,2 -New-MgEntitlementManagementAccessPackageAssignmentRequest,Microsoft.Graph.Identity.Governance,0,2 -New-MgEntitlementManagementAccessPackageResourceRequest,Microsoft.Graph.Identity.Governance,0,1 -New-MgEntitlementManagementAccessPackageResourceRoleScope,Microsoft.Graph.Identity.Governance,0,1 -Confirm-MgRiskyUserCompromised,Microsoft.Graph.Identity.SignIns,0,1 -Get-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,2,2 -Get-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,2,2 -Get-MgRiskDetection,Microsoft.Graph.Identity.SignIns,0,4 -Get-MgRiskyUser,Microsoft.Graph.Identity.SignIns,0,2 -Get-MgRiskyUserHistory,Microsoft.Graph.Identity.SignIns,0,2 -New-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,2,2 -New-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,2,2 -Remove-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,1,1 -Remove-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,1,1 -Update-MgIdentityConditionalAccessNamedLocation,Microsoft.Graph.Identity.SignIns,1,1 -Update-MgIdentityConditionalAccessPolicy,Microsoft.Graph.Identity.SignIns,1,1 -Get-MgUser,Microsoft.Graph.Users,6,6 -Get-MgUserCreatedObject,Microsoft.Graph.Users,1,1 -Get-MgUserDirectReport,Microsoft.Graph.Users,1,1 -Get-MgUserLicenseDetail,Microsoft.Graph.Users,1,1 -Get-MgUserManager,Microsoft.Graph.Users,1,1 -Get-MgUserPhoto,Microsoft.Graph.Users,1,1 -New-MgUser,Microsoft.Graph.Users,1,1 -Remove-MgUser,Microsoft.Graph.Users,2,2 -Set-MgUserManagerByRef,Microsoft.Graph.Users,1,1 -Update-MgUser,Microsoft.Graph.Users,1,1 -Set-MgUserLicense,Microsoft.Graph.Users.Actions,6,6 -New-MgInvitation,Microsoft.Graph.Identity.SignIns,2,0 -Get-MgUserOauth2PermissionGrant,Microsoft.Graph.Users,1,0 -Remove-MgUserManagerByRef,Microsoft.Graph.Users,1,0 -Get-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,2,2 -Get-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 -Get-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 -New-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,1,1 -New-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 -New-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 -Remove-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,1,1 -Remove-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 -Remove-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 -Update-MgPolicyPermissionGrantPolicy,Microsoft.Graph.Identity.SignIns,1,1 -Update-MgPolicyPermissionGrantPolicyExclude,Microsoft.Graph.Identity.SignIns,1,1 -Update-MgPolicyPermissionGrantPolicyInclude,Microsoft.Graph.Identity.SignIns,1,1 -New-MgEntitlementManagementAssignmentPolicy,Microsoft.Graph.Identity.Governance,1,0 -Get-MgEntitlementManagementCatalog,Microsoft.Graph.Identity.Governance,2,0 -Remove-MgEntitlementManagementAssignmentPolicy,Microsoft.Graph.Identity.Governance,1,0 From 6f45aaa42626717ec303d952cfb1f5a2e4a3ed9b Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Mon, 22 May 2023 10:22:02 +0300 Subject: [PATCH 07/10] Updated git ignore file --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24670b3a0b8..d379648302a 100644 --- a/.gitignore +++ b/.gitignore @@ -358,4 +358,7 @@ MigrationBackup/ .vscode/ #Custom Environment Files -localenv.json \ No newline at end of file +localenv.json + +#Wrong Examples report Folder +examplesreport/ \ No newline at end of file From 8be4ab268bf3f81b776dcdeb4fdfb0bb946b75ee Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Mon, 22 May 2023 10:24:23 +0300 Subject: [PATCH 08/10] corrected indentation --- config/ModulesMapping.jsonc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/ModulesMapping.jsonc b/config/ModulesMapping.jsonc index 2f654910a2a..81fdd5aa996 100644 --- a/config/ModulesMapping.jsonc +++ b/config/ModulesMapping.jsonc @@ -1,5 +1,5 @@ { - "Applications": "^applicationTemplates\\.|^applications\\.|^servicePrincipals\\.|^onPremisesPublishingProfiles\\.|^users.appRoleAssignment$|^groups.appRoleAssignment$", + "Applications": "^applicationTemplates\\.|^applications\\.|^servicePrincipals\\.|^onPremisesPublishingProfiles\\.|^users.appRoleAssignment$|^groups.appRoleAssignment$", "Bookings": "^solutions\\.|^bookingBusinesses\\.|^bookingCurrencies\\.", "Calendar": "^places\\.|^users.calendar$|^users.calendarGroup$|^users.event$|^groups.calendar$|^groups.event$", "ChangeNotifications": "^subscriptions\\.", @@ -33,7 +33,7 @@ "Search": "^search\\.|^external\\.", "Security": "^security\\.", "Sites": "^sites.site$|^sites.itemAnalytics$|^sites.columnDefinition$|^sites.contentType$|^sites.drive$|^sites.list$|^sites.sitePage$|^sites.permission$|^sites.store$|^users.site$|^groups.site$|^sites.Functions$|^sites.Actions$", - "Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$", + "Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$", "Users": "^users.user$|^users.directoryObject$|^users.licenseDetails$|^users.notification$|^users.outlookUser$|^users.profilePhoto$|^users.userSettings$|^users.extension$|^users.oAuth2PermissionGrant$|^users.todo$", "Users.Actions": "^users.Actions$", "Users.Functions": "^users.Functions$", From 1bb5052ff8ae124963c86125d5719ce5db011daf Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Mon, 22 May 2023 22:45:29 +0300 Subject: [PATCH 09/10] Reviewed script --- tools/ExamplesGenerator.ps1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/ExamplesGenerator.ps1 b/tools/ExamplesGenerator.ps1 index 7b7c9b72696..145ad222ae8 100644 --- a/tools/ExamplesGenerator.ps1 +++ b/tools/ExamplesGenerator.ps1 @@ -340,9 +340,6 @@ function Update-ExampleFile { } } $PatternToSearch = "Import-Module Microsoft.Graph.$Module" - if($GraphProfile -eq "beta"){ - $PatternToSearch = "Import-Module Microsoft.Graph.Beta.$Module" - } if(($Content | Select-String -pattern $SearchText) -and ($Content | Select-String -pattern "This example shows")){ $ContainsPatternToSearch = $False foreach($List in $ExampleList){ From ea45aa71922611546dc334022e5888a183877afe Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Tue, 23 May 2023 20:44:22 +0300 Subject: [PATCH 10/10] Renamed variables --- tools/ExamplesGenerator.ps1 | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tools/ExamplesGenerator.ps1 b/tools/ExamplesGenerator.ps1 index 145ad222ae8..ceafae2f28c 100644 --- a/tools/ExamplesGenerator.ps1 +++ b/tools/ExamplesGenerator.ps1 @@ -156,14 +156,14 @@ function Get-ExternalDocsUrl { $RebuiltPath = $PathRebuild + "microsoft.graph." + $PathToAppend $ExternalDocUrl = $path[$RebuiltPath].get.externalDocs.url if ([string]::IsNullOrEmpty($ExternalDocUrl)) { - $UriPath2 = $null + $GetPath = $null if($GraphProfile -eq "beta"){ - $UriPath2 = $BetaCommandListVariantList[$Command] + $GetPath = $BetaCommandListVariantList[$Command] }else{ - $UriPath2 = $V1CommandListVariantList[$Command] + $GetPath = $V1CommandListVariantList[$Command] } - if(-not([string]::IsNullOrEmpty($UriPath2))){ - $ExternalDocUrl = $Path[$UriPath2].get.externalDocs.url + if(-not([string]::IsNullOrEmpty($GetPath))){ + $ExternalDocUrl = $Path[$GetPath].get.externalDocs.url } } @@ -172,14 +172,14 @@ function Get-ExternalDocsUrl { if ($MethodName -eq "POST") { $ExternalDocUrl = $Path[$UriPath].post.externalDocs.url if ([string]::IsNullOrEmpty($ExternalDocUrl)) { - $UriPath3 = $null + $PostPath = $null if($GraphProfile -eq "beta"){ - $UriPath3 = $BetaCommandListVariantList[$Command] + $PostPath = $BetaCommandListVariantList[$Command] }else{ - $UriPath3 = $V1CommandListVariantList[$Command] + $PostPath = $V1CommandListVariantList[$Command] } - if(-not([string]::IsNullOrEmpty($UriPath3))){ - $ExternalDocUrl = $Path[$UriPath3].post.externalDocs.url + if(-not([string]::IsNullOrEmpty($PostPath))){ + $ExternalDocUrl = $Path[$PostPath].post.externalDocs.url } } } @@ -187,14 +187,14 @@ function Get-ExternalDocsUrl { if ($MethodName -eq "PATCH") { $ExternalDocUrl = $Path[$UriPath].patch.externalDocs.url if ([string]::IsNullOrEmpty($ExternalDocUrl)) { - $UriPath4 = $null + $PatchPath = $null if($GraphProfile -eq "beta"){ - $UriPath4 = $BetaCommandListVariantList[$Command] + $PatchPath = $BetaCommandListVariantList[$Command] }else{ - $UriPath4 = $V1CommandListVariantList[$Command] + $PatchPath = $V1CommandListVariantList[$Command] } - if(-not([string]::IsNullOrEmpty($UriPath4))){ - $ExternalDocUrl = $Path[$UriPath4].post.externalDocs.url + if(-not([string]::IsNullOrEmpty($PatchPath))){ + $ExternalDocUrl = $Path[$PatchPath].post.externalDocs.url } } } @@ -202,14 +202,14 @@ function Get-ExternalDocsUrl { if ($MethodName -eq "DELETE") { $ExternalDocUrl = $Path[$UriPath].delete.externalDocs.url if ([string]::IsNullOrEmpty($ExternalDocUrl)) { - $UriPath5 = $null + $DeletePath = $null if($GraphProfile -eq "beta"){ - $UriPath5 = $BetaCommandListVariantList[$Command] + $DeletePath = $BetaCommandListVariantList[$Command] }else{ - $UriPath5 = $V1CommandListVariantList[$Command] + $DeletePath = $V1CommandListVariantList[$Command] } - if(-not([string]::IsNullOrEmpty($UriPath5))){ - $ExternalDocUrl = $Path[$UriPath5].post.externalDocs.url + if(-not([string]::IsNullOrEmpty($DeletePath))){ + $ExternalDocUrl = $Path[$DeletePath].post.externalDocs.url } } } @@ -217,14 +217,14 @@ function Get-ExternalDocsUrl { if ($MethodName -eq "PUT") { $ExternalDocUrl = $Path[$UriPath].put.externalDocs.url if ([string]::IsNullOrEmpty($ExternalDocUrl)) { - $UriPath6 = $null + $PutPath = $null if($GraphProfile -eq "beta"){ - $UriPath6 = $BetaCommandListVariantList[$Command] + $PutPath = $BetaCommandListVariantList[$Command] }else{ - $UriPath6 = $V1CommandListVariantList[$Command] + $PutPath = $V1CommandListVariantList[$Command] } - if(-not([string]::IsNullOrEmpty($UriPath6))){ - $ExternalDocUrl = $Path[$UriPath6].post.externalDocs.url + if(-not([string]::IsNullOrEmpty($PutPath))){ + $ExternalDocUrl = $Path[$PutPath].post.externalDocs.url } } }