@bcherny @cyrilletuzi @lucianbuzzo @rolandjitsu
The type of the $schema property of a JSONSchema7 object is JSONSchema7Version, which is basically an enum of strings (each string being a URI to an official JSON-Schema meta-schema).
However, this makes it impossible to extend a JSONSchema7 object, if you are writing your own meta-schemata:
/**
* A meta-schema that validates JSON Schemata of a certain form.
*/
interface ExampleMetaSchema extends JSONSchema7 {
/** The `$schema` property must be this string literal. */
$schema: 'https://example.com/chharvey/meta-schema.jsd#'; // ---- ERROR! ----
/** Title required. */
title: string;
/** Description required. */
description: string;
/**
* The `type` property must be the literal `'array'`.
* (The instance schema must only validate arrays.)
*/
type: 'array';
}
In the example above, the line $schema: 'https://example.com/chharvey/meta-schema.jsd#'; will throw an error, because that string literal is not assignable to the JSONSchema7Definition type.
My suggestion is to allow the $schema property of JSONSchema7 to be a string:
interface JSONSchema7 {
// ...
$schema: JSONSchema7Version|string;
// ...
}
Indeed, my suggestion is supported by the official JSON Schema Core spec as well as the official Core/Validation meta-schemata. The spec only specifies that $schema must be an URI, but does not specify which URIs, and the meta-schemata contains the following definition:
"$schema": {
"type": "string",
"format": "uri"
}
@chharvey feel free to make a PR.
Most helpful comment
@chharvey feel free to make a PR.