Fall back to JsonSchema4 if JsonSchema is unavailable
For some reason, it looks like the NJsonSchema library exports a NJsonSchema object if queried from .NET Core, but if queried from .NET Framework (Windows PowerShell) it exports a NJsonSchema4 object. From the same DLL. This is a workaround to fallback to NJsonSchema4 if NJsonSchema doesn't seem available, which makes the library work for Windows PowerShell.
This commit is contained in:
Родитель
c4567e4946
Коммит
203fa19e22
|
@ -44,17 +44,32 @@ try {
|
||||||
|
|
||||||
$script:schema = $null
|
$script:schema = $null
|
||||||
try {
|
try {
|
||||||
Write-Verbose "Loading JSON schema..."
|
Write-Verbose "Reading JSON schema..."
|
||||||
$script:schemaPath = Get-Content $PSScriptRoot\featureflags.schema.json
|
$script:schemaPath = Get-Content $PSScriptRoot\featureflags.schema.json
|
||||||
$script:schema = [NJsonSchema.JSonSchema]::FromJsonAsync($script:schemaPath).GetAwaiter().GetResult()
|
|
||||||
Write-Verbose "Loaded JSON schema from featureflags.schema.json."
|
|
||||||
Write-Verbose $script:schema
|
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "Error loading JSON schema"
|
Write-Error "Error reading JSON schema: $($_.Exception.Message)"
|
||||||
Write-Host $_.Exception.Message
|
|
||||||
throw
|
throw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Write-Verbose "Loading JSON schema..."
|
||||||
|
$script:schema = [NJsonSchema.JSonSchema]::FromJsonAsync($script:schemaPath).GetAwaiter().GetResult()
|
||||||
|
} catch {
|
||||||
|
$firstException = $_.Exception
|
||||||
|
# As a fallback, try reading using the JsonSchema4 object. The JSON schema library
|
||||||
|
# exposes that object to .NET Framework instead of JsonSchema for some reason.
|
||||||
|
try {
|
||||||
|
Write-Verbose "Loading JSON schema (fallback)..."
|
||||||
|
$script:schema = [NJsonSchema.JSonSchema4]::FromJsonAsync($script:schemaPath).GetAwaiter().GetResult()
|
||||||
|
} catch {
|
||||||
|
Write-Error "Error loading JSON schema: $($_.Exception.Message). First error: $($firstException.Message)."
|
||||||
|
Write-Host $_.Exception.Message
|
||||||
|
throw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Verbose "Loaded JSON schema from featureflags.schema.json."
|
||||||
|
Write-Verbose $script:schema
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Validates feature flag configuration.
|
Validates feature flag configuration.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче