Skip to content

Commit 70c43fd

Browse files
committed
Check $schema dialect is 2020-12 if present
1 parent b32c87c commit 70c43fd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ import {
2525
export const validate = (schema, instance) => {
2626
registerSchema(schema, "");
2727
const schemaNode = /** @type NonNullable<JsonNode> */ (schemaRegistry.get(""));
28+
29+
if (schemaNode.jsonType === "object" && jsonObjectHas("$schema", schemaNode)) {
30+
const $schema = jsonPointerStep("$schema", schemaNode);
31+
if ($schema.jsonType === "string" && $schema.value !== "https://json-schema.org/draft/2020-12/schema") {
32+
throw Error(`Dialect '${$schema.value}' is not supported. Use 2020-12.`);
33+
}
34+
}
35+
2836
const isValid = validateSchema(schemaNode, toJsonNode(instance));
37+
2938
schemaRegistry.delete("");
39+
3040
return isValid;
3141
};
3242

0 commit comments

Comments
 (0)