Skip to content

Commit e12a540

Browse files
committed
Include instance in annotation handler and allow undefined return
1 parent d1de778 commit e12a540

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/experimental.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export type Keyword<A> = {
7373
collectEvaluatedProperties?: (compiledKeywordValue: A, instance: JsonNode, context: ValidationContext, isTop?: boolean) => Set<string> | false;
7474
collectEvaluatedItems?: (compiledKeywordValue: A, instance: JsonNode, context: ValidationContext, isTop?: boolean) => Set<number> | false;
7575
collectExternalIds?: (visited: Set<string>, parentSchema: Browser<SchemaDocument>, schema: Browser<SchemaDocument>) => Promise<Set<string>>;
76-
annotation?: <B>(compiledKeywordValue: A) => B;
76+
annotation?: <B>(compiledKeywordValue: A, instance: JsonNode) => B | undefined;
7777
};
7878

7979
export type ValidationContext = {

lib/keywords/validation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ const interpret = (url, instance, { ast, dynamicAnchors, errors, annotations, ou
8585
}
8686
errors.push(...context.errors);
8787
} else {
88-
if (keywordHandler.annotation) {
88+
const annotation = keywordHandler.annotation?.(keywordValue, instance);
89+
if (annotation !== undefined) {
8990
schemaAnnotations.unshift({
9091
keyword: keywordId,
9192
absoluteKeywordLocation: schemaUri,
9293
instanceLocation: Instance.uri(instance),
93-
annotation: keywordHandler.annotation(keywordValue)
94+
annotation: annotation
9495
});
9596
}
9697
for (const contextAnnotation of context.annotations) {

0 commit comments

Comments
 (0)