Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Test-Json.Tests.ps1542 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Test-Json" -Tags "CI" {5    BeforeAll {6        $assetsPath = Join-Path $PSScriptRoot -ChildPath assets7        $validSchemaJsonPath = Join-Path -Path $assetsPath -ChildPath valid_schema_reference.json8        $invalidSchemaJsonPath = Join-Path -Path $assetsPath -ChildPath invalid_schema_reference.json9        $missingSchemaJsonPath = Join-Path -Path $assetsPath -ChildPath no_such_file.json10        $missingJsonPath = Join-Path -Path $assetsPath -ChildPath no_such_file.json11 12        $validSchemaJson = @'13            {14            "description": "A person",15            "type": "object",16            "properties": {17                "name": {"type": "string"},18                "hobbies": {19                "type": "array",20                "items": {"type": "string"}21                }22                }23            }24'@25 26        $invalidSchemaJson = @'27            {28            "description",29            "type": "object",30            "properties": {31                "name": {"type": "string"},32                "hobbies": {33                "type": "array",34                "items": {"type": "string"}35                }36                }37            }38'@39 40        $validJson = @'41            {42                "name": "James",43                "hobbies": [".NET", "Blogging", "Reading", "Xbox", "LOLCATS"]44            }45'@46 47        $invalidTypeInJson = @'48            {49                "name": 123,50                "hobbies": [".NET", "Blogging", "Reading", "Xbox", "LOLCATS"]51            }52'@53 54        $invalidTypeInJson2 = @'55            {56                "name": 123,57                "hobbies": [456, "Blogging", "Reading", "Xbox", "LOLCATS"]58            }59'@60 61        $invalidNodeInJson = @'62            {63                "name": "James",64                "hobbies": [".NET", "Blogging", "Reading", "Xbox", "LOLCATS"]65                errorNode66            }67'@68 69        $jsonWithComments = @'70            {71                // A Json comment72                "string": "test"73            }74'@75 76        $jsonWithTrailingComma = @'77            {78                "string": "test",79            }80'@81 82        $jsonWithCommentsAndTrailingComma = @'83            {84                // A Json comment85                "string": "test",86            }87'@88 89        # Schema using oneOf to allow either integer or string pattern for port items90        $oneOfSchema = @'91            {92                "type": "object",93                "properties": {94                    "ports": {95                        "type": "array",96                        "items": {97                            "oneOf": [98                                { "type": "integer", "minimum": 0, "maximum": 65535 },99                                { "type": "string", "pattern": "^\\d+-\\d+$" }100                            ]101                        }102                    }103                }104            }105'@106 107        # Valid JSON where ports are integers (first oneOf choice matches)108        $validOneOfJson = '{ "ports": [80, 443, 8080] }'109 110        # Invalid JSON where a port value matches neither oneOf choice111        $invalidOneOfJson = '{ "ports": [80, "invalid-port", 8080] }'112 113        # Schema using oneOf to allow either smartphone or laptop device types114        $oneOfDeviceSchema = @'115            {116                "type": "object",117                "properties": {118                    "Devices": {119                        "type": "array",120                        "items": {121                            "type": "object",122                            "oneOf": [123                                {124                                    "properties": {125                                        "id": { "type": "string" },126                                        "deviceType": { "const": "smartphone" },127                                        "os": { "type": "string", "enum": ["iOS", "Android"] }128                                    },129                                    "required": ["deviceType", "os"]130                                },131                                {132                                    "properties": {133                                        "id": { "type": "string" },134                                        "deviceType": { "const": "laptop" },135                                        "arch": { "type": "string", "enum": ["x86", "x64", "arm64"] }136                                    },137                                    "required": ["deviceType", "arch"]138                                }139                            ]140                        }141                    }142                },143                "required": ["Devices"]144            }145'@146 147        # Valid JSON with mixed device types (all matching their respective oneOf choice)148        $validOneOfDeviceJson = @'149            {150                "Devices": [151                    { "id": "0", "deviceType": "laptop", "arch": "x64" },152                    { "id": "1", "deviceType": "smartphone", "os": "iOS" },153                    { "id": "2", "deviceType": "laptop", "arch": "arm64" },154                    { "id": "3", "deviceType": "smartphone", "os": "Android" }155                ]156            }157'@158 159        # Invalid JSON where only Devices/3 has an invalid os value160        $invalidOneOfDeviceJson = @'161            {162                "Devices": [163                    { "id": "0", "deviceType": "laptop", "arch": "x64" },164                    { "id": "1", "deviceType": "smartphone", "os": "iOS" },165                    { "id": "2", "deviceType": "laptop", "arch": "arm64" },166                    { "id": "3", "deviceType": "smartphone", "os": "WindowsPhone" }167                ]168            }169'@170 171        # Schema using anyOf to allow either smartphone or laptop device types172        $anyOfDeviceSchema = @'173            {174                "type": "object",175                "properties": {176                    "Devices": {177                        "type": "array",178                        "items": {179                            "type": "object",180                            "anyOf": [181                                {182                                    "properties": {183                                        "deviceType": { "const": "smartphone" },184                                        "os": { "type": "string", "enum": ["iOS", "Android"] }185                                    },186                                    "required": ["deviceType", "os"]187                                },188                                {189                                    "properties": {190                                        "deviceType": { "const": "laptop" },191                                        "arch": { "type": "string", "enum": ["x86", "x64", "arm64"] }192                                    },193                                    "required": ["deviceType", "arch"]194                                }195                            ]196                        }197                    }198                },199                "required": ["Devices"]200            }201'@202 203        # Valid JSON with mixed device types (all matching their respective anyOf choice)204        $validAnyOfDeviceJson = @'205            {206                "Devices": [207                    { "deviceType": "laptop", "arch": "x64" },208                    { "deviceType": "smartphone", "os": "iOS" }209                ]210            }211'@212 213        # Invalid JSON where only Devices/2 has an invalid os value214        $invalidAnyOfDeviceJson = @'215            {216                "Devices": [217                    { "deviceType": "laptop", "arch": "x64" },218                    { "deviceType": "smartphone", "os": "iOS" },219                    { "deviceType": "smartphone", "os": "WindowsPhone" }220                ]221            }222'@223 224        $validJsonPath = Join-Path -Path $TestDrive -ChildPath 'validJson.json'225        $validLiteralJsonPath = Join-Path -Path $TestDrive -ChildPath "[valid]Json.json"226        $invalidNodeInJsonPath = Join-Path -Path $TestDrive -ChildPath 'invalidNodeInJson.json'227        $invalidTypeInJsonPath = Join-Path -Path $TestDrive -ChildPath 'invalidTypeInJson.json'228        $invalidTypeInJson2Path = Join-Path -Path $TestDrive -ChildPath 'invalidTypeInJson2.json'229        $invalidEmptyJsonPath = Join-Path -Path $TestDrive -ChildPath 'emptyJson.json'230 231        Set-Content -Path $validJsonPath -Value $validJson232        Set-Content -LiteralPath $validLiteralJsonPath -Value $validJson233        Set-Content -Path $invalidNodeInJsonPath -Value $invalidNodeInJson234        Set-Content -Path $invalidTypeInJsonPath -Value $invalidTypeInJson235        Set-Content -Path $invalidTypeInJson2Path -Value $invalidTypeInJson2236        New-Item -Path $invalidEmptyJsonPath -ItemType File237    }238 239    It "Missing JSON schema file doesn't exist" {240        Test-Path -LiteralPath $missingSchemaJsonPath | Should -BeFalse241    }242 243    It "Missing JSON file doesn't exist" {244        Test-Path -LiteralPath $missingJsonPath | Should -BeFalse245    }246 247    It "Json is valid" {248        Test-Json -Json $validJson | Should -BeTrue249    }250 251    It "Json is valid against a valid schema from string" {252        Test-Json -Json $validJson -Schema $validSchemaJson | Should -BeTrue253    }254 255    It "Json is valid against a valid schema from file" {256        Test-Json -Json $validJson -SchemaFile $validSchemaJsonPath | Should -BeTrue257        ($validJson | Test-Json -SchemaFile $validSchemaJsonPath) | Should -BeTrue258    }259 260    It "Json file specified using -Path is valid" {261        Test-Json -Path $validJsonPath | Should -BeTrue262    }263 264    It "Json file specified using -LiteralPath is valid" {265        Test-Json -LiteralPath $validLiteralJsonPath | Should -BeTrue266    }267 268    It "Json file specified using LiteralPath aliases -PSPath and -LP is valid" {269        Test-Json -PSPath $validLiteralJsonPath | Should -BeTrue270        Test-Json -LP $validLiteralJsonPath | Should -BeTrue271    }272 273    It "Json file specified using -Path from pipeline is valid" {274        (Get-ChildItem -Path $validJsonPath -File | Test-Json) | Should -BeTrue275    }276 277    It "Json file specified using -LiteralPath from pipeline is valid" {278        (Get-ChildItem -LiteralPath $validLiteralJsonPath -File | Test-Json) | Should -BeTrue279    }280 281    It "Json file is valid against a valid schema from string" {282        Test-Json -Path $validJsonPath -Schema $validSchemaJson | Should -BeTrue283    }284 285    It "Json file is valid against a valid schema from file" {286        Test-Json -Path $validJsonPath -SchemaFile $validSchemaJsonPath | Should -BeTrue287    }288 289    It "Json is invalid" {290        Test-Json -Json $invalidNodeInJson -ErrorAction SilentlyContinue | Should -BeFalse291        ($invalidNodeInJson | Test-Json -ErrorAction SilentlyContinue) | Should -BeFalse292    }293 294    It "Json is invalid against a valid schema from string" {295        Test-Json -Json $invalidTypeInJson2 -Schema $validSchemaJson -ErrorAction SilentlyContinue | Should -BeFalse296        ($invalidTypeInJson2 | Test-Json -Schema $validSchemaJson -ErrorAction SilentlyContinue) | Should -BeFalse297 298        Test-Json -Json $invalidNodeInJson -Schema $validSchemaJson -ErrorAction SilentlyContinue | Should -BeFalse299        ($invalidNodeInJson | Test-Json -Schema $validSchemaJson -ErrorAction SilentlyContinue) | Should -BeFalse300    }301 302    It "Json is invalid against a valid schema from file" {303        Test-Json -Json $invalidTypeInJson2 -SchemaFile $validSchemaJsonPath -ErrorAction SilentlyContinue | Should -BeFalse304        ($invalidTypeInJson2 | Test-Json -SchemaFile $validSchemaJsonPath -ErrorAction SilentlyContinue) | Should -BeFalse305 306        Test-Json -Json $invalidNodeInJson -SchemaFile $validSchemaJsonPath -ErrorAction SilentlyContinue | Should -BeFalse307        ($invalidNodeInJson | Test-Json -SchemaFile $validSchemaJsonPath -ErrorAction SilentlyContinue) | Should -BeFalse308    }309 310    It "Json file is invalid against a valid schema from file" {311        Test-Json -Path $invalidTypeInJson2Path -SchemaFile $validSchemaJsonPath -ErrorAction SilentlyContinue | Should -BeFalse312        Test-Json -Path $invalidNodeInJsonPath -SchemaFile $validSchemaJsonPath -ErrorAction SilentlyContinue | Should -BeFalse313    }314 315    It "Json file is invalid" {316        Test-Json -Path $invalidNodeInJsonPath -ErrorAction SilentlyContinue | Should -BeFalse317    }318 319    It "Json file is invalid against a valid schema from string" {320        Test-Json -Path $invalidTypeInJson2Path -Schema $validSchemaJson -ErrorAction SilentlyContinue | Should -BeFalse321        Test-Json -Path $invalidNodeInJsonPath -Schema $validSchemaJson -ErrorAction SilentlyContinue | Should -BeFalse322    }323 324    It "Json file is invalid against an empty file" {325        Test-Json -Path $invalidEmptyJsonPath -ErrorAction SilentlyContinue | Should -BeFalse326    }327 328    It "Test-Json throw if a schema from string is invalid" {329        { Test-Json -Json $validJson -Schema $invalidSchemaJson -ErrorAction Stop } | Should -Throw -ErrorId "InvalidJsonSchema,Microsoft.PowerShell.Commands.TestJsonCommand"330        { Test-Json -Path $validJsonPath -Schema $invalidSchemaJson -ErrorAction Stop } | Should -Throw -ErrorId "InvalidJsonSchema,Microsoft.PowerShell.Commands.TestJsonCommand"331    }332 333    It "Test-Json throw if a schema from file is invalid" {334        { Test-Json -Json $validJson -SchemaFile $invalidSchemaJsonPath -ErrorAction Stop } | Should -Throw -ErrorId "InvalidJsonSchema,Microsoft.PowerShell.Commands.TestJsonCommand"335        { Test-Json -Path $validJsonPath -SchemaFile $invalidSchemaJsonPath -ErrorAction Stop } | Should -Throw -ErrorId "InvalidJsonSchema,Microsoft.PowerShell.Commands.TestJsonCommand"336    }337 338    It "Test-Json throw if a path to a schema from file is invalid" {339        { Test-Json -Json $validJson -SchemaFile $missingSchemaJsonPath -ErrorAction Stop } | Should -Throw -ErrorId "JsonSchemaFileOpenFailure,Microsoft.PowerShell.Commands.TestJsonCommand"340        { Test-Json -Path $validJsonPath -SchemaFile $missingSchemaJsonPath -ErrorAction Stop } | Should -Throw -ErrorId "JsonSchemaFileOpenFailure,Microsoft.PowerShell.Commands.TestJsonCommand"341    }342 343    It "Test-Json throw if a path from file is invalid" {344        { Test-Json -Path $missingJsonPath -ErrorAction Stop } | Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.TestJsonCommand"345    }346 347    It "Test-Json throw if a path from file using -Path is a literal path" {348        { Test-Json -Path $validLiteralJsonPath -ErrorAction Stop } | Should -Throw -ErrorId "FileOpenFailure,Microsoft.PowerShell.Commands.TestJsonCommand"349    }350 351    It "Json file throw if a path from file using -LiteralPath is a wildcard or regular expression" {352        { Test-Json -LiteralPath (Join-Path -Path $TestDrive -ChildPath "*Json.json") -ErrorAction Stop } | Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.TestJsonCommand"353        { Test-Json -LiteralPath (Join-Path -Path $TestDrive -ChildPath "[a-z]Json.json") -ErrorAction Stop } | Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.TestJsonCommand"354    }355 356    It "Test-Json write an error on invalid (<name>) Json against a valid schema from string" -TestCases @(357        @{ name = "type"; json = $invalidTypeInJson; errorId = "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand" }358        @{ name = "node"; json = $invalidNodeInJson; errorId = "InvalidJson,Microsoft.PowerShell.Commands.TestJsonCommand" }359    ) {360        param ($json, $errorId)361 362        $errorVar = $null363        Test-Json -Json $json -Schema $validSchemaJson -ErrorVariable errorVar -ErrorAction SilentlyContinue364 365        $errorVar.FullyQualifiedErrorId | Should -BeExactly $errorId366    }367 368    It "Test-Json write an error on invalid (<name>) Json against a valid schema from file" -TestCases @(369        @{ name = "type"; json = $invalidTypeInJson; errorId = "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand" }370        @{ name = "node"; json = $invalidNodeInJson; errorId = "InvalidJson,Microsoft.PowerShell.Commands.TestJsonCommand" }371    ) {372        param ($json, $errorId)373 374        $errorVar = $null375        Test-Json -Json $json -SchemaFile $validSchemaJsonPath -ErrorVariable errorVar -ErrorAction SilentlyContinue376 377        $errorVar.FullyQualifiedErrorId | Should -BeExactly $errorId378    }379 380    It "Test-Json write an error on invalid (<name>) Json file against a valid schema from string" -TestCases @(381        @{ name = "type"; json = $invalidTypeInJsonPath; errorId = "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand" }382        @{ name = "node"; json = $invalidNodeInJsonPath; errorId = "InvalidJson,Microsoft.PowerShell.Commands.TestJsonCommand" }383    ) {384        param ($json, $errorId)385 386        $errorVar = $null387        Test-Json -Path $json -Schema $validSchemaJson -ErrorVariable errorVar -ErrorAction SilentlyContinue388 389        $errorVar.FullyQualifiedErrorId | Should -BeExactly $errorId390    }391 392    It "Test-Json write an error on invalid (<name>) Json file against a valid schema from file" -TestCases @(393        @{ name = "type"; json = $invalidTypeInJsonPath; errorId = "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand" }394        @{ name = "node"; json = $invalidNodeInJsonPath; errorId = "InvalidJson,Microsoft.PowerShell.Commands.TestJsonCommand" }395    ) {396        param ($json, $errorId)397 398        $errorVar = $null399        Test-Json -Path $json -SchemaFile $validSchemaJsonPath -ErrorVariable errorVar -ErrorAction SilentlyContinue400 401        $errorVar.FullyQualifiedErrorId | Should -BeExactly $errorId402    }403 404    It "Test-Json return all errors when check invalid Json against a valid schema from string" {405        $errorVar = $null406        Test-Json -Json $invalidTypeInJson2 -Schema $validSchemaJson -ErrorVariable errorVar -ErrorAction SilentlyContinue407 408        # '$invalidTypeInJson2' contains two errors in property types.409        $errorVar.Count | Should -Be 2410        $errorVar[0].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"411        $errorVar[1].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"412    }413 414    It "Test-Json return all errors when check invalid Json against a valid schema from file" {415        $errorVar = $null416        Test-Json -Json $invalidTypeInJson2 -SchemaFile $validSchemaJsonPath -ErrorVariable errorVar -ErrorAction SilentlyContinue417 418        # '$invalidTypeInJson2' contains two errors in property types.419        $errorVar.Count | Should -Be 2420        $errorVar[0].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"421        $errorVar[1].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"422    }423 424    It "Test-Json return all errors when check invalid Json file against a valid schema from string" {425        $errorVar = $null426        Test-Json -Path $invalidTypeInJson2Path -Schema $validSchemaJson -ErrorVariable errorVar -ErrorAction SilentlyContinue427 428        # '$invalidTypeInJson2Path' contains two errors in property types.429        $errorVar.Count | Should -Be 2430        $errorVar[0].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"431        $errorVar[1].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"432    }433 434    It "Test-Json return all errors when check invalid Json file against a valid schema from file" {435        $errorVar = $null436        Test-Json -Path $invalidTypeInJson2Path -SchemaFile $validSchemaJsonPath -ErrorVariable errorVar -ErrorAction SilentlyContinue437 438        # '$invalidTypeInJson2Path' contains two errors in property types.439        $errorVar.Count | Should -Be 2440        $errorVar[0].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"441        $errorVar[1].FullyQualifiedErrorId | Should -BeExactly "InvalidJsonAgainstSchemaDetailed,Microsoft.PowerShell.Commands.TestJsonCommand"442    }443 444    It 'Test-Json recognizes non-object types: <name>' -TestCases @(445        @{ name = 'number'; value = 1; expected = 'number' }446        @{ name = '"true"'; value = '"true"'; expected = 'string' }447        @{ name = 'true'; value = 'true'; expected = 'boolean' }448        @{ name = '"false"'; value = '"false"'; expected = 'string' }449        @{ name = 'false'; value = 'false'; expected = 'boolean' }450        @{ name = '"null"'; value = '"null"'; expected = 'string' }451        @{ name = 'null'; value = 'null'; expected = 'null' }452        @{ name = 'string'; value = '"abc"'; expected = 'string' }453        @{ name = 'array'; value = '[ 1, 2 ]'; expected = 'array' }454    ) {455        param ($name, $value, $expected)456 457        # All JSON valid458        Test-Json -Json $value | Should -BeTrue459 460        # Exactly one type should match461        $types = 'string', 'number', 'boolean', 'null', 'array', 'object'462        $types | Where-Object {463            $schema = "{ `"type`": `"$_`" }"464            Test-Json -Json $value -Schema $schema -ErrorAction SilentlyContinue465        } | Should -Be $expected466    }467 468    It "Test-Json returns True with document options '<options>'" -TestCases @(469        @{ Json = $jsonWithComments; Options = 'IgnoreComments' }470        @{ Json = $jsonWithTrailingComma; Options = 'AllowTrailingCommas'}471        @{ Json = $jsonWithCommentsAndTrailingComma; Options = 'IgnoreComments', 'AllowTrailingCommas'}472    ) {473        param($Json, $Options)474 475        # Without options should fail476        ($Json | Test-Json -ErrorAction SilentlyContinue) | Should -BeFalse477 478        # With options should pass479        ($Json | Test-Json -Option $Options -ErrorAction SilentlyContinue) | Should -BeTrue480    }481 482    It "Test-Json does not report false positives for valid oneOf matches" {483        $errorVar = $null484        $result = Test-Json -Json $validOneOfJson -Schema $oneOfSchema -ErrorVariable errorVar -ErrorAction SilentlyContinue485 486        $result | Should -BeTrue487        $errorVar.Count | Should -Be 0488    }489 490    It "Test-Json reports only relevant errors for invalid oneOf values" {491        $errorVar = $null492        $result = Test-Json -Json $invalidOneOfJson -Schema $oneOfSchema -ErrorVariable errorVar -ErrorAction SilentlyContinue493 494        $result | Should -BeFalse495        # Should report error only for the invalid item, not for valid items496        $errorVar.Count | Should -BeGreaterThan 0497        $errorVar[0].Exception.Message | Should -Match "/ports/1"498    }499 500    It "Test-Json does not report false positives for valid oneOf device matches" {501        $errorVar = $null502        $result = Test-Json -Json $validOneOfDeviceJson -Schema $oneOfDeviceSchema -ErrorVariable errorVar -ErrorAction SilentlyContinue503 504        $result | Should -BeTrue505        $errorVar.Count | Should -Be 0506    }507 508    It "Test-Json reports errors only for the invalid device in oneOf schema" {509        $errorVar = $null510        $result = Test-Json -Json $invalidOneOfDeviceJson -Schema $oneOfDeviceSchema -ErrorVariable errorVar -ErrorAction SilentlyContinue511 512        $result | Should -BeFalse513        # Should not report errors for valid devices (Devices/0, /1, /2)514        $falsePositives = $errorVar | Where-Object { $_.Exception.Message -match '/Devices/(0|1|2)' }515        $falsePositives.Count | Should -Be 0516        # Should report errors only for the invalid device (Devices/3)517        $relevantErrors = $errorVar | Where-Object { $_.Exception.Message -match '/Devices/3' }518        $relevantErrors.Count | Should -BeGreaterThan 0519    }520 521    It "Test-Json does not report false positives for valid anyOf device matches" {522        $errorVar = $null523        $result = Test-Json -Json $validAnyOfDeviceJson -Schema $anyOfDeviceSchema -ErrorVariable errorVar -ErrorAction SilentlyContinue524 525        $result | Should -BeTrue526        $errorVar.Count | Should -Be 0527    }528 529    It "Test-Json reports errors only for the invalid device in anyOf schema" {530        $errorVar = $null531        $result = Test-Json -Json $invalidAnyOfDeviceJson -Schema $anyOfDeviceSchema -ErrorVariable errorVar -ErrorAction SilentlyContinue532 533        $result | Should -BeFalse534        # Should not report errors for valid devices (Devices/0, /1)535        $falsePositives = $errorVar | Where-Object { $_.Exception.Message -match '/Devices/(0|1)' }536        $falsePositives.Count | Should -Be 0537        # Should report errors only for the invalid device (Devices/2)538        $relevantErrors = $errorVar | Where-Object { $_.Exception.Message -match '/Devices/2' }539        $relevantErrors.Count | Should -BeGreaterThan 0540    }541}542