55 $Available = @ (),
66 [string ] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot " ..\config\ModulesMapping.jsonc" ),
77 [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"
109)
1110function Start-Generator {
1211 Param (
@@ -36,8 +35,7 @@ function Start-Generator {
3635 $ProfilePathMapping = " beta\examples"
3736 }
3837 $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
4139 }
4240}
4341function Get-FilesByProfile {
@@ -54,13 +52,7 @@ function Get-FilesByProfile {
5452 $ModulesToGenerate | ForEach-Object {
5553 $ModuleName = $_
5654 $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
6456 }
6557
6658}
@@ -71,8 +63,7 @@ function Get-Files {
7163 [ValidateNotNullOrEmpty ()]
7264 [string ] $GraphProfilePath = (Join-Path $PSScriptRoot " ..\src\Users\v1.0\examples" ),
7365 [ValidateNotNullOrEmpty ()]
74- [string ] $Module = " Users" ,
75- [Hashtable ] $OpenApiContent
66+ [string ] $Module = " Users"
7667 )
7768
7869 try {
@@ -82,22 +73,31 @@ function Get-Files {
8273
8374 # Extract command over here
8475 $Command = [System.IO.Path ]::GetFileNameWithoutExtension($File )
76+
8577 if ($Command -ine " README" ) {
8678 # 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+
9390 }
91+
92+
9493 }
9594 else {
9695 # Clear any content in that file as long as its not a readme file
9796 Clear-Content $File - Force
9897
9998 }
10099 }
100+
101101 }
102102 }
103103 }
@@ -108,96 +108,6 @@ function Get-Files {
108108 Write-Host " `n Error Item Name: " $_.Exception.ItemName
109109 }
110110
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-
201111}
202112
203113function Append-GraphPrefix {
0 commit comments