-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Here are a few things to look out for when implementing something like this.
The set of properties that are considered keywords depends on the dialect
In the following example, additionalItems
should not be highlighted as a keyword because it was removed in 2020-12.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [true],
"additionalItems": false, // <- not a keyword
"items": false,
"definitions": {} // <- not a keyword
"aaa": 42 // <- not a keyword
}
When we change the dialect, the properties that are considered keywords changes.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"prefixItems": [true], // <- not a keyword
"additionalItems": false,
"items": false
"definitions": {}
"aaa": 42 // <- not a keyword
}
Properties are only keywords inside schemas
Not every object in a JSON Schema document is a schema, so you need to know when you're in a schema and when you're not. Here are a couple examples.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"$id": "foo" // <- not a keyword
}
}
In the next example, $id
isn't considered a keyword because definitions
isn't a keyword in 2020-12. Therefore, their values aren't schemas and the properties of those values shouldn't be considered keywords.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"definitions": {
"foo": {
"type": "string" // <- not a keyword
}
}
}
Embedded schemas can have a different dialect
It's possible for embedded schemas to have a different dialect than their parent schema. In the following example, the same keywords are highlighted differently depending on which schema resource the keyword appears in.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [true],
"additionalItems": false, // <- not a keyword
"items": false,
"$defs": {
"foo": {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/schema/embedded",
"prefixItems": [true], // <- not a keyword
"additionalItems": false,
"items": false,
"definitions": {}
}
}
}