prosser / json-schema-validation-extension

JSON Schema Validation extension and language server for VS Code
MIT License
5 stars 0 forks source link

JSON Schema Diagnostics

A JSON Schema (up to draft/2020-12) validation extension for Visual Studio Code. Provides a language server that validates JSON documents, including JSON Schema documents, against the $schema they declare.

The extension is powered by a Language Server written in C# that uses the fantastic JsonSchema.Net library by Greg Dennis.

Features

Local schema substitution

During development it is handy to use the real URLs that your schemas will be available from, but still be able to validate them. For example, say you have a schema that you plan to publish to https://company.com/schema/foo, but you're still creating it. Without changing your JSON, you should still be able to validate against that schema prior to publishing it.

[!WARNING] Schema substitution only works for $schema, not $ref. I may add this feature if there is enough demand, but that would require hooking deeper into the guts of the schema validation library I'm using. I figured it would be more useful to get draft/2020-12 support available now than spend a bunch of time doing that...

To configure this, there are a few settings you can configure: Screenshot of settings

The default configuration will expect the schema filenames to match the last segment of the URL. E.g., "https://company.com/schema/foo" will match foo and foo.json in the search paths. The first match will be used. More details on the Glob syntax here

If you have a different pattern, adjust the Search Globs and Search Url Pattern to fit your needs. Here are a few examples:

Url Expected filename Pattern to use Glob to use
https://company.com/schema/abc/def abc.def.json ^https://.+/(.+)/(.+)$ $1.$2.json
https://company.com/schemas?get=abc abc.json https://.+\?get=(.+)$ $1.json
urn://local/abc abc.json ^urn://local/(.+)$ $1.json
urn://local/abc.json abc.json ^urn://local/(.+)$ $1

Requirements

Supports VS Code running on Windows x64, Linux x64, and OSX.

Known Issues

Release Notes