Powershell: Test-Json passes erroneously when data required in schema is missing

Created on 23 Jul 2020  路  5Comments  路  Source: PowerShell/PowerShell

Expected behavior: Test-Json should evaluate the input data against the given schema. If the schema requires certain properties to be present, it should fail without those properties.

Actual behavior: Test-Json returns true even if required properties are missing.

In the following example, the schema requires a billing address if there is a credit card. The sample data contains a credit card, but no billing address. This passes, but it should fail.

Example:
$demoschema = @'
{
"type": "object",

"properties": {
"name": { "type": "string" },
"credit_card": { "type": "number" },
"billing_address": { "type": "string" }
},

"required": ["name"],

"dependencies": {
"credit_card": ["billing_address"]
}
}
'@

$demoinput = "{"name": "John Doe","credit_card": 5555555555555555}"

$demoinput | Test-Json -Schema $demoschema

Area-Cmdlets-Utility Issue-Question

All 5 comments

/cc @iSazonov to comment.

@smitheroons Thanks for your report!

We use NJsonSchema API to validate JSON schema. You could ask in NJsonSchema repository about this behavior.

@iSazonov Can we label this one as external?

@daxian-dbw / @iSazonov
Do either of you have time to write up a test in .NET to try this in the NJsonSchema library directly?

If we don't see this issue in the library directly then it sounds like this is a cmdlet issue.
If we do see this issue in the library then we have a repro ready to file an upstream bug.

Was this page helpful?
0 / 5 - 0 ratings