5
5
$Available = @ (),
6
6
[string ] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot " ..\config\ModulesMapping.jsonc" ),
7
7
[string ] $FolderForExamplesToBeReviewed = (Join-Path $PSScriptRoot " ..\examplesreport" ),
8
- [string ] $ExamplesToBeReviewed = " ExamplesToBeReviewed.csv" ,
9
- $MetaDataJsonFile = (Join-Path $PSScriptRoot " ../src/Authentication/Authentication/custom/common/MgCommandMetadata.json" )
8
+ [string ] $ExamplesToBeReviewed = " ExamplesToBeReviewed.csv"
10
9
)
11
10
function Start-Generator {
12
11
Param (
@@ -36,8 +35,7 @@ function Start-Generator {
36
35
$ProfilePathMapping = " beta\examples"
37
36
}
38
37
$ModulePath = Join-Path $PSScriptRoot " ..\src\$GraphModule \$ProfilePathMapping "
39
- Get-ExternalDocsUrl - ManualExternalDocsUrl $ManualExternalDocsUrl - GenerationMode $GenerationMode - GraphProfilePath $ModulePath - Command $GraphCommand - GraphProfile $ProfilePath - Module $GraphModule
40
-
38
+ Start-WebScrapping - GraphProfile $GraphProfile - ExternalDocUrl $ManualExternalDocsUrl - Command $GraphCommand - GraphProfilePath $ModulePath - Module $GraphModule
41
39
}
42
40
}
43
41
function Get-FilesByProfile {
@@ -54,13 +52,7 @@ function Get-FilesByProfile {
54
52
$ModulesToGenerate | ForEach-Object {
55
53
$ModuleName = $_
56
54
$ModulePath = Join-Path $PSScriptRoot " ..\src\$ModuleName \$GraphProfilePath "
57
- $OpenApiFile = Join-Path $PSScriptRoot " ..\openApiDocs\v1.0\$ModuleName .yml"
58
- # test this path first before proceeding
59
- if (Test-Path $OpenApiFile ) {
60
- $yamlContent = Get-Content - Path $OpenApiFile
61
- $OpenApiContent = ($yamlContent | ConvertFrom-Yaml )
62
- Get-Files - GraphProfile $GraphProfile - GraphProfilePath $modulePath - Module $ModuleName - OpenApiContent $OpenApiContent
63
- }
55
+ Get-Files - GraphProfile $GraphProfile - GraphProfilePath $modulePath - Module $ModuleName
64
56
}
65
57
66
58
}
@@ -71,8 +63,7 @@ function Get-Files {
71
63
[ValidateNotNullOrEmpty ()]
72
64
[string ] $GraphProfilePath = (Join-Path $PSScriptRoot " ..\src\Users\v1.0\examples" ),
73
65
[ValidateNotNullOrEmpty ()]
74
- [string ] $Module = " Users" ,
75
- [Hashtable ] $OpenApiContent
66
+ [string ] $Module = " Users"
76
67
)
77
68
78
69
try {
@@ -82,22 +73,31 @@ function Get-Files {
82
73
83
74
# Extract command over here
84
75
$Command = [System.IO.Path ]::GetFileNameWithoutExtension($File )
76
+
85
77
if ($Command -ine " README" ) {
86
78
# Extract URI path
87
- $CommandDetails = Find-MgGraphCommand - Command $Command
88
- if ($CommandDetails ) {
89
- foreach ($CommandDetail in $CommandDetails ) {
90
- $ApiPath = $CommandDetail.URI
91
- $Method = $CommandDetails.Method
92
- Get-ExternalDocsUrl - GraphProfile $GraphProfile - UriPath $ApiPath - Command $Command - OpenApiContent $OpenApiContent - GraphProfilePath $GraphProfilePath - Method $Method.Trim () - Module $Module
79
+ $ApiRefLinks = (Find-MgGraphCommand - Command $Command ).ApiReferenceLink
80
+
81
+ if ($ApiRefLinks ) {
82
+ foreach ($ApiRefLink in $ApiRefLinks ) {
83
+
84
+
85
+ if (-not ($null -eq $ApiRefLink -or $ApiRefLink -eq " " )) {
86
+ $ExternalDocsUrl = $ApiRefLink + " &tabs=powershell"
87
+ Start-WebScrapping - GraphProfile $GraphProfile - ExternalDocUrl $ExternalDocsUrl - Command $Command - GraphProfilePath $GraphProfilePath - UriPath $UriPath - Module $Module
88
+ }
89
+
93
90
}
91
+
92
+
94
93
}
95
94
else {
96
95
# Clear any content in that file as long as its not a readme file
97
96
Clear-Content $File - Force
98
97
99
98
}
100
99
}
100
+
101
101
}
102
102
}
103
103
}
@@ -108,96 +108,6 @@ function Get-Files {
108
108
Write-Host " `n Error Item Name: " $_.Exception.ItemName
109
109
}
110
110
111
- }
112
- function Get-ExternalDocsUrl {
113
-
114
- param (
115
- [ValidateSet (" beta" , " v1.0" )]
116
- [string ] $GraphProfile = " v1.0" ,
117
- [string ] $UriPath ,
118
- [string ] $Module = " Users" ,
119
- [string ] $GenerationMode = " auto" ,
120
- [string ] $ManualExternalDocsUrl ,
121
- [ValidateNotNullOrEmpty ()]
122
- [string ] $Command = " Get-MgUser" ,
123
- [Hashtable ] $OpenApiContent ,
124
- [System.Object ] $Method = " GET" ,
125
- [string ] $GraphProfilePath = (Join-Path $PSScriptRoot " ..\src\Users\v1.0\examples" )
126
- )
127
- if ($GenerationMode -eq " manual" ) {
128
-
129
- if (-not ([string ]::IsNullOrEmpty($ManualExternalDocsUrl ))) {
130
-
131
- Start-WebScrapping - GraphProfile $GraphProfile - ExternalDocUrl $ManualExternalDocsUrl - Command $Command - GraphProfilePath $GraphProfilePath - UriPath $UriPath - Module $Module
132
- }
133
-
134
- }
135
- else {
136
- if ($UriPath ) {
137
-
138
- if ($OpenApiContent.openapi && $OpenApiContent.info.version ) {
139
- foreach ($Path in $OpenApiContent.paths ) {
140
- $ExternalDocUrl = $null
141
- switch ($Method ) {
142
- " GET" {
143
- $ExternalDocUrl = $path [$UriPath ].get.externalDocs.url
144
- if ([string ]::IsNullOrEmpty($ExternalDocUrl )) {
145
- # Try with microsoft.graph prefix on the last path segment
146
- $UriPathWithGraphPrefix = Append- GraphPrefix - UriPath $UriPath
147
- $ExternalDocUrl = $path [$UriPathWithGraphPrefix ].get.externalDocs.url
148
- }
149
- }
150
- " POST" {
151
- $ExternalDocUrl = $Path [$UriPath ].post.externalDocs.url
152
- if ([string ]::IsNullOrEmpty($ExternalDocUrl )) {
153
- # Try with microsoft.graph prefix on the last path segment
154
- $UriPathWithGraphPrefix = Append- GraphPrefix - UriPath $UriPath
155
- $ExternalDocUrl = $path [$UriPathWithGraphPrefix ].post.externalDocs.url
156
- }
157
- }
158
- " PATCH" {
159
- $ExternalDocUrl = $Path [$UriPath ].patch.externalDocs.url
160
- if ([string ]::IsNullOrEmpty($ExternalDocUrl )) {
161
- # Try with microsoft.graph prefix on the last path segment
162
- $UriPathWithGraphPrefix = Append- GraphPrefix - UriPath $UriPath
163
- $ExternalDocUrl = $path [$UriPathWithGraphPrefix ].patch.externalDocs.url
164
- }
165
- }
166
- " DELETE" {
167
- $ExternalDocUrl = $Path [$UriPath ].delete.externalDocs.url
168
- if ([string ]::IsNullOrEmpty($ExternalDocUrl )) {
169
- # Try with microsoft.graph prefix on the last path segment
170
- $UriPathWithGraphPrefix = Append- GraphPrefix - UriPath $UriPath
171
- $ExternalDocUrl = $path [$UriPathWithGraphPrefix ].delete.externalDocs.url
172
- }
173
- }
174
- " PUT" {
175
- $ExternalDocUrl = $Path [$UriPath ].put.externalDocs.url
176
- if ([string ]::IsNullOrEmpty($ExternalDocUrl )) {
177
- # Try with microsoft.graph prefix on the last path segment
178
- $UriPathWithGraphPrefix = Append- GraphPrefix - UriPath $UriPath
179
- $ExternalDocUrl = $path [$UriPathWithGraphPrefix ].put.externalDocs.url
180
- }
181
- }
182
-
183
- }
184
- if (-not ([string ]::IsNullOrEmpty($ExternalDocUrl ))) {
185
- Start-WebScrapping - GraphProfile $GraphProfile - ExternalDocUrl $ExternalDocUrl - Command $Command - GraphProfilePath $GraphProfilePath - UriPath $UriPath - Module $Module
186
- }
187
- else {
188
- # This step will still correct the examples if the external docs url is not found.
189
- $ExampleFile = " $GraphProfilePath /$Command .md"
190
- $boilerPlateCode = Select-String - Path $File - Pattern " Add title here"
191
- if ($boilerPlateCode.Length -eq 0 ){
192
- Retain- ExistingCorrectExamples - Content (Get-Content $ExampleFile ) - File $ExampleFile - CommandPattern $Command
193
- }
194
- }
195
- }
196
-
197
- }
198
- }
199
- }
200
-
201
111
}
202
112
203
113
function Append-GraphPrefix {
0 commit comments