Validating a json schema file against the draft-07 schema definition within powershell

Viewed 73

I want to validate that a given json schema file is valid against the draft-07 specification.

So I have a testschema.json file:

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "type": "object",
    "title": "test schema",
    "required": [
        "MyProperty"
    ],
    "properties": {
        "MyProperty": {
            "type": "string"
        }
    },
    "additionalProperties": true
}

And I use that in the usual way to validate json files, as in following expected failure:

PS> '{ "Foo": "Bar" }' | test-json -schemaFile "c:\temp\testschema.json"
Test-Json: PropertyRequired: #/MyProperty
False

But now I want to validate that the schema file itself is valid (for automation and PR validation purposes), but I can't get test-json to use the draft-07 as a schema file. For example:

PS>Invoke-WebRequest -Uri "http://json-schema.org/draft-07/schema" -OutFile "c:\temp\draft07schema.json"
PS>Get-Content -Path "C:\temp\c:\temp\draft07schema.json" -Raw | test-json
True
PS>Get-Content -Path "C:\temp\testschema.json" -Raw | test-json -SchemaFile "c:\temp\draft07schema.json"
Test-Json: Cannot parse the JSON schema.

The draft07schema.json file looks perfectly normal, validates in VSCode, and passes test-json check as shown above.

Am I missing something? Or is this a limitation of test-json itself ?

0 Answers
Related