|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Verify that the json files used to generate docs have the required members. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | +Given a doc repo location verify that the required members are in json |
| 7 | +metadata files. This does not verify for correctness, only that the required |
| 8 | +members exist within the file and are non-null. The required members are: |
| 9 | + Name |
| 10 | + Version |
| 11 | + ServiceDirectory |
| 12 | + SdkType |
| 13 | + IsNewSdk |
| 14 | +For Java only |
| 15 | + Group |
| 16 | +
|
| 17 | +.PARAMETER DocRepoLocation |
| 18 | +Location of the documentation repo. |
| 19 | +#> |
| 20 | + |
| 21 | +param ( |
| 22 | + [Parameter(Mandatory = $true)] |
| 23 | + [string] $DocRepoLocation # the location of the cloned doc repo |
| 24 | +) |
| 25 | + |
| 26 | +. (Join-Path $PSScriptRoot common.ps1) |
| 27 | +Set-StrictMode -Version 3 |
| 28 | + |
| 29 | +$script:FoundError = $false |
| 30 | + |
| 31 | +function Test-RequiredDocsJsonMembers($moniker) { |
| 32 | + |
| 33 | + $searchPath = Join-Path $DocRepoLocation 'metadata' $moniker |
| 34 | + Write-Host "Scanning json files in $searchPath" |
| 35 | + if (!(Test-Path $searchPath)) { |
| 36 | + return |
| 37 | + } |
| 38 | + $paths = Get-ChildItem -Path $searchPath -Filter *.json |
| 39 | + |
| 40 | + foreach ($path in $paths) { |
| 41 | + $fileContents = Get-Content $path -Raw |
| 42 | + $fileObject = ConvertFrom-Json -InputObject $fileContents |
| 43 | + |
| 44 | + if ($fileObject.PSObject.Members.Name -contains "Name") { |
| 45 | + if ($null -eq $fileObject.Name -or $fileObject.Name -eq "") { |
| 46 | + Write-Host "$path has a null or empty Name member. The Name member cannot be null or empty." |
| 47 | + $script:FoundError = $true |
| 48 | + } |
| 49 | + } else { |
| 50 | + Write-Host "$path is missing its Name member. The Name member must exist and cannot be null or empty." |
| 51 | + $script:FoundError = $true |
| 52 | + } |
| 53 | + |
| 54 | + if ($fileObject.PSObject.Members.Name -contains "Version") { |
| 55 | + if ($null -eq $fileObject.Version -or $fileObject.Version -eq "") { |
| 56 | + Write-Host "$path has a null or empty Version member. The Version member cannot be null or empty." |
| 57 | + $script:FoundError = $true |
| 58 | + } |
| 59 | + } else { |
| 60 | + Write-Host "$path is missing its Version member. The Version member must exist and cannot be null or empty." |
| 61 | + $script:FoundError = $true |
| 62 | + } |
| 63 | + |
| 64 | + if ($fileObject.PSObject.Members.Name -contains "ServiceDirectory") { |
| 65 | + if ($null -eq $fileObject.ServiceDirectory -or $fileObject.ServiceDirectory -eq "") { |
| 66 | + Write-Host "$path has a null or empty ServiceDirectory member. If the ServiceDirectory is unknown please use ""NA""" |
| 67 | + $script:FoundError = $true |
| 68 | + } |
| 69 | + } else { |
| 70 | + Write-Host "$path is missing its ServiceDirectory member. If the ServiceDirectory is unknown please use ""NA""." |
| 71 | + $script:FoundError = $true |
| 72 | + } |
| 73 | + |
| 74 | + if ($fileObject.PSObject.Members.Name -contains "SdkType") { |
| 75 | + if ($null -eq $fileObject.SdkType -or $fileObject.SdkType -eq "") { |
| 76 | + Write-Host "$path has a null or empty SdkType member. If the SdkType is unknwon please use ""NA""." |
| 77 | + $script:FoundError = $true |
| 78 | + } |
| 79 | + } else { |
| 80 | + Write-Host "$path is missing its SdkType member. If the SdkType is unknwon please use ""NA""." |
| 81 | + $script:FoundError = $true |
| 82 | + } |
| 83 | + |
| 84 | + if ($fileObject.PSObject.Members.Name -contains "IsNewSdk") { |
| 85 | + # IsNewSdk is a boolean, no empty string check necessary |
| 86 | + if ($null -eq $fileObject.IsNewSdk) { |
| 87 | + Write-Host "$path has a null IsNewSdk member which must be true or false." |
| 88 | + } |
| 89 | + } else { |
| 90 | + Write-Host "$path is missing its IsNewSdk member which must be true or false." |
| 91 | + $script:FoundError = $true |
| 92 | + } |
| 93 | + |
| 94 | + if ($Language -eq "java") { |
| 95 | + if ($fileObject.PSObject.Members.Name -contains "Group") |
| 96 | + { |
| 97 | + if ($null -eq $fileObject.Group -or $fileObject.Group -eq "") { |
| 98 | + Write-Host "$path has an null or empty Group member. The Group member cannot be null or empty." |
| 99 | + $script:FoundError = $true |
| 100 | + } |
| 101 | + } else { |
| 102 | + Write-Host "$path is missing its Group member. The Group member must exist and cannot be null or empty." |
| 103 | + $script:FoundError = $true |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +Test-RequiredDocsJsonMembers 'latest' |
| 110 | +Test-RequiredDocsJsonMembers 'preview' |
| 111 | + |
| 112 | +if ($script:FoundError) |
| 113 | +{ |
| 114 | + LogError "There were missing or empty members docs metadata json files. Please see above for specifics.` |
| 115 | +The missing entries were either the result of the MsToc update or were directly checked into the repository." |
| 116 | + exit 1 |
| 117 | +} |
| 118 | + |
| 119 | +Write-Host "The json files appear to contain the required members." |
| 120 | +exit 0 |
0 commit comments