Skip to content

Commit 10644ef

Browse files
committed
Reviewed script by adding commands with corresponding path and method to the hash table
1 parent 7839708 commit 10644ef

File tree

1 file changed

+77
-94
lines changed

1 file changed

+77
-94
lines changed

tools/ExamplesGenerator.ps1

Lines changed: 77 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Start-Generator {
2424
)
2525

2626
$GraphMapping = @{
27-
"v1.0" = "examples\v1.0"
27+
#"v1.0" = "examples\v1.0"
2828
"beta" = "examples\v1.0-beta"
2929
}
3030
if ($GenerationMode -eq "auto") {
@@ -87,16 +87,19 @@ function Get-Files {
8787
#Extract command over here
8888
$Command = [System.IO.Path]::GetFileNameWithoutExtension($File)
8989
#Extract URI path
90-
$UriPath = $null
90+
$CommandValue = $null
9191
if($GraphProfile -eq "beta"){
92-
$UriPath = $BetaCommandGetVariantList[$Command]
92+
$CommandValue = $BetaCommandGetVariantList[$Command]
93+
9394
}else{
94-
$UriPath = $V1CommandGetVariantList[$Command]
95+
$CommandValue = $V1CommandGetVariantList[$Command]
9596
}
9697

97-
if ($UriPath) {
98-
$Method = $UriPaths.Method
99-
Get-ExternalDocsUrl -GraphProfile $GraphProfile -Url -UriPath $UriPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method -Module $Module
98+
if ($CommandValue) {
99+
$CommandValueParams = $CommandValue.Split(",")
100+
$ApiPath = $CommandValueParams[0]
101+
$Method = $CommandValueParams[1]
102+
Get-ExternalDocsUrl -GraphProfile $GraphProfile -Url -UriPath $ApiPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method.Trim() -Module $Module
100103
}
101104

102105
}
@@ -139,94 +142,54 @@ function Get-ExternalDocsUrl {
139142

140143
if ($OpenApiContent.openapi && $OpenApiContent.info.version) {
141144
foreach ($Path in $OpenApiContent.paths) {
142-
$MethodName = $Method | Out-String
143-
$ExternalDocUrl = $Path[$UriPath].values.externalDocs.url
144-
145-
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
146-
$PathSplit = $UriPath.Split("/")
147-
$PathToAppend = $PathSplit[$PathSplit.Count - 1]
148-
if ($PathToAppend.StartsWith("{") -or $PathToAppend.StartsWith("$")) {
149-
#skip
150-
}
151-
else {
152-
$PathRebuild = "/" + $PathSplit[0]
153-
for ($i = 1; $i -lt $PathSplit.Count - 1; $i++) {
154-
$PathRebuild += $PathSplit[$i] + "/"
145+
$ExternalDocUrl = $null
146+
switch($Method){
147+
"GET" {
148+
$ExternalDocUrl = $path[$UriPath].get.externalDocs.url
149+
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
150+
$GETApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
151+
if(-not([string]::IsNullOrEmpty($GETApiPath))){
152+
$ExternalDocUrl = $Path[$GETApiPath].get.externalDocs.url
153+
}
155154
}
156-
$RebuiltPath = $PathRebuild + "microsoft.graph." + $PathToAppend
157-
$ExternalDocUrl = $path[$RebuiltPath].get.externalDocs.url
155+
}
156+
"POST" {
157+
$ExternalDocUrl = $Path[$UriPath].post.externalDocs.url
158158
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
159-
$GetPath = $null
160-
if($GraphProfile -eq "beta"){
161-
$GetPath = $BetaCommandListVariantList[$Command]
162-
}else{
163-
$GetPath = $V1CommandListVariantList[$Command]
164-
}
165-
if(-not([string]::IsNullOrEmpty($GetPath))){
166-
$ExternalDocUrl = $Path[$GetPath].get.externalDocs.url
167-
}
168-
159+
$POSTApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
160+
if(-not([string]::IsNullOrEmpty($POSTApiPath))){
161+
$ExternalDocUrl = $Path[$POSTApiPath].post.externalDocs.url
162+
}
163+
}
164+
}
165+
"PATCH" {
166+
$ExternalDocUrl = $Path[$UriPath].patch.externalDocs.url
167+
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
168+
$PATCHApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
169+
if(-not([string]::IsNullOrEmpty($PATCHApiPath))){
170+
$ExternalDocUrl = $Path[$PATCHApiPath].patch.externalDocs.url
171+
}
169172
}
170173
}
171-
}
172-
if ($MethodName -eq "POST") {
173-
$ExternalDocUrl = $Path[$UriPath].post.externalDocs.url
174-
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
175-
$PostPath = $null
176-
if($GraphProfile -eq "beta"){
177-
$PostPath = $BetaCommandListVariantList[$Command]
178-
}else{
179-
$PostPath = $V1CommandListVariantList[$Command]
174+
"DELETE" {
175+
$ExternalDocUrl = $Path[$UriPath].delete.externalDocs.url
176+
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
177+
$DELETEApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
178+
if(-not([string]::IsNullOrEmpty($DELETEApiPath))){
179+
$ExternalDocUrl = $Path[$DELETEApiPath].delete.externalDocs.url
180+
}
180181
}
181-
if(-not([string]::IsNullOrEmpty($PostPath))){
182-
$ExternalDocUrl = $Path[$PostPath].post.externalDocs.url
183-
}
184-
}
185-
}
186-
187-
if ($MethodName -eq "PATCH") {
188-
$ExternalDocUrl = $Path[$UriPath].patch.externalDocs.url
189-
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
190-
$PatchPath = $null
191-
if($GraphProfile -eq "beta"){
192-
$PatchPath = $BetaCommandListVariantList[$Command]
193-
}else{
194-
$PatchPath = $V1CommandListVariantList[$Command]
195-
}
196-
if(-not([string]::IsNullOrEmpty($PatchPath))){
197-
$ExternalDocUrl = $Path[$PatchPath].post.externalDocs.url
198-
}
199-
}
200-
}
201-
202-
if ($MethodName -eq "DELETE") {
203-
$ExternalDocUrl = $Path[$UriPath].delete.externalDocs.url
204-
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
205-
$DeletePath = $null
206-
if($GraphProfile -eq "beta"){
207-
$DeletePath = $BetaCommandListVariantList[$Command]
208-
}else{
209-
$DeletePath = $V1CommandListVariantList[$Command]
210-
}
211-
if(-not([string]::IsNullOrEmpty($DeletePath))){
212-
$ExternalDocUrl = $Path[$DeletePath].post.externalDocs.url
213-
}
214-
}
215-
}
216-
217-
if ($MethodName -eq "PUT") {
218-
$ExternalDocUrl = $Path[$UriPath].put.externalDocs.url
219-
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
220-
$PutPath = $null
221-
if($GraphProfile -eq "beta"){
222-
$PutPath = $BetaCommandListVariantList[$Command]
223-
}else{
224-
$PutPath = $V1CommandListVariantList[$Command]
182+
}
183+
"PUT" {
184+
$ExternalDocUrl = $Path[$UriPath].put.externalDocs.url
185+
if ([string]::IsNullOrEmpty($ExternalDocUrl)) {
186+
$PUTApiPath = Extract-PathFromListVariant -GraphProfile $GraphProfile -Command $Command
187+
if(-not([string]::IsNullOrEmpty($PUTApiPath))){
188+
$ExternalDocUrl = $Path[$PUTApiPath].put.externalDocs.url
189+
}
225190
}
226-
if(-not([string]::IsNullOrEmpty($PutPath))){
227-
$ExternalDocUrl = $Path[$PutPath].post.externalDocs.url
228-
}
229-
}
191+
}
192+
230193
}
231194
if (-not([string]::IsNullOrEmpty($ExternalDocUrl))) {
232195
Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ExternalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath -Module $Module
@@ -238,6 +201,25 @@ function Get-ExternalDocsUrl {
238201
}
239202

240203
}
204+
function Extract-PathFromListVariant{
205+
param(
206+
[ValidateSet("beta", "v1.0")]
207+
[string] $GraphProfile = "v1.0",
208+
[string] $Command = "Get-MgUser"
209+
)
210+
$ListApiPath = $null
211+
$ListCommandValue = $null
212+
if($GraphProfile -eq "beta"){
213+
$ListCommandValue = $BetaCommandListVariantList[$Command]
214+
}else{
215+
$ListCommandValue = $V1CommandListVariantList[$Command]
216+
}
217+
if(-not([string]::IsNullOrEmpty($ListCommandValue))){
218+
$ListCommandValueParams = $ListCommandValue.Split(",")
219+
$ListApiPath = $ListCommandValueParams[0]
220+
}
221+
return $ListApiPath
222+
}
241223
function Start-WebScrapping {
242224
param(
243225
[ValidateSet("beta", "v1.0")]
@@ -397,19 +379,20 @@ foreach($Data in $DeserializedContent)
397379
if($Data.ApiVersion -eq "beta")
398380
{
399381
if((-not($Data.Variants[0].Contains("List")))){
400-
$Beta = $BetaCommandGetVariantList.Add($Data.Command, $Data.Uri)
382+
$BetaAPIPathAndMethod = $Data.Uri,$Data.Method -join ","
383+
$Beta = $BetaCommandGetVariantList.Add($Data.Command, $BetaAPIPathAndMethod)
401384
}else{
402-
$Beta1 = $BetaCommandListVariantList.Add($Data.Command, $Data.Uri)
385+
$Beta1 = $BetaCommandListVariantList.Add($Data.Command, $BetaAPIPathAndMethod)
403386
}
404387
}
405388

406389
if($Data.ApiVersion -eq "v1.0")
407390
{
408-
391+
$V1APIPathAndMethod = $Data.Uri,$Data.Method -join ","
409392
if((-not($Data.Variants[0].Contains("List")))){
410-
$V1 = $V1CommandGetVariantList.Add($Data.Command, $Data.Uri)
393+
$V1 = $V1CommandGetVariantList.Add($Data.Command, $V1APIPathAndMethod)
411394
}else{
412-
$V11 = $V1CommandListVariantList.Add($Data.Command, $Data.Uri)
395+
$V11 = $V1CommandListVariantList.Add($Data.Command, $V1APIPathAndMethod)
413396
}
414397
}
415398
}

0 commit comments

Comments
 (0)