Skip to content

Commit be26e48

Browse files
committed
Used Find-MgGraph
1 parent f1c8bfc commit be26e48

File tree

2 files changed

+52
-136
lines changed

2 files changed

+52
-136
lines changed

scripts/MsProdUpdate.ps1

Lines changed: 48 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ Param(
77
[string] $SDKOpenApiPath = (Join-Path $PSScriptRoot "../../msgraph-sdk-powershell"),
88
[string] $WorkLoadDocsPath = (Join-Path $PSScriptRoot "../microsoftgraph"),
99
[string] $GraphDocsPath = (Join-Path $PSScriptRoot "../../microsoft-graph-docs"),
10-
[string] $MissingMsProdHeaderPath = (Join-Path $PSScriptRoot "../missingexternaldocsurl"),
11-
[hashtable]$V1CommandGetVariantList= @{},
12-
[hashtable]$BetaCommandGetVariantList= @{},
13-
[hashtable]$V1CommandListVariantList= @{},
14-
[hashtable]$BetaCommandListVariantList= @{}
10+
[string] $MissingMsProdHeaderPath = (Join-Path $PSScriptRoot "../missingexternaldocsurl")
1511
)
1612
function Get-GraphMapping {
1713
$graphMapping = @{}
@@ -49,7 +45,7 @@ function Get-FilesByProfile {
4945
[ValidateNotNullOrEmpty()]
5046
$ModulesToGenerate = @()
5147
)
52-
if($GraphProfile -eq "beta"){
48+
if ($GraphProfile -eq "beta") {
5349
$ModulePrefix = "Microsoft.Graph.Beta"
5450
}
5551

@@ -93,21 +89,15 @@ function Get-Files {
9389

9490
#Extract command over here
9591
$Command = [System.IO.Path]::GetFileNameWithoutExtension($File)
96-
#Extract URI path
97-
$CommandValue = $null
98-
if($GraphProfile -eq "beta"){
99-
$CommandValue = $BetaCommandGetVariantList[$Command]
100-
101-
}else{
102-
$CommandValue = $V1CommandGetVariantList[$Command]
103-
}
104-
105-
if ($CommandValue) {
106-
$CommandValueParams = $CommandValue.Split(",")
107-
$ApiPath = $CommandValueParams[0]
108-
$Method = $CommandValueParams[1]
109-
Get-ExternalDocsUrl -GraphProfile $GraphProfile -Url -UriPath $ApiPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method.Trim() -Module $Module
92+
#Extract URI path
93+
$CommandDetails = Find-MgGraphCommand -Command $Command
94+
if ($CommandDetails) {
95+
foreach ($CommandDetail in $CommandDetails) {
96+
$ApiPath = $CommandDetail.URI
97+
$Method = $CommandDetails.Method
98+
Get-ExternalDocsUrl -GraphProfile $GraphProfile -UriPath $ApiPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method.Trim() -Module $Module
11099
}
100+
}
111101

112102
}
113103
}
@@ -139,62 +129,58 @@ function Get-ExternalDocsUrl {
139129
if ($OpenApiContent.openapi && $OpenApiContent.info.version) {
140130
foreach ($Path in $OpenApiContent.paths) {
141131
$ExternalDocUrl = $null
142-
switch($Method){
132+
switch ($Method) {
143133
"GET" {
144134
$ExternalDocUrl = $path[$UriPath].get.externalDocs.url
145135
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
146-
$GETApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
147-
if(-not([string]::IsNullOrEmpty($GETApiPath))){
148-
$ExternalDocUrl = $Path[$GETApiPath].get.externalDocs.url
149-
}
136+
#Try with microsoft.graph prefix on the last path segment
137+
$UriPathWithGraphPrefix = Append-GraphPrefix -UriPath $UriPath
138+
$ExternalDocUrl = $path[$UriPathWithGraphPrefix].get.externalDocs.url
150139
}
151140
}
152141
"POST" {
153-
$ExternalDocUrl = $Path[$UriPath].post.externalDocs.url
142+
$ExternalDocUrl = $Path[$UriPath].post.externalDocs.url
154143
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
155-
$POSTApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
156-
if(-not([string]::IsNullOrEmpty($POSTApiPath))){
157-
$ExternalDocUrl = $Path[$POSTApiPath].post.externalDocs.url
158-
}
159-
}
144+
#Try with microsoft.graph prefix on the last path segment
145+
$UriPathWithGraphPrefix = Append-GraphPrefix -UriPath $UriPath
146+
$ExternalDocUrl = $path[$UriPathWithGraphPrefix].post.externalDocs.url
147+
}
160148
}
161149
"PATCH" {
162-
$ExternalDocUrl = $Path[$UriPath].patch.externalDocs.url
150+
$ExternalDocUrl = $Path[$UriPath].patch.externalDocs.url
163151
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
164-
$PATCHApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
165-
if(-not([string]::IsNullOrEmpty($PATCHApiPath))){
166-
$ExternalDocUrl = $Path[$PATCHApiPath].patch.externalDocs.url
167-
}
168-
}
152+
#Try with microsoft.graph prefix on the last path segment
153+
$UriPathWithGraphPrefix = Append-GraphPrefix -UriPath $UriPath
154+
$ExternalDocUrl = $path[$UriPathWithGraphPrefix].patch.externalDocs.url
155+
}
169156
}
170157
"DELETE" {
171158
$ExternalDocUrl = $Path[$UriPath].delete.externalDocs.url
172159
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
173-
$DELETEApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
174-
if(-not([string]::IsNullOrEmpty($DELETEApiPath))){
175-
$ExternalDocUrl = $Path[$DELETEApiPath].delete.externalDocs.url
176-
}
160+
#Try with microsoft.graph prefix on the last path segment
161+
$UriPathWithGraphPrefix = Append-GraphPrefix -UriPath $UriPath
162+
$ExternalDocUrl = $path[$UriPathWithGraphPrefix].delete.externalDocs.url
177163
}
178164
}
179165
"PUT" {
180166
$ExternalDocUrl = $Path[$UriPath].put.externalDocs.url
181167
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
182-
$PUTApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
183-
if(-not([string]::IsNullOrEmpty($PUTApiPath))){
184-
$ExternalDocUrl = $Path[$PUTApiPath].put.externalDocs.url
185-
}
186-
}
168+
#Try with microsoft.graph prefix on the last path segment
169+
$UriPathWithGraphPrefix = Append-GraphPrefix -UriPath $UriPath
170+
$ExternalDocUrl = $path[$UriPathWithGraphPrefix].put.externalDocs.url
171+
}
187172
}
188173

189174
}
190175
if (-not([string]::IsNullOrEmpty($ExternalDocUrl))) {
191176
WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ExternalDocUrl -Command $Command -File $File
192-
}else{
177+
}
178+
else {
193179
#Add report for missing external docs url
194180
#Version UriPath Command #Module
195181
$Folder = "$MissingMsProdHeaderPath\$Module"
196182
#Create folder if it doesn't exist
197-
if (-not (Test-Path $Folder)) {
183+
if (-not (Test-Path $Folder)) {
198184
New-Item -ItemType Directory -Force -Path $Folder
199185
}
200186
#Create file if it doesn't exist
@@ -219,21 +205,30 @@ function Get-ExternalDocsUrl {
219205
}
220206
}
221207
}
222-
223-
function Extract-PathFromListVariant{
208+
function Append-GraphPrefix {
209+
param(
210+
[string] $UriPath
211+
)
212+
$UriPathSegments = $UriPath.Split("/")
213+
$LastUriPathSegment = $UriPathSegments[$UriPathSegments.Length - 1]
214+
$UriPath = $UriPath.Replace($LastUriPathSegment, "microsoft.graph." + $LastUriPathSegment)
215+
return $UriPath
216+
}
217+
function Extract-PathFromListVariant {
224218
param(
225219
[ValidateSet("beta", "v1.0")]
226220
[string] $GraphProfile = "v1.0",
227221
[string] $Command = "Get-MgUser"
228222
)
229223
$ListApiPath = $null
230224
$ListCommandValue = $null
231-
if($GraphProfile -eq "beta"){
225+
if ($GraphProfile -eq "beta") {
232226
$ListCommandValue = $BetaCommandListVariantList[$Command]
233-
}else{
227+
}
228+
else {
234229
$ListCommandValue = $V1CommandListVariantList[$Command]
235230
}
236-
if(-not([string]::IsNullOrEmpty($ListCommandValue))){
231+
if (-not([string]::IsNullOrEmpty($ListCommandValue))) {
237232
$ListCommandValueParams = $ListCommandValue.Split(",")
238233
$ListApiPath = $ListCommandValueParams[0]
239234
}
@@ -300,31 +295,7 @@ else {
300295
Write-Host "Branch already exists"
301296
git checkout $proposedBranch
302297
}
303-
$MetaDataJsonFile = Join-Path $SDKDocsPath "Authentication" "Authentication" "custom" "common" "MgCommandMetadata.json"
304-
$JsonContent = Get-Content -Path $MetaDataJsonFile
305-
$DeserializedContent = $JsonContent | ConvertFrom-Json
306-
foreach($Data in $DeserializedContent)
307-
{
308-
if($Data.ApiVersion -eq "beta")
309-
{
310-
if((-not($Data.Variants[0].Contains("List")))){
311-
$BetaAPIPathAndMethod = $Data.Uri,$Data.Method -join ","
312-
$Beta = $BetaCommandGetVariantList.Add($Data.Command, $BetaAPIPathAndMethod)
313-
}else{
314-
$Beta1 = $BetaCommandListVariantList.Add($Data.Command, $BetaAPIPathAndMethod)
315-
}
316-
}
317298

318-
if($Data.ApiVersion -eq "v1.0")
319-
{
320-
$V1APIPathAndMethod = $Data.Uri,$Data.Method -join ","
321-
if((-not($Data.Variants[0].Contains("List")))){
322-
$V1 = $V1CommandGetVariantList.Add($Data.Command, $V1APIPathAndMethod)
323-
}else{
324-
$V11 = $V1CommandListVariantList.Add($Data.Command, $V1APIPathAndMethod)
325-
}
326-
}
327-
}
328299
if (!(Get-Module "powershell-yaml" -ListAvailable -ErrorAction SilentlyContinue)) {
329300
Install-Module "powershell-yaml" -AcceptLicense -Scope CurrentUser -Force
330301
}

scripts/UpdateLinks.ps1

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# Licensed under the MIT License.
33
Param(
44
$ModulesToGenerate = @(),
5-
[System.Collections.Generic.HashSet[string]]$V1CommandGetVariantList = @(),
6-
[System.Collections.Generic.HashSet[string]]$BetaCommandGetVariantList = @(),
7-
[System.Collections.Generic.HashSet[string]]$V1CommandListVariantList = @(),
8-
[System.Collections.Generic.HashSet[string]]$BetaCommandListVariantList = @(),
95
[string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "../microsoftgraph/config/ModulesMapping.jsonc"),
106
[string] $SDKDocsPath = (Join-Path $PSScriptRoot "../../msgraph-sdk-powershell/src"),
117
[string] $WorkLoadDocsPath = (Join-Path $PSScriptRoot "../microsoftgraph"),
@@ -86,37 +82,10 @@ function Get-Files {
8682
$Command = [System.IO.Path]::GetFileNameWithoutExtension($File)
8783

8884
if ($Command -ne $NonAllowedCommand[$NonAllowedCommand.Count - 1]) {
89-
if ($GraphProfile -eq "v1.0") {
90-
#Search for corresponding command on v1
91-
#Start with Get variant list
92-
$V1CommandFromGetVariant = $V1CommandGetVariantList.Contains($Command)
93-
if ($V1CommandFromGetVariant -ne $null) {
94-
Construct-Path -Command $Command -Module $Module
95-
}
96-
else {
97-
#Search from List variant
98-
$V1CommandFromListVariant = $V1CommandGetVariantList.Contains($Command)
99-
if ($V1CommandFromListVariant -ne $null) {
100-
Construct-Path -Command $Command -Module $Module
101-
}
102-
}
103-
}
104-
else {
105-
#Search for corresponding command on beta
106-
#Start with Get variant list
107-
$BetaCommandFromGetVariant = $BetaCommandGetVariantList.Contains($Command)
108-
if ($BetaCommandFromGetVariant -ne $null) {
109-
Construct-Path -Command $Command -Module $Module
110-
}
111-
else {
112-
#Search from List variant
113-
$BetaCommandFromListVariant = $BetaCommandGetVariantList.Contains($Command)
114-
if ($BetaCommandFromListVariant -ne $null) {
115-
Construct-Path -Command $Command -Module $Module
116-
}
117-
}
118-
}
119-
85+
$AvailableCommand = Find-MgGraphCommand -Command $Command
86+
if ($AvailableCommand) {
87+
Construct-Path -Command $Command -Module $Module
88+
}
12089
}
12190
}
12291
}
@@ -219,30 +188,6 @@ if ($ModulesToGenerate.Count -eq 0) {
219188
$ModulesToGenerate = $ModuleMapping.Keys
220189
}
221190

222-
$MetaDataJsonFile = Join-Path $SDKDocsPath "Authentication" "Authentication" "custom" "common" "MgCommandMetadata.json"
223-
$JsonContent = Get-Content -Path $MetaDataJsonFile
224-
$DeserializedContent = $JsonContent | ConvertFrom-Json
225-
foreach ($Data in $DeserializedContent) {
226-
if ($Data.ApiVersion -eq "beta") {
227-
228-
if (-not($Data.Variants[0].Contains("List"))) {
229-
$Beta = $V1CommandGetVariantList.Add($Data.Command)
230-
}
231-
else {
232-
$Beta1 = $V1CommandListVariantList.Add($Data.Command)
233-
}
234-
}
235-
236-
if ($Data.ApiVersion -eq "v1.0") {
237-
238-
if (-not($Data.Variants[0].Contains("List"))) {
239-
$V1 = $BetaCommandGetVariantList.Add($Data.Command)
240-
}
241-
else {
242-
$V11 = $BetaCommandListVariantList.Add($Data.Command)
243-
}
244-
}
245-
}
246191
Set-Location microsoftgraph-docs-powershell
247192
$date = Get-Date -Format "dd-MM-yyyy"
248193
$proposedBranch = "weekly_v2_docs_update_$date"

0 commit comments

Comments
 (0)