Metaschema with new keyword #1008
-
|
I'm currently stuck with my metaschema definition: I want to write a metaschema that adds an additional keyword ( I started with the easy one: enforce format validation through the metaschema: JSON metaschema JSON schemaHowever, as you can see, I still have the This looks good, if I test it with [`sourcemeta-jsonschema`](https://github.com/sourcemeta/jsonschema).with However, if I use the same with [`ajv`](https://github.com/ajv-validator/ajv) (in strict mode) it fails.resulting in Using [`python-jsonschema`](https://github.com/python-jsonschema/jsonschema) results in an error as well.results in So my question is: Is my metaschema wrong or what am I missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
You mostly have the right idea. You're right that you don't want to set the {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://www.first.org/cvss/meta.json",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
"https://json-schema.org/draft/2020-12/vocab/validation": true,
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
"https://json-schema.org/draft/2020-12/vocab/format-assertion": true
},
"$ref": "#/$defs/schema",
"type": "object",
"properties": {
"license": { ... }
},
"unevaluatedProperties": false,
"$defs": {
"schema": {
"$dynamicAnchor": "meta",
"allOf": [
{ "$ref": "https://json-schema.org/draft/2020-12/meta/core" },
{ "$ref": "https://json-schema.org/draft/2020-12/meta/applicator" },
{ "$ref": "https://json-schema.org/draft/2020-12/meta/unevaluated" },
{ "$ref": "https://json-schema.org/draft/2020-12/meta/validation" },
{ "$ref": "https://json-schema.org/draft/2020-12/meta/meta-data" },
{ "$ref": "https://json-schema.org/draft/2020-12/meta/format-assertion" }
]
}
}
}
JSON Schema is supposed to ignore keywords it doesn't know, but Ajv's strict mode will through an error. There's some function you can call to add support for that keyword. I'll leave it to you to find it. I don't have it memorized. So, the meta-schema is fine, but you need to configure the validator. This is usually the part where I give the "never use ajv with strict mode" warning, but in this case, I approve of this being an error. This will be part of the next release of JSON Schema. But, in general, always disable strict mode.
That looks like a bug. |
Beta Was this translation helpful? Give feedback.
You mostly have the right idea. You're right that you don't want to set the
$dynamicAnchorat the top, but you do need to set it. You want something more like this,{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://www.first.org/cvss/meta.json", "$vocabulary": { "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/applicator": true, "https://json-schema.org/draft/2020-12/vocab/unevaluated": true, "https://json-schema.org/draft/2020-12/vocab/validation": true, "https://json-schema.org/draft/2020-12/vocab/meta-data": true, "https://json-schema.org/draft/2020-12/vocab/format-assertion": t…