I would like to define a JSON schema vocabulary to extend any regular JSON schema with storage related metadata.
As an example I would like to define a pk
keyword which marks an arbitrary JSON property as a primary key.
My meta-schema looks like this:
{
"$schema": "http://json-schema.org/draft/2019-09/schema#",
"$id": "https://myschema/meta/storage-schema",
"$vocabulary": {
"https://json-schema.org/draft/2019-09/vocab/core": true,
"https://json-schema.org/draft/2019-09/vocab/applicator": true,
"https://json-schema.org/draft/2019-09/vocab/validation": true,
"https://json-schema.org/draft/2019-09/vocab/meta-data": true,
"https://json-schema.org/draft/2019-09/vocab/format": false,
"https://json-schema.org/draft/2019-09/vocab/content": true,
"https://myschema/vocab/storage-schema": false
},
"$recursiveAnchor": true,
"title": "JSON Storage-Schema",
"allOf": [
{"$ref": "https://json-schema.org/draft/2019-09/schema"},
{
"$recursiveAnchor": true,
"title": "storage vocabulary meta-schema",
"type": ["object", "boolean"],
"properties": {
"pk": {
"description": "Marks a property as primary key",
"type": "boolean",
"default": false
}
}
}
]
}
And a corresponding JSON instance might be:
{
"$id": "https://myschema/invoice.schema.json",
"$schema": "https://myschema/meta/storage-schema",
"type": "object",
"properties": {
"invoiceNumber": {
"pk": true,
"type": "string"
},
"invoiceIssueDate": {
"type": "string"
}
}
}
However, I am not sure if I am on the right track. For example WebStorm's IntelliSense only offers the pk
keyword as a top level keyword and not as a keyword for properties:
{
"$id": "https://myschema/invoice.schema.json",
"$schema": "https://myschema/meta/storage-schema",
"$comment": "Webstorm IntelliSense works and pk documentation is displayed",
"pk": false,
"type": "object",
"properties": {
"invoiceNumber": {
"$comment": "No webstorm IntelliSense and no documentation displayed",
"pk": true,
"type": "string"
},
"invoiceIssueDate": {
"type": "string"
}
}
}
Does anyone have experience with meta-schemas and custom keywords and can confirm if I am doing it right?