@@ -24,9 +24,14 @@ import { Output } from "./output.js";
2424
2525/** @type (schema: Json, instance: Json) => Output */
2626export const validate = ( schema , instance ) => {
27- registerSchema ( schema , "" ) ;
28- const schemaNode = /** @type NonNullable<JsonNode> */ ( schemaRegistry . get ( "" ) ) ;
27+ // Determine schema identifier
28+ const uri = typeof schema === "object" && schema !== null && ! Array . isArray ( schema )
29+ && typeof schema . $id === "string" ? schema . $id : "" ;
30+ registerSchema ( schema , uri ) ;
2931
32+ const schemaNode = /** @type NonNullable<JsonNode> */ ( schemaRegistry . get ( uri ) ) ;
33+
34+ // Verify the dialect is supported
3035 if ( schemaNode . jsonType === "object" && jsonObjectHas ( "$schema" , schemaNode ) ) {
3136 const $schema = jsonPointerStep ( "$schema" , schemaNode ) ;
3237 if ( $schema . jsonType === "string" && $schema . value !== "https://json-schema.org/draft/2020-12/schema" ) {
@@ -36,7 +41,7 @@ export const validate = (schema, instance) => {
3641
3742 const output = validateSchema ( schemaNode , toJsonNode ( instance ) ) ;
3843
39- schemaRegistry . delete ( "" ) ;
44+ schemaRegistry . delete ( uri ) ;
4045
4146 return output ;
4247} ;
@@ -625,3 +630,31 @@ keywordHandlers.set("uniqueItems", (uniqueItemsNode, instanceNode) => {
625630 const isValid = new Set ( normalizedItems ) . size === normalizedItems . length ;
626631 return new Output ( isValid , uniqueItemsNode , instanceNode ) ;
627632} ) ;
633+
634+ keywordHandlers . set ( "$id" , ( idNode , instanceNode , schemaNode ) => {
635+ if ( ! idNode . location . endsWith ( "#/$id" ) ) {
636+ throw Error ( `Embedded schemas are not supported. Found at ${ schemaNode . location } ` ) ;
637+ }
638+
639+ return new Output ( true , idNode , instanceNode ) ;
640+ } ) ;
641+
642+ keywordHandlers . set ( "$anchor" , ( anchorNode ) => {
643+ throw Error ( `The '$anchor' keyword is not supported. Found at ${ anchorNode . location } ` ) ;
644+ } ) ;
645+
646+ keywordHandlers . set ( "$dynamicAnchor" , ( dynamicAnchorNode ) => {
647+ throw Error ( `The '$dynamicAnchor' keyword is not supported. Found at ${ dynamicAnchorNode . location } ` ) ;
648+ } ) ;
649+
650+ keywordHandlers . set ( "$dynamicRef" , ( dynamicRefNode ) => {
651+ throw Error ( `The '$dynamicRef' keyword is not supported. Found at ${ dynamicRefNode . location } ` ) ;
652+ } ) ;
653+
654+ keywordHandlers . set ( "unevaluatedProperties" , ( unevaluatedPropertiesNode ) => {
655+ throw Error ( `The 'unevaluatedProperties' keyword is not supported. Found at ${ unevaluatedPropertiesNode . location } ` ) ;
656+ } ) ;
657+
658+ keywordHandlers . set ( "unevaluatedItems" , ( unevaluatedItemsNode ) => {
659+ throw Error ( `The 'unevaluatedItems' keyword is not supported. Found at ${ unevaluatedItemsNode . location } ` ) ;
660+ } ) ;
0 commit comments