RicoSuter / VisualJsonEditor

A JSON schema based file editor for Windows.
http://visualjsoneditor.org
MIT License
349 stars 87 forks source link

Add ability to specify schema location in a "_schema" property in the document #34

Closed dannylane closed 4 years ago

dannylane commented 4 years ago

Use Case We have multiple JSON documents that share the same schema. Instead of always prompting the user to select the schema file it would be useful if the document could point to its own schema.

Change Proposed This PR allows a document to specify a _schema property at the root of the JSON containing a relative path to the schema. Relative paths are supported so "myschema.json" and "../../schemas/myschema.json" would be valid examples.

As a side effect of this change I also set the SaveAsync(bool saveSchema) flag to use the saveAs flag so the schema is only persisted when the user is doing a 'Save As' operation

RicoSuter commented 4 years ago

wouldnt it be better to use the "$schema" field as this is usually used for referencing the schema (usually an URL but file path is also fine i suppose)?

dannylane commented 4 years ago

I thought about $schema but I think that already has a meaning that is different from this.

From here

The $schema keyword is used to declare that a JSON fragment is actually a piece of JSON Schema.

The URL is normally the schema standard used, not to point to a specific schema instance.

We don't want to say these documents are schemas, rather point to a location of a schema instance.

I'm not tied to the name of the property, I could make it something more descriptive like _schemaLocation or _schemaPath. I could even go with $schema but I'm not sure that would be the right approach.

What do you think?

RicoSuter commented 4 years ago

But the value in $schema is the URL to the JSON Schema schema :-): http://json-schema.org/draft/2019-09/schema

RicoSuter commented 4 years ago

Also see: https://code.visualstudio.com/Docs/languages/json#_json-schemas-and-settings

and also: https://devblogs.microsoft.com/aspnet/intellisense-for-json-schema-in-the-json-editor/

dannylane commented 4 years ago

Got it, that makes sense. Have updated the PR to look for $schema

RicoSuter commented 4 years ago

v2.10

RicoSuter commented 4 years ago

If the build still works than this should be soon available via the download link.