Skip to content

Commit 79ea06f

Browse files
committed
Ensured that atleast one correct example is maintained if the api returns a wrong example to an existing file with correct examples
1 parent f40960c commit 79ea06f

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

tools/ImportExamples.ps1

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,10 @@ function Update-ExampleFile {
370370

371371
}
372372
$CheckIfFileEmpty = Test-FileEmpty $ExampleFile
373-
Write-Host $ExampleFile
374373
if($CheckIfFileEmpty){
375-
Retain-ExistingCorrectExamples -Content $Content -File $ExampleFile
374+
if($Content){
375+
Retain-ExistingCorrectExamples -Content $Content -File $ExampleFile
376+
}
376377
}
377378
#----------------------------------------------------------------------------------------------#
378379
#The code below corrects the numbering of the example headers/title if there is a situation where
@@ -438,26 +439,29 @@ function Test-FileEmpty {
438439
function Retain-ExistingCorrectExamples {
439440

440441
Param ([Parameter(Mandatory = $true)][object]$Content,[Parameter(Mandatory = $true)][string]$File)
441-
442442
$CorrectMaintainableHeaderCount = 1;
443443
$LineCounter = 0;
444-
if($Content.Count -gt 0){
444+
$Header = $null
445445
foreach($Line in $Content){
446-
446+
447447
if($Line.StartsWith("$CommandPattern ")){
448-
$LineCounter++
449-
$Header = $Content[$LineCounter-1]
450-
if(($Null -eq $Header) -or ($Header -eq "")){
451-
$Header = "### Example " + $CorrectMaintainableHeaderCount + ": Code snippet"
452-
}
453-
$MaintainedCorrectExample = "$Header`r`n`n``````powershell`r`n$PatternToSearch`r`n`n$Line`r`n```````r`n$Description`r`n"
454448
$CorrectMaintainableHeaderCount++
455-
Add-Content -Path $File -Value $MaintainedCorrectExample
449+
break
456450
}
451+
$LineCounter++
452+
}
457453

454+
for($j = 0; $j -lt $LineCounter+1; $j++){
455+
$Val = $Content[$j]
456+
$Header+= "$Val`r`n"
458457
}
459-
}
460-
458+
if(($Null -eq $Header) -or ($Header -eq "")){
459+
$Header = "### Example " + $CorrectMaintainableHeaderCount + ": Code snippet"
460+
}
461+
462+
$MaintainedCorrectExample = "$Header`r`n```````r`n$Description`r`n"
463+
$CorrectMaintainableHeaderCount++
464+
Add-Content -Path $File -Value $MaintainedCorrectExample
461465
}
462466
$JsonContent = Get-Content -Path $MetaDataJsonFile
463467
$DeserializedContent = $JsonContent | ConvertFrom-Json
@@ -499,7 +503,7 @@ if ($ModulesToGenerate.Count -eq 0) {
499503
[HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable
500504
$ModulesToGenerate = $ModuleMapping.Keys
501505
}
502-
Start-Generator -ModulesToGenerate $ModulesToGenerate -GenerationMode "auto"
506+
#Start-Generator -ModulesToGenerate $ModulesToGenerate -GenerationMode "auto"
503507

504508
#Comment the above and uncomment the below start command, if you manually want to manually pass ExternalDocs url.
505509
#This is for scenarios where the correponding external docs url to the uri path gotten from Find-MgGraph command, is missing on the openapi.yml file for a particular module.
@@ -519,3 +523,4 @@ Start-Generator -ModulesToGenerate $ModulesToGenerate -GenerationMode "auto"
519523

520524
#4. Test for beta updates from api reference
521525
#Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/serviceprincipal-post-approleassignedto?view=graph-rest-beta" -GraphCommand "New-MgBetaServicePrincipalAppRoleAssignedTo" -GraphModule "Applications" -Profile "beta"
526+
Start-Generator -GenerationMode "manual" -ManualExternalDocsUrl "https://docs.microsoft.com/graph/api/meetingattendancereport-list?view=graph-rest-1.0" -GraphCommand "Update-MgBetaUserSettingShiftPreference" -GraphModule "Users" -Profile "beta"

0 commit comments

Comments
 (0)