Skip to content

Commit 2875521

Browse files
committed
Fix annotations for unknown keywords
1 parent 3d943c4 commit 2875521

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

annotations/tests/unknown.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[
2+
{
3+
"title": "`unknownKeyword` is an annotation",
4+
"schema": {
5+
"$schema": "https://json-schema.org/draft/2020-12/schema",
6+
"unknownKeyword": "Foo"
7+
},
8+
"subjects": [
9+
{
10+
"instance": 42,
11+
"assertions": [
12+
{
13+
"location": "#",
14+
"keyword": "unknownKeyword",
15+
"expected": ["Foo"]
16+
}
17+
]
18+
}
19+
]
20+
}
21+
]

lib/keywords/unknown.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import * as Browser from "@hyperjump/browser";
22
import * as Instance from "../../annotations/annotated-instance.js";
3+
import { pointerSegments } from "@hyperjump/json-pointer";
34

45

56
const id = "https://json-schema.org/keyword/unknown";
67

7-
const compile = (schema) => Browser.value(schema);
8+
const compile = (schema) => {
9+
const keywordName = [...pointerSegments(schema.cursor)].pop();
10+
return [keywordName, Browser.value(schema)];
11+
};
812

9-
const interpret = (value, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10-
Instance.setAnnotation(instance, id, schemaLocation, value);
13+
const interpret = ([keywordName, value], instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
14+
const keywordId = `${id}#${keywordName}`;
15+
Instance.setAnnotation(instance, keywordId, schemaLocation, value);
1116
return true;
1217
};
1318

0 commit comments

Comments
 (0)