-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathrun-metadata-validation.ps1
More file actions
52 lines (43 loc) · 2.31 KB
/
run-metadata-validation.ps1
File metadata and controls
52 lines (43 loc) · 2.31 KB
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
<#
.Synopsis
Runs MetadataParser tool to validate latest XSLT rules don't break downstream parsing of the metadata
.Description
1. tranforms latests snapshots of beta or v1 metadata
2. validates that the transformed metadata is parsable as OData EDM model and conversion to OpenAPI document is possible
.Example
./scripts/run-metadata-validation.ps1 -repoDirectory C:/github/msgraph-metadata -version "v1.0"
.Example
./scripts/run-metadata-validation.ps1 -repoDirectory $GITHUB_WORKSPACE -version "v1.0"
.Parameter repoDirectory
Full path the the root directory of msgraph-metadata checkout.
#>
param(
[Parameter(Mandatory=$true)][string]$repoDirectory,
[Parameter(Mandatory=$true)][string]$version,
[Parameter(Mandatory=$false)][string]$platformName
)
if([string]::IsNullOrWhiteSpace($platformName))
{
$platformName = "openapi"
}
$transformCsdlDirectory = Join-Path $repoDirectory "transforms/csdl"
$transformScript = Join-Path $transformCsdlDirectory "transform.ps1"
$xsltPath = Join-Path $transformCsdlDirectory "preprocess_csdl.xsl"
$conversionSettingsDirectory = Join-Path $repoDirectory "conversion-settings"
$snapshot = Join-Path $repoDirectory "schemas" "annotated-$($version)-Prod.csdl"
$transformed = Join-Path $repoDirectory "transformed_$($version)_metadata.xml"
$yamlFilePath = Join-Path $repoDirectory "transformed_$($version)_$($platformName)_metadata.yml"
try {
Write-Host "Tranforming $snapshot metadata using xslt with parameters used in the OpenAPI flow..." -ForegroundColor Green
& $transformScript -xslPath $xsltPath -inputPath $snapshot -outputPath $transformed -addInnerErrorDescription $true -removeCapabilityAnnotations $false -csdlVersion $version
Write-Host "Validating $transformed metadata after the transform..." -ForegroundColor Green
# pin the hidi version till odata to openApi conversion supports 2.0
& dotnet tool install --global Microsoft.OpenApi.Hidi --version 1.4.14
& hidi transform --cs $transformed -o $yamlFilePath --co -f Yaml --sp "$conversionSettingsDirectory/$platformName.json"
} catch {
Remove-Item $yamlFilePath -Force -ErrorAction SilentlyContinue -Verbose
Remove-Item $transformed -Force -ErrorAction SilentlyContinue -Verbose
throw
}