Using $schema in JSON documents
#473
Replies: 5 comments 2 replies
|
IMO the main argument against defining Another limitation of this approach is that it would only work for objects. JSON Schema can represent other types at the root as well and there would still need to be some way to externally associate a JSON document with its schema.
The I think I'd rather document it as a common convention rather than something that goes in the spec. |
|
One possible reflection that I have that stands against specifying |
|
This shouldn't be a concern of JSON Schema itself, as it normalizes a lot of cans of worms, such as async logic being a-okay for validation, implementations willy nilly doing HTTP requests just because of a field in a JSON file and a range of behaviours in case of failure states. You really don't want this mechanics outside of IDE helper tooltips. |
|
I stumbled across this discussion while looking for a clear answer whether While reading through the discussion, I was wondering whether I missed something or whether the change in the interpretation would prevent to write meta-schemas that enforce a certain value for Metaschema example: An arbitrary instance: |
|
The data file has no standard way to declare "I belong to this schema." Sometimes the approach is: it is commonly understood by editors such as VS Code and some JSON tooling ecosystems. Still not a standard. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We've long held that although many editors support using
$schemain JSON documents to indicate the schema to be used to validate that document, it's not something we can specify because we don't specify JSON. Therefore, we can't say that$schemawith a URI value in a JSON document means it should be validated by the JSON Schema represented by that URI.This makes sense, but what if we turn it around?
Instead we could say that when a JSON Schema implementation processes a JSON document that has
$schemain it, that URI indicates the schema to use to validate it.This changes a paradigm, at least for my implementation. Currently for many implementations, the schema needs to be provided explicitly: something similar to
or
With this requirement, a user could instead just do
and the implementation would detect the schema to use.
I think this is probably the closest we could get to specifying the use of
$schemain instances, which seems to be something that users want.(There is also some overlap with json-schema-org/json-schema-spec#1420 in that the
application/schema-instance+jsonmedia type could also be registered to accept aschemaparameter that the implementation could honor.)This also has the nice side effect that processing a schema by its meta-schema just becomes processing a schema as any other instance.
All reactions