7
7
[string ] $SDKOpenApiPath = (Join-Path $PSScriptRoot " ../../msgraph-sdk-powershell" ),
8
8
[string ] $WorkLoadDocsPath = (Join-Path $PSScriptRoot " ../microsoftgraph" ),
9
9
[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" )
15
11
)
16
12
function Get-GraphMapping {
17
13
$graphMapping = @ {}
@@ -49,7 +45,7 @@ function Get-FilesByProfile {
49
45
[ValidateNotNullOrEmpty ()]
50
46
$ModulesToGenerate = @ ()
51
47
)
52
- if ($GraphProfile -eq " beta" ){
48
+ if ($GraphProfile -eq " beta" ) {
53
49
$ModulePrefix = " Microsoft.Graph.Beta"
54
50
}
55
51
@@ -93,21 +89,15 @@ function Get-Files {
93
89
94
90
# Extract command over here
95
91
$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
110
99
}
100
+ }
111
101
112
102
}
113
103
}
@@ -139,62 +129,58 @@ function Get-ExternalDocsUrl {
139
129
if ($OpenApiContent.openapi && $OpenApiContent.info.version ) {
140
130
foreach ($Path in $OpenApiContent.paths ) {
141
131
$ExternalDocUrl = $null
142
- switch ($Method ){
132
+ switch ($Method ) {
143
133
" GET" {
144
134
$ExternalDocUrl = $path [$UriPath ].get.externalDocs.url
145
135
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
150
139
}
151
140
}
152
141
" POST" {
153
- $ExternalDocUrl = $Path [$UriPath ].post.externalDocs.url
142
+ $ExternalDocUrl = $Path [$UriPath ].post.externalDocs.url
154
143
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
+ }
160
148
}
161
149
" PATCH" {
162
- $ExternalDocUrl = $Path [$UriPath ].patch.externalDocs.url
150
+ $ExternalDocUrl = $Path [$UriPath ].patch.externalDocs.url
163
151
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
+ }
169
156
}
170
157
" DELETE" {
171
158
$ExternalDocUrl = $Path [$UriPath ].delete.externalDocs.url
172
159
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
177
163
}
178
164
}
179
165
" PUT" {
180
166
$ExternalDocUrl = $Path [$UriPath ].put.externalDocs.url
181
167
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
+ }
187
172
}
188
173
189
174
}
190
175
if (-not ([string ]::IsNullOrEmpty($ExternalDocUrl ))) {
191
176
WebScrapping - GraphProfile $GraphProfile - ExternalDocUrl $ExternalDocUrl - Command $Command - File $File
192
- }else {
177
+ }
178
+ else {
193
179
# Add report for missing external docs url
194
180
# Version UriPath Command #Module
195
181
$Folder = " $MissingMsProdHeaderPath \$Module "
196
182
# Create folder if it doesn't exist
197
- if (-not (Test-Path $Folder )) {
183
+ if (-not (Test-Path $Folder )) {
198
184
New-Item - ItemType Directory - Force - Path $Folder
199
185
}
200
186
# Create file if it doesn't exist
@@ -219,21 +205,30 @@ function Get-ExternalDocsUrl {
219
205
}
220
206
}
221
207
}
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 {
224
218
param (
225
219
[ValidateSet (" beta" , " v1.0" )]
226
220
[string ] $GraphProfile = " v1.0" ,
227
221
[string ] $Command = " Get-MgUser"
228
222
)
229
223
$ListApiPath = $null
230
224
$ListCommandValue = $null
231
- if ($GraphProfile -eq " beta" ){
225
+ if ($GraphProfile -eq " beta" ) {
232
226
$ListCommandValue = $BetaCommandListVariantList [$Command ]
233
- }else {
227
+ }
228
+ else {
234
229
$ListCommandValue = $V1CommandListVariantList [$Command ]
235
230
}
236
- if (-not ([string ]::IsNullOrEmpty($ListCommandValue ))){
231
+ if (-not ([string ]::IsNullOrEmpty($ListCommandValue ))) {
237
232
$ListCommandValueParams = $ListCommandValue.Split (" ," )
238
233
$ListApiPath = $ListCommandValueParams [0 ]
239
234
}
@@ -300,31 +295,7 @@ else {
300
295
Write-Host " Branch already exists"
301
296
git checkout $proposedBranch
302
297
}
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
- }
317
298
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
- }
328
299
if (! (Get-Module " powershell-yaml" - ListAvailable - ErrorAction SilentlyContinue)) {
329
300
Install-Module " powershell-yaml" - AcceptLicense - Scope CurrentUser - Force
330
301
}
0 commit comments