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
/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.
@cchildress All the cmdlet does it is call two NJsonSchema methods
https://github.com/PowerShell/PowerShell/blob/4464d1b4140cc53fa1cf65e95b569e8fd956bba8/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs#L85-L106