File: Verify-RequiredDocsJsonMembers.ps1

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (130 lines) | stat: -rw-r--r-- 4,708 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<#
.SYNOPSIS
Verify that the json files used to generate docs have the required members.

.DESCRIPTION
Given a doc repo location verify that the required members are in json
metadata files. This does not verify for correctness, only that the required
members exist within the file and are non-null. The required members are:
  Name
  Version
  ServiceDirectory
  SdkType
  IsNewSdk
For Java only
  Group

.PARAMETER DocRepoLocation
Location of the documentation repo.
#>

param (
  [Parameter(Mandatory = $true)]
  [string] $DocRepoLocation # the location of the cloned doc repo
)

. (Join-Path $PSScriptRoot common.ps1)
Set-StrictMode -Version 3

$script:FoundError = $false

function Test-RequiredDocsJsonMembers($moniker) {

  $searchPath = Join-Path $DocRepoLocation 'metadata' $moniker
  Write-Host "Scanning json files in $searchPath"
  if (!(Test-Path $searchPath)) {
    return
  }
  $paths = Get-ChildItem -Path $searchPath -Filter *.json

  foreach ($path in $paths) {
    $fileContents = Get-Content $path -Raw
    $fileObject = ConvertFrom-Json -InputObject $fileContents

    if ($fileObject.PSObject.Members.Name -contains "Name") {
      if ($null -eq $fileObject.Name -or $fileObject.Name -eq "") {
        Write-Host "$path has a null or empty Name member. The Name member cannot be null or empty."
        $script:FoundError = $true
      }
    } else {
      Write-Host "$path is missing its Name member. The Name member must exist and cannot be null or empty."
      $script:FoundError = $true
    }

    if ($fileObject.PSObject.Members.Name -contains "Version") {
      if ($null -eq $fileObject.Version -or $fileObject.Version -eq "") {
        Write-Host "$path has a null or empty Version member. The Version member cannot be null or empty."
        $script:FoundError = $true
      }
    } else {
      Write-Host "$path is missing its Version member. The Version member must exist and cannot be null or empty."
      $script:FoundError = $true
    }

    if ($fileObject.PSObject.Members.Name -contains "ServiceDirectory") {
      if ($null -eq $fileObject.ServiceDirectory -or $fileObject.ServiceDirectory -eq "") {
        Write-Host "$path has a null or empty ServiceDirectory member. If the ServiceDirectory is unknown please use ""NA"""
        $script:FoundError = $true
      }
    } else {
      Write-Host "$path is missing its ServiceDirectory member. If the ServiceDirectory is unknown please use ""NA""."
      $script:FoundError = $true
    }

    if ($fileObject.PSObject.Members.Name -contains "SdkType") {
      if ($null -eq $fileObject.SdkType -or $fileObject.SdkType -eq "") {
        Write-Host "$path has a null or empty SdkType member. If the SdkType is unknwon please use ""NA""."
        $script:FoundError = $true
      }
    } else {
      Write-Host "$path is missing its SdkType member. If the SdkType is unknwon please use ""NA""."
      $script:FoundError = $true
    }

    if ($fileObject.PSObject.Members.Name -contains "IsNewSdk") {
      # IsNewSdk is a boolean, no empty string check necessary
      if ($null -eq $fileObject.IsNewSdk) {
        Write-Host "$path has a null IsNewSdk member which must be true or false."
      }
    } else {
      Write-Host "$path is missing its IsNewSdk member which must be true or false."
      $script:FoundError = $true
    }

    if ($fileObject.PSObject.Members.Name -contains 'DirectoryPath') {
      if ($null -eq $fileObject.DirectoryPath) { 
        Write-Host "$path has a null DirectoryPath member. If the DirectoryPath is unknown please use the value `"`"."
        $script:FoundError = $true
      }
    } else { 
      Write-Host "$path is missing its DirectoryPath member. If the DirectoryPath is unknown please use the value `"`"."
      $script:FoundError = $true
    }

    if ($Language -eq "java") {
      if ($fileObject.PSObject.Members.Name -contains "Group")
      {
        if ($null -eq $fileObject.Group -or $fileObject.Group -eq "") {
          Write-Host "$path has an null or empty Group member. The Group member cannot be null or empty."
          $script:FoundError = $true
        }
      } else {
        Write-Host "$path is missing its Group member. The Group member must exist and cannot be null or empty."
        $script:FoundError = $true
      }
    }
  }
}

Test-RequiredDocsJsonMembers 'latest'
Test-RequiredDocsJsonMembers 'preview'

if ($script:FoundError)
{
  LogError "There were missing or empty members docs metadata json files. Please see above for specifics.`
The missing entries were either the result of the MsToc update or were directly checked into the repository."
  exit 1
}

Write-Host "The json files appear to contain the required members."
exit 0